test(core): preserve global mcp startup wait semantics

This commit is contained in:
Felipe Coury
2026-06-03 15:45:06 -03:00
parent acb2d8676c
commit 6727539114
3 changed files with 22 additions and 9 deletions
+12 -1
View File
@@ -393,7 +393,7 @@ impl McpConnectionManager {
pub fn wait_for_servers_ready(
&self,
server_names: &[String],
) -> impl std::future::Future<Output = Vec<McpStartupFailure>> + Send + 'static {
) -> impl std::future::Future<Output = Vec<McpStartupFailure>> + Send + 'static + use<> {
let clients = server_names
.iter()
.map(|server_name| (server_name.clone(), self.clients.get(server_name).cloned()))
@@ -419,6 +419,17 @@ impl McpConnectionManager {
}
}
/// Returns an owned future that waits for every configured MCP server.
pub fn wait_for_all_servers_ready(
&self,
) -> impl std::future::Future<Output = (Vec<String>, Vec<McpStartupFailure>)> + Send + 'static
{
let mut server_names = self.clients.keys().cloned().collect::<Vec<_>>();
server_names.sort();
let readiness = self.wait_for_servers_ready(&server_names);
async move { (server_names, readiness.await) }
}
pub async fn required_startup_failures(
&self,
required_servers: &[String],
+2 -5
View File
@@ -144,10 +144,7 @@ impl CodexThread {
}
#[doc(hidden)]
pub async fn wait_for_mcp_servers_ready(
&self,
server_names: &[String],
) -> Vec<McpStartupFailure> {
pub async fn wait_for_mcp_startup(&self) -> (Vec<String>, Vec<McpStartupFailure>) {
let readiness = {
let manager = self
.codex
@@ -156,7 +153,7 @@ impl CodexThread {
.mcp_connection_manager
.read()
.await;
manager.wait_for_servers_ready(server_names)
manager.wait_for_all_servers_ready()
};
readiness.await
}
+8 -3
View File
@@ -246,9 +246,14 @@ where
/// 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<()> {
let server_names = vec![server_name.to_string()];
let failures = codex.wait_for_mcp_servers_ready(&server_names).await;
if let Some(failure) = failures.first() {
let (server_names, failures) = codex.wait_for_mcp_startup().await;
if !server_names.iter().any(|name| name == server_name) {
anyhow::bail!("MCP server {server_name} was not initialized");
}
if let Some(failure) = failures
.iter()
.find(|failure| failure.server == server_name)
{
let error = &failure.error;
anyhow::bail!("MCP server {server_name} failed to start: {error}");
}