Lightweight coding agent that runs in your terminal
Rust
Treat non-interactive dumb terminals as warnings in `codex doctor` (#44615)
Eric Traut3422443ec4af
diff --git a/codex-rs/cli/src/doctor.rs b/codex-rs/cli/src/doctor.rsindex e42fa9be01..5028c711fe 100644--- a/codex-rs/cli/src/doctor.rs+++ b/codex-rs/cli/src/doctor.rs@@ -1761,16 +1761,20 @@ fn terminal_check_from_inputs(inputs: TerminalCheckInputs) -> DoctorCheck {let locale_warning = locale.as_deref().is_some_and(is_non_utf8_locale);let mut issues = Vec::new();if matches!(name, TerminalName::Dumb) {- issues.push(+ let issue = if inputs.stdin_is_terminal || inputs.stdout_is_terminal {DoctorIssue::new(CheckStatus::Fail,"TERM=dumb - colors and cursor control are disabled",)- .measured("TERM=dumb").expected("TERM=xterm-256color or another real terminal type").remedy("set TERM to a real value, for example xterm-256color")- .field("TERM"),- );+ } else {+ DoctorIssue::new(+ CheckStatus::Warning,+ "TERM=dumb - colors and cursor control are disabled in this non-interactive run",+ )+ };+ issues.push(issue.measured("TERM=dumb").field("TERM"));}if locale_warning {let measured = locale.unwrap_or_else(|| "unknown".to_string());@@ -1798,6 +1802,7 @@ fn terminal_check_from_inputs(inputs: TerminalCheckInputs) -> DoctorCheck {);}issues.extend(terminal_size_issues(&inputs));+ issues.sort_by_key(|issue| std::cmp::Reverse(issue.severity));let status = issues.iter()@@ -4057,24 +4062,57 @@ mod tests {}#[test]- fn terminal_check_warns_for_dumb_terminal() {- let mut inputs = terminal_inputs();- inputs.info.name = TerminalName::Dumb;- inputs.info.term = Some("dumb".to_string());- set_terminal_env(&mut inputs, "TERM", "dumb");-- let check = terminal_check_from_inputs(inputs);-- assert_eq!(check.status, CheckStatus::Fail);- assert_eq!(- check.summary,- "TERM=dumb - colors and cursor control are disabled"- );- assert_eq!(check.issues.len(), 1);- assert_eq!(- check.issues[0].remedy.as_deref(),- Some("set TERM to a real value, for example xterm-256color")- );+ fn terminal_check_dumb_requires_interactive_stream() {+ for (stdin, stdout, stderr, expected) in [+ (false, false, false, CheckStatus::Warning),+ (false, false, true, CheckStatus::Warning),+ (false, true, false, CheckStatus::Fail),+ (true, false, false, CheckStatus::Fail),+ ] {+ let mut inputs = terminal_inputs();+ inputs.info.name = TerminalName::Dumb;+ inputs.info.term = Some("dumb".to_string());+ set_terminal_env(&mut inputs, "TERM", "dumb");+ inputs.stdin_is_terminal = stdin;+ inputs.stdout_is_terminal = stdout;+ inputs.stderr_is_terminal = stderr;++ let check = terminal_check_from_inputs(inputs);++ assert_eq!(check.status, expected);+ assert_eq!(check.issues.len(), 1);+ assert_eq!(+ check.issues[0].remedy.as_deref(),+ (expected == CheckStatus::Fail)+ .then_some("set TERM to a real value, for example xterm-256color")+ );+ assert_eq!(+ check.issues[0].expected.as_deref(),+ (expected == CheckStatus::Fail)+ .then_some("TERM=xterm-256color or another real terminal type")+ );+ if !stdin && !stdout && !stderr {+ let report = DoctorReport {+ schema_version: 1,+ generated_at: "0s since unix epoch".to_string(),+ overall_status: overall_status(std::slice::from_ref(&check)),+ codex_version: "0.0.0".to_string(),+ checks: vec![check],+ };+ insta::assert_snapshot!(+ "doctor_dumb_non_interactive_human",+ render_human_report(+ &report,+ HumanOutputOptions {+ show_details: true,+ show_all: true,+ ascii: true,+ color_enabled: false,+ }+ )+ );+ }+ }}#[test]@@ -4132,10 +4170,15 @@ mod tests {}#[test]- fn terminal_check_warns_for_unreadable_terminfo_path() {+ fn terminal_check_prioritizes_unreadable_terminfo_over_warnings() {let tempdir = tempfile::tempdir().expect("create tempdir");let missing = tempdir.path().join("missing-terminfo");let mut inputs = terminal_inputs();+ inputs.info.name = TerminalName::Dumb;+ inputs.stdin_is_terminal = false;+ inputs.stdout_is_terminal = false;+ set_terminal_env(&mut inputs, "TERM", "dumb");+ set_terminal_env(&mut inputs, "LANG", "C");set_terminal_env(&mut inputs, "TERMINFO", &missing.to_string_lossy());let check = terminal_check_from_inputs(inputs);@@ -4155,6 +4198,21 @@ mod tests {check.issues[0].remedy.as_deref(),Some("check that $TERMINFO points to a readable directory"));+ insta::assert_snapshot!(render_human_report(+ &DoctorReport {+ schema_version: 1,+ generated_at: "0s since unix epoch".to_string(),+ overall_status: check.status,+ codex_version: "0.0.0".to_string(),+ checks: vec![check],+ },+ HumanOutputOptions {+ show_details: false,+ show_all: false,+ ascii: true,+ color_enabled: false,+ }+ ));}#[test]diff --git a/codex-rs/cli/src/snapshots/codex__doctor__tests__doctor_dumb_non_interactive_human.snap b/codex-rs/cli/src/snapshots/codex__doctor__tests__doctor_dumb_non_interactive_human.snapnew file mode 100644index 0000000000..4974e49533--- /dev/null+++ b/codex-rs/cli/src/snapshots/codex__doctor__tests__doctor_dumb_non_interactive_human.snap@@ -0,0 +1,25 @@+---+source: cli/src/doctor.rs+expression: "render_human_report(&report, HumanOutputOptions\n{ show_details: true, show_all: true, ascii: true, color_enabled: false, })"+---+Codex Doctor v0.0.0++Notes+ [!!] terminal TERM=dumb - colors and cursor control are disabled in this non-interactive run+-------------------------------------------------------------++Environment+ [!!] terminal TERM=dumb - colors and cursor control are disabled in this non-interactive run+ terminal dumb+ TERM dumb+ stdin is terminal false+ stdout is terminal false+ stderr is terminal false+ terminal size 120x40+ color output disabled (TERM=dumb)++-------------------------------------------------------------+0 ok | 1 notes | 1 warn | 0 fail degraded++--summary compact output --all expand truncated lists+--json redacted reportdiff --git a/codex-rs/cli/src/snapshots/codex__doctor__tests__terminal_check_prioritizes_unreadable_terminfo_over_warnings.snap b/codex-rs/cli/src/snapshots/codex__doctor__tests__terminal_check_prioritizes_unreadable_terminfo_over_warnings.snapnew file mode 100644index 0000000000..3e21aaa6be--- /dev/null+++ b/codex-rs/cli/src/snapshots/codex__doctor__tests__terminal_check_prioritizes_unreadable_terminfo_over_warnings.snap@@ -0,0 +1,18 @@+---+source: cli/src/doctor.rs+expression: "render_human_report(&DoctorReport\n{\n schema_version: 1, generated_at: \"0s since unix epoch\".to_string(),\n overall_status: check.status, codex_version: \"0.0.0\".to_string(), checks:\n vec![check],\n}, HumanOutputOptions\n{ show_details: false, show_all: false, ascii: true, color_enabled: false, })"+---+Codex Doctor v0.0.0++Notes+ [XX] terminal 3 issues - TERMINFO unreadable - terminal capabilities are unknown; TERM=dumb - colors and cursor control are disabled in this non-interactive run+-------------------------------------------------------------++Environment+ [XX] terminal 3 issues - TERMINFO unreadable - terminal capabilities are unknown; TERM=dumb - colors and cursor control are disabled in this non-interactive run++-------------------------------------------------------------+0 ok | 1 notes | 0 warn | 1 fail failed++Run codex doctor without --summary for detailed diagnostics.+--all expand truncated lists --json redacted reportdiff --git a/codex-rs/cli/tests/doctor_path_safety.rs b/codex-rs/cli/tests/doctor_path_safety.rsindex 96530ca952..ea73fb115e 100644--- a/codex-rs/cli/tests/doctor_path_safety.rs+++ b/codex-rs/cli/tests/doctor_path_safety.rs@@ -178,6 +178,25 @@ fn startup_and_doctor_do_not_execute_path_helpers() -> Result<()> {Ok(())}+#[test]+fn non_interactive_dumb_terminal_preserves_other_doctor_failures() -> Result<()> {+ let fixture = Fixture::new()?;+ let output = fixture+ .command()?+ .args(["doctor", "--json"])+ // Explicit identity takes precedence over inherited terminal-specific variables.+ .env("TERM_PROGRAM", "dumb")+ .env_remove("TERMINFO")+ .env_remove("TERMINFO_DIRS")+ .output()?;+ // The fixture's provider is unreachable, regardless of terminal capabilities.+ assert_eq!(output.status.code(), Some(1));+ let report: Value = serde_json::from_slice(&output.stdout)?;+ assert_eq!(report["checks"]["terminal.env"]["status"], "warning");+ assert_eq!(report["overallStatus"], "fail");+ Ok(())+}+#[cfg(unix)]#[tokio::test]async fn interactive_tmux_startup_does_not_execute_workspace_helpers() -> Result<()> {