use crate::agents::BackendState;
use crate::agents::mcpjson::{ServerShape, probe as mcp_probe};
use crate::components::{McpKind, McpServer};
fn scratch(name: &str) -> std::path::PathBuf {
let dir = crate::scratch::path("ez-kiro-unit");
std::fs::create_dir_all(&dir).unwrap();
dir.join(name)
}
fn server(name: &str, command: &str) -> McpServer {
McpServer { name: name.into(), kind: McpKind::Stdio, command: command.into(), args: vec!["mcp".into()], env: Default::default() }
}
#[test]
fn probe_classifies_absent_healthy_and_needs_repair() {
let path = scratch("mcp.json");
let servers = [server("ez-fixture", "host_fixture")];
let key = ["mcpServers"];
assert!(matches!(mcp_probe(&path, &key, &servers, ServerShape::plain()).unwrap(), BackendState::Absent));
std::fs::write(&path, r#"{"mcpServers":{"ez-fixture":{"command":"host_fixture","args":["mcp"],"env":{}}}}"#).unwrap();
assert!(matches!(mcp_probe(&path, &key, &servers, ServerShape::plain()).unwrap(), BackendState::Healthy));
std::fs::write(&path, r#"{"mcpServers":{"ez-fixture":{"command":"other","args":["mcp"],"env":{}}}}"#).unwrap();
assert!(matches!(mcp_probe(&path, &key, &servers, ServerShape::plain()).unwrap(), BackendState::NeedsRepair));
std::fs::remove_dir_all(path.parent().unwrap()).ok();
}