use tempfile::tempdir;
use super::support::{global_file, one_stdio_server};
use crate::mcp::{McpToolSet, register_configured_tools};
use crate::tools::registry::ToolRegistry;
#[tokio::test]
async fn an_unconfigured_run_registers_nothing_and_reports_nothing() {
let home = tempdir().expect("tempdir");
let project = tempdir().expect("tempdir");
let set = McpToolSet::load_at(&home.path().join("servers.toml"), project.path()).await;
let mut registry = ToolRegistry::new();
let diagnostics = register_configured_tools(&mut registry, &set);
assert!(set.is_empty());
assert!(diagnostics.statuses.is_empty());
assert!(diagnostics.issues.is_empty());
assert_eq!(diagnostics.usable_count(), 0);
}
#[tokio::test]
async fn a_failed_server_does_not_stop_the_others() {
let home = tempdir().expect("tempdir");
let project = tempdir().expect("tempdir");
let mut text = one_stdio_server("ghost-a", "/nonexistent/mcp/a-5428");
text.push_str(&one_stdio_server("ghost-b", "/nonexistent/mcp/b-5428"));
let global = global_file(home.path(), &text);
let set = McpToolSet::load_at(&global, project.path()).await;
let diagnostics = set.diagnostics();
assert_eq!(diagnostics.statuses.len(), 2, "both are reported");
assert!(diagnostics.statuses.iter().all(|s| !s.usable));
assert!(
diagnostics.statuses[1]
.detail
.as_deref()
.is_some_and(|d| d.contains("b-5428")),
"the second server was still attempted: {:?}",
diagnostics.statuses[1],
);
assert!(set.tool_names().is_empty());
}
#[tokio::test]
async fn a_malformed_global_file_reaches_the_diagnostics() {
let home = tempdir().expect("tempdir");
let project = tempdir().expect("tempdir");
let global = global_file(home.path(), "not = = toml [[[");
let set = McpToolSet::load_at(&global, project.path()).await;
let mut registry = ToolRegistry::new();
let diagnostics = register_configured_tools(&mut registry, &set);
assert!(diagnostics.tools.is_empty());
assert!(
!diagnostics.issues.is_empty(),
"a broken file MUST be reported, never read as an empty catalog",
);
diagnostics.log();
}
#[tokio::test]
async fn the_live_path_loads_nothing_under_a_test_harness() {
let project = tempdir().expect("tempdir");
let set = McpToolSet::load(project.path()).await;
assert!(set.is_empty());
assert!(set.diagnostics().statuses.is_empty());
}