[codex] Wait for MCP readiness in core integration tests (#24964)

Ensures MCP-backed `codex-core` integration tests exercise initialized
servers instead of racing server startup.

I've been idly investigating a few flakes and the failure modes are much
more confusing when a tool call fails because of a failed server start
than when the failed server start causes the test to fail directly.
This commit is contained in:
Adam Perry @ OpenAI
2026-05-29 10:22:27 -07:00
committed by GitHub
parent e29bbb5368
commit 3e666dd32a
8 changed files with 73 additions and 85 deletions
+33
View File
@@ -248,6 +248,39 @@ where
wait_for_event_with_timeout(codex, predicate, Duration::from_secs(1)).await
}
/// Waits for a configured MCP server to finish startup and requires it to be ready.
pub async fn wait_for_mcp_server(codex: &CodexThread, server_name: &str) -> anyhow::Result<()> {
use codex_protocol::protocol::EventMsg;
// Wait for the startup summary regardless of outcome, then interpret the
// requested server's ready, failed, or cancelled entry below.
let summary = loop {
let event = codex
.next_event()
.await
.expect("stream ended unexpectedly while waiting for MCP startup");
if let EventMsg::McpStartupComplete(summary) = event.msg {
break summary;
}
};
if let Some(failure) = summary
.failed
.iter()
.find(|failure| failure.server == server_name)
{
let error = &failure.error;
anyhow::bail!("MCP server {server_name} failed to start: {error}");
}
if summary.cancelled.iter().any(|server| server == server_name) {
anyhow::bail!("MCP server {server_name} startup was cancelled");
}
assert!(
summary.ready.iter().any(|server| server == server_name),
"expected MCP server {server_name} to be ready; startup summary: {summary:?}"
);
Ok(())
}
pub async fn submit_thread_settings(
codex: &CodexThread,
thread_settings: codex_protocol::protocol::ThreadSettingsOverrides,