selfware 0.6.3

Your personal AI workshop — software you own, software that lasts
Documentation
use super::*;

#[test]
fn test_mcp_config_default() {
    let config = McpConfig::default();
    assert!(config.servers.is_empty());
}

#[test]
fn test_mcp_config_serialize_empty() {
    let config = McpConfig::default();
    let json = serde_json::to_string(&config).unwrap();
    assert!(json.contains("servers"));
}

#[test]
fn test_mcp_config_deserialize_empty() {
    let json = r#"{"servers": []}"#;
    let config: McpConfig = serde_json::from_str(json).unwrap();
    assert!(config.servers.is_empty());
}

#[test]
fn test_mcp_config_deserialize_no_servers_field() {
    let json = "{}";
    let config: McpConfig = serde_json::from_str(json).unwrap();
    assert!(config.servers.is_empty());
}

#[test]
fn test_mcp_server_config_serialize_roundtrip() {
    let server = McpServerConfig {
        name: "github".to_string(),
        command: "npx".to_string(),
        args: vec![
            "-y".to_string(),
            "@modelcontextprotocol/server-github".to_string(),
        ],
        env: {
            let mut m = std::collections::HashMap::new();
            m.insert("GITHUB_TOKEN".to_string(), "ghp_test".to_string());
            m
        },
        init_timeout_secs: 30,
        framing: Default::default(),
    };
    let json = serde_json::to_string(&server).unwrap();
    let parsed: McpServerConfig = serde_json::from_str(&json).unwrap();
    assert_eq!(parsed.name, "github");
    assert_eq!(parsed.command, "npx");
    assert_eq!(parsed.args.len(), 2);
    assert_eq!(
        parsed.env.get("GITHUB_TOKEN"),
        Some(&"ghp_test".to_string())
    );
    assert_eq!(parsed.init_timeout_secs, 30);
}

#[test]
fn test_mcp_server_config_defaults() {
    let json = r#"{"name": "test", "command": "echo"}"#;
    let config: McpServerConfig = serde_json::from_str(json).unwrap();
    assert_eq!(config.name, "test");
    assert_eq!(config.command, "echo");
    assert!(config.args.is_empty());
    assert!(config.env.is_empty());
    assert_eq!(config.init_timeout_secs, 30);
}

#[test]
fn test_mcp_config_with_multiple_servers() {
    let json = r#"{
            "servers": [
                {"name": "github", "command": "npx", "args": ["-y", "gh-server"]},
                {"name": "db", "command": "mcp-server-sqlite", "args": ["--db", "test.db"]}
            ]
        }"#;
    let config: McpConfig = serde_json::from_str(json).unwrap();
    assert_eq!(config.servers.len(), 2);
    assert_eq!(config.servers[0].name, "github");
    assert_eq!(config.servers[1].name, "db");
}

#[test]
fn test_mcp_server_config_clone() {
    let server = McpServerConfig {
        name: "test".to_string(),
        command: "cmd".to_string(),
        args: vec!["--arg".to_string()],
        env: std::collections::HashMap::new(),
        init_timeout_secs: 60,
        framing: Default::default(),
    };
    let cloned = server.clone();
    assert_eq!(cloned.name, "test");
    assert_eq!(cloned.init_timeout_secs, 60);
}

#[test]
fn test_mcp_config_clone() {
    let config = McpConfig {
        servers: vec![McpServerConfig {
            name: "s1".to_string(),
            command: "c1".to_string(),
            args: vec![],
            env: std::collections::HashMap::new(),
            init_timeout_secs: 30,
            framing: Default::default(),
        }],
    };
    let cloned = config.clone();
    assert_eq!(cloned.servers.len(), 1);
    assert_eq!(cloned.servers[0].name, "s1");
}

#[test]
fn test_default_init_timeout() {
    assert_eq!(default_init_timeout(), 30);
}

#[test]
fn test_mcp_server_config_custom_timeout() {
    let json = r#"{"name": "slow", "command": "heavy-server", "init_timeout_secs": 120}"#;
    let config: McpServerConfig = serde_json::from_str(json).unwrap();
    assert_eq!(config.init_timeout_secs, 120);
}

#[test]
fn test_mcp_server_config_with_env() {
    let json = r#"{"name": "test", "command": "cmd", "env": {"KEY1": "val1", "KEY2": "val2"}}"#;
    let config: McpServerConfig = serde_json::from_str(json).unwrap();
    assert_eq!(config.env.len(), 2);
    assert_eq!(config.env.get("KEY1"), Some(&"val1".to_string()));
}

#[test]
fn test_mcp_config_debug() {
    let config = McpConfig::default();
    let debug_str = format!("{:?}", config);
    assert!(debug_str.contains("McpConfig"));
}

#[test]
fn test_mcp_server_config_debug() {
    let server = McpServerConfig {
        name: "test".to_string(),
        command: "cmd".to_string(),
        args: vec![],
        env: std::collections::HashMap::new(),
        init_timeout_secs: 30,
        framing: Default::default(),
    };
    let debug_str = format!("{:?}", server);
    assert!(debug_str.contains("test"));
}