mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Probe Windows terminal colors without risking startup input (#40598)
## Why Windows Terminal and xterm.js can render a theme that differs from the underlying console color table. Querying that visible theme through OSC shares the console input queue with keystrokes, including input for security-sensitive startup prompts. ## What changed - Defer the Windows OSC color probe until protected startup decisions and the world-writable workspace scan have completed. - Preserve and replay unrelated console input records around the probe, while removing only valid OSC 10 and 11 replies and retaining the console palette as a fallback. - Require an explicit confirmation key after shortcuts select trust, sandbox, or world-writable warning choices, so a fragmented terminal reply cannot accept them. - Accept one- through four-digit OSC RGB components so the visible terminal palette is applied across supported response formats. ## Testing Added coverage for delayed startup scans, protected prompt confirmation, console-record replay, bracketed paste and malformed OSC preservation, RGB response parsing, and light-theme composer rendering. GitOrigin-RevId: b8ae456fe32c701ba3af31e9cc452fc4e8bffa22
This commit is contained in:
1 parent
1f5c9ba183
commit
70b5cfc73b
19 files changed
+1162
-149
No files matched your search
@@ -6,6 +6,7 @@ use crate::tui::FrameRequester;
|
||||
use app_test_support::create_fake_parented_rollout_with_source;
|
||||
use codex_app_server_protocol::ToolRequestUserInputOption;
|
||||
use codex_app_server_protocol::ToolRequestUserInputQuestion;
|
||||
use codex_utils_approval_presets::builtin_approval_presets;
|
||||
use crossterm::event::KeyCode;
|
||||
use crossterm::event::KeyEvent;
|
||||
use crossterm::event::KeyModifiers;
|
||||
@@ -30,6 +31,105 @@ fn startup_bottom_pane() -> (BottomPane, UnboundedReceiver<AppEvent>) {
|
||||
)
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn terminal_color_probe_waits_for_startup_sandbox_choice() {
|
||||
let (mut app, mut app_event_rx, _op_rx) = make_test_app_with_channels().await;
|
||||
app.startup_protected_input_boundary = true;
|
||||
while app_event_rx.try_recv().is_ok() {}
|
||||
|
||||
assert!(app.ready_for_terminal_color_probe(/*has_pending_app_events*/ false));
|
||||
assert!(!app.ready_for_terminal_color_probe(/*has_pending_app_events*/ true));
|
||||
|
||||
let preset = builtin_approval_presets()
|
||||
.into_iter()
|
||||
.find(|preset| preset.id == "auto")
|
||||
.expect("auto preset");
|
||||
app.chat_widget
|
||||
.open_windows_sandbox_enable_prompt(preset, /*profile_selection*/ None);
|
||||
|
||||
assert!(!app.ready_for_terminal_color_probe(/*has_pending_app_events*/ false));
|
||||
app.chat_widget
|
||||
.handle_key_event(KeyEvent::new(KeyCode::Char('2'), KeyModifiers::NONE));
|
||||
assert!(!app.ready_for_terminal_color_probe(/*has_pending_app_events*/ false));
|
||||
assert!(app_event_rx.try_recv().is_err());
|
||||
|
||||
app.chat_widget
|
||||
.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
|
||||
assert!(matches!(
|
||||
app_event_rx.try_recv(),
|
||||
Ok(AppEvent::BeginWindowsSandboxLegacySetup { .. })
|
||||
));
|
||||
assert!(app.ready_for_terminal_color_probe(/*has_pending_app_events*/ false));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn terminal_color_probe_waits_for_delayed_world_writable_scan_failure() {
|
||||
let (mut app, mut app_event_rx, _op_rx) = make_test_app_with_channels().await;
|
||||
app.startup_protected_input_boundary = true;
|
||||
app.windows_sandbox.startup_world_writable_scan_pending = true;
|
||||
while app_event_rx.try_recv().is_ok() {}
|
||||
|
||||
assert!(!app.ready_for_terminal_color_probe(/*has_pending_app_events*/ false));
|
||||
|
||||
app.app_event_tx
|
||||
.send(AppEvent::OpenWorldWritableWarningConfirmation {
|
||||
preset: None,
|
||||
profile_selection: None,
|
||||
sample_paths: Vec::new(),
|
||||
extra_count: 0,
|
||||
failed_scan: true,
|
||||
});
|
||||
app.app_event_tx
|
||||
.send(AppEvent::StartupWorldWritableScanCompleted);
|
||||
assert!(!app.ready_for_terminal_color_probe(/*has_pending_app_events*/ true));
|
||||
|
||||
let warning = app_event_rx
|
||||
.try_recv()
|
||||
.expect("the delayed scan should queue its warning before completion");
|
||||
let AppEvent::OpenWorldWritableWarningConfirmation {
|
||||
preset,
|
||||
profile_selection,
|
||||
sample_paths,
|
||||
extra_count,
|
||||
failed_scan,
|
||||
} = warning
|
||||
else {
|
||||
panic!("the delayed scan should open a protected warning before completion");
|
||||
};
|
||||
app.chat_widget.open_world_writable_warning_confirmation(
|
||||
preset,
|
||||
profile_selection,
|
||||
sample_paths,
|
||||
extra_count,
|
||||
failed_scan,
|
||||
);
|
||||
assert!(matches!(
|
||||
app_event_rx.try_recv(),
|
||||
Ok(AppEvent::StartupWorldWritableScanCompleted)
|
||||
));
|
||||
app.windows_sandbox.startup_world_writable_scan_pending = false;
|
||||
|
||||
assert!(!app.windows_sandbox.startup_world_writable_scan_pending);
|
||||
assert!(!app.ready_for_terminal_color_probe(/*has_pending_app_events*/ false));
|
||||
for character in "20;rgb:2222/ffff/ffff".chars() {
|
||||
app.chat_widget
|
||||
.handle_key_event(KeyEvent::new(KeyCode::Char(character), KeyModifiers::NONE));
|
||||
assert!(app_event_rx.try_recv().is_err());
|
||||
}
|
||||
|
||||
app.chat_widget
|
||||
.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
|
||||
assert!(matches!(
|
||||
app_event_rx.try_recv(),
|
||||
Ok(AppEvent::UpdateWorldWritableWarningAcknowledged(true))
|
||||
));
|
||||
assert!(matches!(
|
||||
app_event_rx.try_recv(),
|
||||
Ok(AppEvent::PersistWorldWritableWarningAcknowledged)
|
||||
));
|
||||
assert!(app.ready_for_terminal_color_probe(/*has_pending_app_events*/ false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn startup_waiting_gate_is_only_for_fresh_or_exit_session_selection() {
|
||||
assert_eq!(
|
||||
|
||||
Reference in new issue
Block a user