mirror of
https://github.com/openai/codex.git
synced 2026-12-02 00:31:03 +00:00
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
This commit is contained in:
@@ -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::<String>()
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.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 {
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Buffer>;
|
||||
}
|
||||
|
||||
pub(crate) fn last_rendered_buffer<B>(terminal: &Terminal<B>) -> &Buffer
|
||||
where
|
||||
B: Backend<Error = io::Error> + Write,
|
||||
|
||||
Reference in New Issue
Block a user