#![allow(clippy::expect_used, clippy::unwrap_used)]

use std::collections::HashMap;

use capo_agent::mcp::{connect_all, McpConfig, McpServerConfig};
use tempfile::tempdir;

#[tokio::test]
async fn slow_server_is_skipped() {
    let log_dir = tempdir().unwrap();
    let mut servers = HashMap::new();
    servers.insert(
        "slow".into(),
        McpServerConfig::Stdio {
            // `sleep 60` won't respond on stdio; connect will fail or hit timeout.
            command: "sleep".into(),
            args: vec!["60".into()],
            env: HashMap::new(),
            startup_timeout_ms: 200,
            enabled: true,
        },
    );
    let cfg = McpConfig { servers };
    let started = connect_all(&cfg, log_dir.path()).await;
    assert!(started.is_empty(), "slow server should have been skipped");
}

#[tokio::test]
async fn disabled_server_is_not_connected() {
    let log_dir = tempdir().unwrap();
    let mut servers = HashMap::new();
    servers.insert(
        "off".into(),
        McpServerConfig::Stdio {
            command: "/nonexistent".into(),
            args: vec![],
            env: HashMap::new(),
            startup_timeout_ms: 100,
            enabled: false,
        },
    );
    let cfg = McpConfig { servers };
    let started = connect_all(&cfg, log_dir.path()).await;
    assert!(started.is_empty());
}
