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
This commit is contained in:
jif
2026-10-09 17:56:26 +00:00
committed by copyberry
parent 8a0437ff34
commit b49e2211a5
+11 -7
View File
@@ -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 {