From 187affbce3cb908f9a94c0dbcb529e8b65bf0474 Mon Sep 17 00:00:00 2001 From: Dylan Hurd Date: Tue, 1 Dec 2026 14:43:05 +0000 Subject: [PATCH] Wait for the Command Center grouping header in the startup test (#65004) ## Why Startup can send a `thread/list` request while the loading screen is still visible. Reading the terminal buffer at that point can make the saved grouping test fail before the Command Center header has rendered. ## What changed Capture completed terminal frames through a test-only channel. Have `agents_overview_startup_restores_saved_grouping` wait for the grouping header and verify that it shows `Group: Status`, the saved preference. GitOrigin-RevId: e4479039e0663483016637be0fe5bfff62f27044 --- .../src/app/tests/startup_defaults_tests.rs | 45 ++++++++----------- codex-rs/tui/src/custom_terminal.rs | 4 ++ .../tui/src/custom_terminal_test_support.rs | 7 ++- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/codex-rs/tui/src/app/tests/startup_defaults_tests.rs b/codex-rs/tui/src/app/tests/startup_defaults_tests.rs index ec16edb1c0..3fbb12083d 100644 --- a/codex-rs/tui/src/app/tests/startup_defaults_tests.rs +++ b/codex-rs/tui/src/app/tests/startup_defaults_tests.rs @@ -80,14 +80,14 @@ async fn agents_overview_startup_restores_saved_grouping() -> Result<()> { .loader_overrides(LoaderOverrides::without_managed_config_for_tests()) .build() .await?; - let (mut server, requests, proxy) = start_recording_remote_app_server(&config).await?; + let (mut server, _requests, proxy) = start_recording_remote_app_server(&config).await?; let bootstrap = server.bootstrap(&config).await?; let mut tui = crate::tui::test_support::make_test_tui()?; tui.pause_events(); let endpoint = crate::resolve_remote_addr("ws://127.0.0.1:4500")?; // The saved client preference should win over the resolved core field. config.tui_agents_overview_grouping = codex_config::types::AgentsOverviewGrouping::Project; - let mut run = Box::pin(run_startup_for_test( + let run = run_startup_for_test( &mut tui, InitialBackendSessions::singleton(server), config, @@ -97,39 +97,30 @@ async fn agents_overview_startup_restores_saved_grouping() -> Result<()> { allow_embedded_fallback: true, endpoint, }, - )); - tokio::time::timeout(Duration::from_secs(/*secs*/ 15), async { + ); + // Thread discovery can start while the provisional loading frame is still visible. + let (tx, mut frames) = tokio::sync::mpsc::unbounded_channel(); + let mut run = Box::pin(crate::custom_terminal::test_support::RENDERED_FRAMES.scope(tx, run)); + let grouping_header = tokio::time::timeout(Duration::from_secs(/*secs*/ 15), async { loop { - if !recorded_params(&requests, "thread/list").is_empty() { - return Ok::<(), color_eyre::eyre::Report>(()); - } tokio::select! { - _ = &mut run => return Ok(()), - () = tokio::time::sleep(Duration::from_millis(/*millis*/ 20)) => {} + result = &mut run => { + result?; + return Err(color_eyre::eyre::eyre!("startup exited before rendering Command Center")); + } + Some(frame) = frames.recv() => { + let rendered = buffer_text(&frame); + if let Some(header) = rendered.lines().find(|line| line.contains("Group:")) { + return Ok(header.trim().to_owned()); + } + } } } }) .await??; drop(run); - let buffer = crate::custom_terminal::test_support::last_rendered_buffer(&tui.terminal); - let rendered = buffer - .content - .chunks(buffer.area.width as usize) - .map(|row| { - row.iter() - .map(ratatui::buffer::Cell::symbol) - .collect::() - }) - .collect::>() - .join("\n"); - let grouping_header = rendered - .lines() - .find(|line| line.contains("Group:")) - .expect("production startup renders Command Center grouping") - .trim(); insta::assert_snapshot!(grouping_header, @"Agent command center Group: Status g"); - proxy.abort(); - Ok(()) + stop_interrupted_startup_recorder(proxy).await } fn layered_config_read_count(requests: &RecordedRequests) -> usize { diff --git a/codex-rs/tui/src/custom_terminal.rs b/codex-rs/tui/src/custom_terminal.rs index e5fdd5bffb..d2d4d689fc 100644 --- a/codex-rs/tui/src/custom_terminal.rs +++ b/codex-rs/tui/src/custom_terminal.rs @@ -549,6 +549,10 @@ where Backend::flush(&mut self.backend)?; + #[cfg(test)] + let _ = + test_support::RENDERED_FRAMES.try_with(|tx| tx.send(self.previous_buffer().clone())); + Ok(()) } diff --git a/codex-rs/tui/src/custom_terminal_test_support.rs b/codex-rs/tui/src/custom_terminal_test_support.rs index 1ff3a153d8..c6a1a09ead 100644 --- a/codex-rs/tui/src/custom_terminal_test_support.rs +++ b/codex-rs/tui/src/custom_terminal_test_support.rs @@ -1,4 +1,4 @@ -//! Inspect the completed frame without adding test helpers to the terminal implementation. +//! Inspect or capture completed terminal frames in tests. use std::io; use std::io::Write; @@ -8,6 +8,11 @@ use ratatui::buffer::Buffer; use super::Terminal; +tokio::task_local! { + /// Capture completed frames while the running app borrows the terminal. + pub(crate) static RENDERED_FRAMES: tokio::sync::mpsc::UnboundedSender; +} + pub(crate) fn last_rendered_buffer(terminal: &Terminal) -> &Buffer where B: Backend + Write,