Files
zclaw_openfang/crates/zclaw-protocols/tests/mcp_transport_tests.rs
iven beeb529d8f test(protocols,skills): add 90 tests for MCP types + skill loader/runner
zclaw-protocols: +43 tests covering mcp_types serde, ContentBlock
variants, transport config builders, and domain type roundtrips.

zclaw-skills: +47 tests covering SKILL.md/TOML parsing, auto-classify,
PromptOnlySkill execution, and SkillManifest/SkillResult roundtrips.

Batch 8 of audit plan (plans/stateless-petting-rossum.md).
2026-04-19 11:24:57 +08:00

56 lines
1.7 KiB
Rust

//! Tests for MCP Transport configuration (McpServerConfig)
//!
//! These tests cover McpServerConfig builder methods without spawning processes.
use std::collections::HashMap;
use zclaw_protocols::McpServerConfig;
#[test]
fn npx_config_creates_correct_command() {
let config = McpServerConfig::npx("@modelcontextprotocol/server-memory");
assert_eq!(config.command, "npx");
assert_eq!(config.args, vec!["-y", "@modelcontextprotocol/server-memory"]);
assert!(config.env.is_empty());
assert!(config.cwd.is_none());
}
#[test]
fn node_config_creates_correct_command() {
let config = McpServerConfig::node("/path/to/server.js");
assert_eq!(config.command, "node");
assert_eq!(config.args, vec!["/path/to/server.js"]);
}
#[test]
fn python_config_creates_correct_command() {
let config = McpServerConfig::python("mcp_server.py");
assert_eq!(config.command, "python");
assert_eq!(config.args, vec!["mcp_server.py"]);
}
#[test]
fn env_adds_variables() {
let config = McpServerConfig::node("server.js")
.env("API_KEY", "secret123")
.env("DEBUG", "true");
assert_eq!(config.env.get("API_KEY").unwrap(), "secret123");
assert_eq!(config.env.get("DEBUG").unwrap(), "true");
}
#[test]
fn cwd_sets_working_directory() {
let config = McpServerConfig::node("server.js").cwd("/tmp/work");
assert_eq!(config.cwd.unwrap(), "/tmp/work");
}
#[test]
fn combined_builder_pattern() {
let config = McpServerConfig::npx("@scope/server")
.env("PORT", "3000")
.cwd("/app");
assert_eq!(config.command, "npx");
assert_eq!(config.args.len(), 2);
assert_eq!(config.env.len(), 1);
assert_eq!(config.cwd.unwrap(), "/app");
}