mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Treat non-interactive dumb terminals as warnings in codex doctor (#44615)
## Why `TERM=dumb` should not fail the terminal check when neither stdin nor stdout is a terminal. Terminal warnings should also not obscure more severe issues such as unreadable terminfo. ## What changed - Report `TERM=dumb` as a warning in non-interactive runs, without suggesting a replacement `TERM` value. Keep it a failure when stdin or stdout is a terminal. - Sort terminal issues by descending severity so failures appear first. ## Testing Add coverage for terminal stream combinations, human output snapshots, and a non-interactive JSON report that retains an overall failure and exit code `1` when another check fails. GitOrigin-RevId: 9af5483e371b4b06eb50e8fcdf15704f0bbc33f1
This commit is contained in:
1 parent
3715bf4100
commit
3422443ec4
4 files changed
+132
-12
No files matched your search
+70
-12
@@ -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 locale_warning = locale.as_deref().is_some_and(is_non_utf8_locale);
|
||||||
let mut issues = Vec::new();
|
let mut issues = Vec::new();
|
||||||
if matches!(name, TerminalName::Dumb) {
|
if matches!(name, TerminalName::Dumb) {
|
||||||
issues.push(
|
let issue = if inputs.stdin_is_terminal || inputs.stdout_is_terminal {
|
||||||
DoctorIssue::new(
|
DoctorIssue::new(
|
||||||
CheckStatus::Fail,
|
CheckStatus::Fail,
|
||||||
"TERM=dumb - colors and cursor control are disabled",
|
"TERM=dumb - colors and cursor control are disabled",
|
||||||
)
|
)
|
||||||
.measured("TERM=dumb")
|
|
||||||
.expected("TERM=xterm-256color or another real terminal type")
|
.expected("TERM=xterm-256color or another real terminal type")
|
||||||
.remedy("set TERM to a real value, for example xterm-256color")
|
.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 {
|
if locale_warning {
|
||||||
let measured = locale.unwrap_or_else(|| "unknown".to_string());
|
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.extend(terminal_size_issues(&inputs));
|
||||||
|
issues.sort_by_key(|issue| std::cmp::Reverse(issue.severity));
|
||||||
|
|
||||||
let status = issues
|
let status = issues
|
||||||
.iter()
|
.iter()
|
||||||
@@ -4057,24 +4062,57 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn terminal_check_warns_for_dumb_terminal() {
|
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();
|
let mut inputs = terminal_inputs();
|
||||||
inputs.info.name = TerminalName::Dumb;
|
inputs.info.name = TerminalName::Dumb;
|
||||||
inputs.info.term = Some("dumb".to_string());
|
inputs.info.term = Some("dumb".to_string());
|
||||||
set_terminal_env(&mut inputs, "TERM", "dumb");
|
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);
|
let check = terminal_check_from_inputs(inputs);
|
||||||
|
|
||||||
assert_eq!(check.status, CheckStatus::Fail);
|
assert_eq!(check.status, expected);
|
||||||
assert_eq!(
|
|
||||||
check.summary,
|
|
||||||
"TERM=dumb - colors and cursor control are disabled"
|
|
||||||
);
|
|
||||||
assert_eq!(check.issues.len(), 1);
|
assert_eq!(check.issues.len(), 1);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
check.issues[0].remedy.as_deref(),
|
check.issues[0].remedy.as_deref(),
|
||||||
Some("set TERM to a real value, for example xterm-256color")
|
(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]
|
#[test]
|
||||||
@@ -4132,10 +4170,15 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[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 tempdir = tempfile::tempdir().expect("create tempdir");
|
||||||
let missing = tempdir.path().join("missing-terminfo");
|
let missing = tempdir.path().join("missing-terminfo");
|
||||||
let mut inputs = terminal_inputs();
|
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());
|
set_terminal_env(&mut inputs, "TERMINFO", &missing.to_string_lossy());
|
||||||
|
|
||||||
let check = terminal_check_from_inputs(inputs);
|
let check = terminal_check_from_inputs(inputs);
|
||||||
@@ -4155,6 +4198,21 @@ mod tests {
|
|||||||
check.issues[0].remedy.as_deref(),
|
check.issues[0].remedy.as_deref(),
|
||||||
Some("check that $TERMINFO points to a readable directory")
|
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]
|
#[test]
|
||||||
|
|||||||
+25
@@ -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 report
|
||||||
+18
@@ -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 report
|
||||||
@@ -178,6 +178,25 @@ fn startup_and_doctor_do_not_execute_path_helpers() -> Result<()> {
|
|||||||
Ok(())
|
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)]
|
#[cfg(unix)]
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn interactive_tmux_startup_does_not_execute_workspace_helpers() -> Result<()> {
|
async fn interactive_tmux_startup_does_not_execute_workspace_helpers() -> Result<()> {
|
||||||
|
|||||||
Reference in new issue
Block a user