mirror of
https://github.com/openai/codex.git
synced 2026-12-03 07:47:10 +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
+141
-21
No files matched your search
+79
-21
@@ -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");
|
||||
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);
|
||||
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")
|
||||
);
|
||||
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]
|
||||
|
||||
Reference in new issue
Block a user