[codex-mcp] Cover pending optional MCP turn startup

This commit is contained in:
Gokul Kumar Krishnan
2026-07-03 13:36:00 -07:00
parent f40d60c478
commit 6efb4609e0

View File

@@ -691,6 +691,68 @@ async fn stdio_server_round_trip() -> anyhow::Result<()> {
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn turn_skips_pending_optional_mcp_without_cached_tools() -> anyhow::Result<()> {
skip_if_no_network!(Ok(()));
let server = responses::start_mock_server().await;
let response_mock = responses::mount_sse_once(
&server,
responses::sse(vec![
responses::ev_response_created("resp-1"),
responses::ev_assistant_message("msg-1", "done"),
responses::ev_completed("resp-1"),
]),
)
.await;
let pending_mcp_listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?;
let pending_mcp_url = format!("http://{}/mcp", pending_mcp_listener.local_addr()?);
let fixture = test_codex()
.with_config(move |config| {
insert_mcp_server(
config,
"pending_optional",
McpServerTransportConfig::StreamableHttp {
url: pending_mcp_url,
bearer_token_env_var: None,
http_headers: None,
env_http_headers: None,
},
TestMcpServerOptions::default(),
);
})
.build(&server)
.await?;
let (_pending_mcp_connection, _) =
tokio::time::timeout(Duration::from_secs(5), pending_mcp_listener.accept())
.await
.context("optional MCP startup should reach the pending server")??;
tokio::time::timeout(Duration::from_secs(5), fixture.submit_turn("hello"))
.await
.context("turn should not wait for pending optional MCP startup")??;
let request = response_mock.single_request();
let body = request.body_json();
let tools = body["tools"].as_array().expect("model request tools");
assert!(
tools.iter().all(|tool| {
tool.get("name")
.or_else(|| tool.get("type"))
.and_then(Value::as_str)
.is_none_or(|name| !name.starts_with("mcp__pending_optional"))
}),
"pending optional MCP tools should be omitted: {tools:?}"
);
tokio::time::timeout(Duration::from_secs(2), fixture.codex.shutdown_and_wait())
.await
.context("shutdown should cancel pending optional MCP startup")??;
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn shutdown_cancels_startup_prewarm_waiting_for_mcp_startup() -> anyhow::Result<()> {
skip_if_no_network!(Ok(()));