From 414d165b47a90d44a231d62a6c2cf2f876306c1a Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Tue, 6 Oct 2026 17:59:31 +0000 Subject: [PATCH] Preserve wrapped help links in Windows sandbox prompts (#51459) ## What changed Render help text in Windows sandbox setup and fallback prompts with `HyperlinkText` so each wrapped URL fragment links to the complete destination. Strip OSC 8 sequences when rendering popup snapshots to keep assertions focused on visible text. ## Testing Add a regression test covering both prompts at 40 columns, asserting that every linked cell retains the complete destination and the visible link text remains intact. Include a snapshot of the wrapped setup prompt. GitOrigin-RevId: 98bd60f04ab3ec8d6552a0b74b9637cce26169d5 --- codex-rs/tui/src/chatwidget/tests/helpers.rs | 2 +- .../tui/src/chatwidget/tests/permissions.rs | 43 +++++++++++++++++++ ...ons__windows_sandbox_wrapped_help_url.snap | 28 ++++++++++++ .../src/chatwidget/windows_sandbox_prompts.rs | 7 ++- 4 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 codex-rs/tui/src/chatwidget/tests/snapshots/codex_tui__chatwidget__tests__permissions__windows_sandbox_wrapped_help_url.snap diff --git a/codex-rs/tui/src/chatwidget/tests/helpers.rs b/codex-rs/tui/src/chatwidget/tests/helpers.rs index 2ccf46ce42..17dc47c3f6 100644 --- a/codex-rs/tui/src/chatwidget/tests/helpers.rs +++ b/codex-rs/tui/src/chatwidget/tests/helpers.rs @@ -1350,7 +1350,7 @@ pub(crate) fn render_bottom_popup(chat: &ChatWidget, width: u16) -> String { if symbol.is_empty() { line.push(' '); } else { - line.push_str(symbol); + line.push_str(&crate::terminal_hyperlinks::strip_osc8(symbol)); } } line.trim_end().to_string() diff --git a/codex-rs/tui/src/chatwidget/tests/permissions.rs b/codex-rs/tui/src/chatwidget/tests/permissions.rs index 4282cab86f..a08388f58d 100644 --- a/codex-rs/tui/src/chatwidget/tests/permissions.rs +++ b/codex-rs/tui/src/chatwidget/tests/permissions.rs @@ -659,6 +659,49 @@ async fn startup_windows_sandbox_prompt_blocks_disallowed_unelevated_fallback() ); } +#[tokio::test] +async fn windows_sandbox_help_links_keep_complete_wrapped_destinations() { + let url = "https://developers.openai.com/codex/windows"; + for fallback in [false, true] { + let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await; + let preset = builtin_approval_presets() + .into_iter() + .find(|preset| preset.id == "auto") + .unwrap(); + if fallback { + chat.open_windows_sandbox_fallback_prompt(preset, /*profile_selection*/ None); + } else { + chat.open_windows_sandbox_enable_prompt(preset, /*profile_selection*/ None); + } + let area = Rect::new(0, 0, 40, 24); + let mut buf = Buffer::empty(area); + chat.bottom_pane.render(area, &mut buf); + let linked = buf + .content + .iter() + .filter(|cell| cell.symbol().contains("\x1b]8;;")) + .map(|cell| { + assert!(cell.symbol().starts_with(&format!("\x1b]8;;{url}\x07"))); + crate::terminal_hyperlinks::strip_osc8(cell.symbol()) + }) + .collect::(); + assert_eq!(linked, url); + if !fallback { + let visible = buf + .content + .chunks(40) + .map(|row| { + row.iter() + .map(|cell| crate::terminal_hyperlinks::strip_osc8(cell.symbol())) + .collect::() + }) + .collect::>() + .join("\n"); + insta::assert_snapshot!("windows_sandbox_wrapped_help_url", visible); + } + } +} + #[tokio::test] async fn windows_sandbox_required_enable_prompt_snapshot() { let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await; diff --git a/codex-rs/tui/src/chatwidget/tests/snapshots/codex_tui__chatwidget__tests__permissions__windows_sandbox_wrapped_help_url.snap b/codex-rs/tui/src/chatwidget/tests/snapshots/codex_tui__chatwidget__tests__permissions__windows_sandbox_wrapped_help_url.snap new file mode 100644 index 0000000000..24f0a8e0bd --- /dev/null +++ b/codex-rs/tui/src/chatwidget/tests/snapshots/codex_tui__chatwidget__tests__permissions__windows_sandbox_wrapped_help_url.snap @@ -0,0 +1,28 @@ +--- +source: tui/src/chatwidget/tests/permissions.rs +expression: visible +--- + + Set up the Codex agent sandbox to + protect your files and control + network access. Learn more + + + +› 1. Set up default sandbox (requires + Administrator permissions) + 2. Use non-admin sandbox (higher risk + if prompt injected) + 3. Quit + + + + + + + + + + + enter select · esc back diff --git a/codex-rs/tui/src/chatwidget/windows_sandbox_prompts.rs b/codex-rs/tui/src/chatwidget/windows_sandbox_prompts.rs index 0bcf5fbe1a..39bbb795f3 100644 --- a/codex-rs/tui/src/chatwidget/windows_sandbox_prompts.rs +++ b/codex-rs/tui/src/chatwidget/windows_sandbox_prompts.rs @@ -33,7 +33,7 @@ impl ChatWidget { !allow_unelevated || self.elevated_windows_sandbox_setup_required(); let mut header = ColumnRenderable::new(); header.push(*Box::new( - Paragraph::new(if allow_unelevated { + crate::terminal_hyperlinks::HyperlinkText::new(if allow_unelevated { vec![ line!["Set up the Codex agent sandbox to protect your files and control network access. Learn more "], ] @@ -42,8 +42,7 @@ impl ChatWidget { line!["Your organization requires the default Codex agent sandbox to continue. Set it up to protect your files and control network access."], line!["Learn more "], ] - }) - .wrap(Wrap { trim: false }), + }), )); let accept_otel = self.session_telemetry.clone(); @@ -170,7 +169,7 @@ impl ChatWidget { ]); let mut header = ColumnRenderable::new(); - header.push(*Box::new(Paragraph::new(lines).wrap(Wrap { trim: false }))); + header.push(crate::terminal_hyperlinks::HyperlinkText::new(lines)); let elevated_preset = preset.clone(); let legacy_preset = preset;