From b49e2211a579553d235c88f9c19eb988331cd159 Mon Sep 17 00:00:00 2001 From: jif Date: Fri, 9 Oct 2026 17:45:33 +0000 Subject: [PATCH] Handle completion events in either order in shell snapshot tests (#52660) ## Why A tool can return before its background watcher emits `ExecCommandEnd`. Waiting for that event first can discard an earlier `TurnComplete`, causing the shell snapshot test helper to time out. ## What changed Update `run_tool_turn_on_harness` to track both the matching `ExecCommandEnd` and `TurnComplete` in a single event loop, returning only after both have arrived regardless of order. GitOrigin-RevId: c9b749a46eda1244aa3e80fd88b663d110d67d1b --- codex-rs/core/tests/suite/shell_snapshot.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/codex-rs/core/tests/suite/shell_snapshot.rs b/codex-rs/core/tests/suite/shell_snapshot.rs index 8bfd272c10..4be1c96bec 100644 --- a/codex-rs/core/tests/suite/shell_snapshot.rs +++ b/codex-rs/core/tests/suite/shell_snapshot.rs @@ -299,13 +299,17 @@ async fn run_tool_turn_on_harness( _ => None, }) .await; - let end = wait_for_event_match(&codex, |ev| match ev { - EventMsg::ExecCommandEnd(ev) if ev.call_id == call_id => Some(ev.clone()), - _ => None, - }) - .await; - wait_for_event(&codex, |ev| matches!(ev, EventMsg::TurnComplete(_))).await; - Ok(end) + let mut end = None; + let mut turn_completed = false; + // The tool can return before its background watcher emits command-end. + while end.is_none() || !turn_completed { + match wait_for_event(&codex, |_| true).await { + EventMsg::ExecCommandEnd(ev) if ev.call_id == call_id => end = Some(ev), + EventMsg::TurnComplete(_) => turn_completed = true, + _ => {} + } + } + Ok(end.expect("command-end should have arrived before completing the wait")) } fn normalize_newlines(text: &str) -> String {