mod coverage_tests {
use super::*;
use serde_json::json;
fn valid_path() -> &'static str {
"."
}
#[test]
fn test_map_mcp_tool_analyze_complexity() {
let params = json!({
"path": valid_path(),
"max_cyclomatic": 15,
"max_cognitive": 20,
"max_halstead": 50.5
});
let result = map_mcp_tool("analyze_complexity", params);
assert!(result.is_ok());
}
#[test]
fn test_map_mcp_tool_analyze_satd() {
let params = json!({
"path": valid_path(),
"severity": "high",
"critical_only": true,
"strict": true,
"fail_on_violation": true
});
let result = map_mcp_tool("analyze_satd", params);
assert!(result.is_ok());
}
#[test]
fn test_map_mcp_tool_analyze_dead_code() {
let params = json!({
"path": valid_path(),
"include_unreachable": true,
"min_dead_lines": 5,
"max_percentage": 10.0,
"fail_on_violation": true
});
let result = map_mcp_tool("analyze_dead_code", params);
assert!(result.is_ok());
}
#[test]
fn test_map_mcp_tool_analyze_tdg() {
let params = json!({
"path": valid_path(),
"threshold": 2.0,
"include_components": true,
"critical_only": true
});
let result = map_mcp_tool("analyze_tdg", params);
assert!(result.is_ok());
}
#[test]
fn test_map_mcp_tool_analyze_lint_hotspot() {
let params = json!({
"path": valid_path(),
"max_density": 3.0,
"min_confidence": 0.9,
"enforce": true,
"dry_run": true
});
let result = map_mcp_tool("analyze_lint_hotspot", params);
assert!(result.is_ok());
}
#[test]
fn test_map_mcp_tool_quality_gate() {
let params = json!({
"path": valid_path(),
"profile": "strict",
"fail_on_violation": true,
"verbose": true
});
let result = map_mcp_tool("quality_gate", params);
assert!(result.is_ok());
}
#[test]
fn test_map_mcp_tool_refactor_auto() {
let params = json!({
"file": "Cargo.toml",
"format": "json",
"target_complexity": 10,
"dry_run": true,
"timeout": 120
});
let result = map_mcp_tool("refactor_auto", params);
assert!(result.is_ok());
}
#[test]
fn test_map_mcp_tool_unknown_tool() {
let params = json!({
"path": valid_path()
});
let result = map_mcp_tool("unknown_tool", params);
assert!(result.is_err());
assert!(result.unwrap_err().to_string().contains("Unknown MCP tool"));
}
#[test]
fn test_map_complexity_contract_minimal() {
let params = json!({
"path": valid_path()
});
let result = map_complexity_contract(¶ms);
assert!(result.is_ok());
}
#[test]
fn test_map_complexity_contract_with_all_options() {
let params = json!({
"path": valid_path(),
"format": "json",
"output": "output.json",
"top_files": 20,
"include_tests": true,
"timeout": 120,
"max_cyclomatic": 10,
"max_cognitive": 15,
"max_halstead": 100.0
});
let result = map_complexity_contract(¶ms);
assert!(result.is_ok());
}
#[test]
fn test_map_complexity_contract_missing_path() {
let params = json!({});
let result = map_complexity_contract(¶ms);
assert!(result.is_err());
assert!(result.unwrap_err().to_string().contains("Missing required parameter: path"));
}
#[test]
fn test_map_satd_contract_minimal() {
let params = json!({
"path": valid_path()
});
let result = map_satd_contract(¶ms);
assert!(result.is_ok());
}
#[test]
fn test_map_satd_contract_with_all_severity_levels() {
for severity in &["low", "medium", "high", "critical"] {
let params = json!({
"path": valid_path(),
"severity": severity
});
let result = map_satd_contract(¶ms);
assert!(result.is_ok(), "Failed for severity: {}", severity);
}
}
#[test]
fn test_map_satd_contract_with_all_options() {
let params = json!({
"path": valid_path(),
"severity": "high",
"critical_only": true,
"strict": true,
"fail_on_violation": true,
"format": "markdown",
"output": "satd.md"
});
let result = map_satd_contract(¶ms);
assert!(result.is_ok());
}
#[test]
fn test_map_satd_contract_invalid_severity() {
let params = json!({
"path": valid_path(),
"severity": "invalid_severity"
});
let result = map_satd_contract(¶ms);
assert!(result.is_ok());
}
#[test]
fn test_map_dead_code_contract_minimal() {
let params = json!({
"path": valid_path()
});
let result = map_dead_code_contract(¶ms);
assert!(result.is_ok());
}
#[test]
fn test_map_dead_code_contract_defaults() {
let params = json!({
"path": valid_path()
});
let result = map_dead_code_contract(¶ms);
assert!(result.is_ok());
}
#[test]
fn test_map_dead_code_contract_with_all_options() {
let params = json!({
"path": valid_path(),
"include_unreachable": true,
"min_dead_lines": 20,
"max_percentage": 25.0,
"fail_on_violation": true
});
let result = map_dead_code_contract(¶ms);
assert!(result.is_ok());
}
#[test]
fn test_map_tdg_contract_minimal() {
let params = json!({
"path": valid_path()
});
let result = map_tdg_contract(¶ms);
assert!(result.is_ok());
}
#[test]
fn test_map_tdg_contract_defaults() {
let params = json!({
"path": valid_path()
});
let result = map_tdg_contract(¶ms);
assert!(result.is_ok());
}
#[test]
fn test_map_tdg_contract_with_all_options() {
let params = json!({
"path": valid_path(),
"threshold": 2.5,
"include_components": true,
"critical_only": true
});
let result = map_tdg_contract(¶ms);
assert!(result.is_ok());
}
#[test]
fn test_map_lint_hotspot_contract_minimal() {
let params = json!({
"path": valid_path()
});
let result = map_lint_hotspot_contract(¶ms);
assert!(result.is_ok());
}
#[test]
fn test_map_lint_hotspot_contract_with_file() {
let params = json!({
"path": valid_path(),
"file": "Cargo.toml"
});
let result = map_lint_hotspot_contract(¶ms);
assert!(result.is_ok());
}
#[test]
fn test_map_lint_hotspot_contract_with_all_options() {
let params = json!({
"path": valid_path(),
"file": "Cargo.toml",
"max_density": 2.5,
"min_confidence": 0.95,
"enforce": true,
"dry_run": true
});
let result = map_lint_hotspot_contract(¶ms);
assert!(result.is_ok());
}
#[test]
fn test_map_quality_gate_contract_minimal() {
let params = json!({
"path": valid_path()
});
let result = map_quality_gate_contract(¶ms);
assert!(result.is_ok());
}
#[test]
fn test_map_quality_gate_contract_with_all_profiles() {
for profile in &["standard", "strict", "extreme", "toyota"] {
let params = json!({
"path": valid_path(),
"profile": profile
});
let result = map_quality_gate_contract(¶ms);
assert!(result.is_ok(), "Failed for profile: {}", profile);
}
}
#[test]
fn test_map_quality_gate_contract_invalid_profile() {
let params = json!({
"path": valid_path(),
"profile": "invalid_profile"
});
let result = map_quality_gate_contract(¶ms);
assert!(result.is_ok());
}
#[test]
fn test_map_quality_gate_contract_with_all_options() {
let params = json!({
"path": valid_path(),
"profile": "toyota",
"file": "Cargo.toml",
"fail_on_violation": true,
"verbose": true
});
let result = map_quality_gate_contract(¶ms);
assert!(result.is_ok());
}
#[test]
fn test_map_refactor_auto_contract_minimal() {
let params = json!({
"file": "Cargo.toml"
});
let result = map_refactor_auto_contract(¶ms);
assert!(result.is_ok());
}
#[test]
fn test_map_refactor_auto_contract_missing_file() {
let params = json!({});
let result = map_refactor_auto_contract(¶ms);
assert!(result.is_err());
assert!(result.unwrap_err().to_string().contains("Missing required parameter: file"));
}
#[test]
fn test_map_refactor_auto_contract_with_all_options() {
let params = json!({
"file": "Cargo.toml",
"format": "yaml",
"output": "refactor.yaml",
"target_complexity": 5,
"dry_run": true,
"timeout": 300
});
let result = map_refactor_auto_contract(¶ms);
assert!(result.is_ok());
}
#[test]
fn test_parse_base_params_minimal() {
let params = json!({
"path": valid_path()
});
let result = parse_base_params(¶ms);
assert!(result.is_ok());
let base = result.unwrap();
assert_eq!(base.path.to_str().unwrap(), ".");
assert_eq!(base.format, OutputFormat::Table); assert!(base.output.is_none());
assert!(base.top_files.is_none());
assert!(!base.include_tests);
assert_eq!(base.timeout, 60); }
#[test]
fn test_parse_base_params_with_all_options() {
let params = json!({
"path": valid_path(),
"format": "json",
"output": "output.json",
"top_files": 50,
"include_tests": true,
"timeout": 180
});
let result = parse_base_params(¶ms);
assert!(result.is_ok());
let base = result.unwrap();
assert_eq!(base.format, OutputFormat::Json);
assert_eq!(base.output, Some(PathBuf::from("output.json")));
assert_eq!(base.top_files, Some(50));
assert!(base.include_tests);
assert_eq!(base.timeout, 180);
}
#[test]
fn test_parse_base_params_missing_path() {
let params = json!({
"format": "json"
});
let result = parse_base_params(¶ms);
assert!(result.is_err());
assert!(result.unwrap_err().to_string().contains("Missing required parameter: path"));
}
#[test]
fn test_parse_output_format_table() {
let value = json!("table");
assert_eq!(parse_output_format(&value), OutputFormat::Table);
}
#[test]
fn test_parse_output_format_json() {
let value = json!("json");
assert_eq!(parse_output_format(&value), OutputFormat::Json);
}
#[test]
fn test_parse_output_format_yaml() {
let value = json!("yaml");
assert_eq!(parse_output_format(&value), OutputFormat::Yaml);
}
#[test]
fn test_parse_output_format_markdown() {
let value = json!("markdown");
assert_eq!(parse_output_format(&value), OutputFormat::Markdown);
}
#[test]
fn test_parse_output_format_csv() {
let value = json!("csv");
assert_eq!(parse_output_format(&value), OutputFormat::Csv);
}
#[test]
fn test_parse_output_format_summary() {
let value = json!("summary");
assert_eq!(parse_output_format(&value), OutputFormat::Summary);
}
#[test]
fn test_parse_output_format_invalid() {
let value = json!("invalid");
assert_eq!(parse_output_format(&value), OutputFormat::Table); }
#[test]
fn test_parse_output_format_null() {
let value = json!(null);
assert_eq!(parse_output_format(&value), OutputFormat::Table); }
#[test]
fn test_parse_output_format_number() {
let value = json!(123);
assert_eq!(parse_output_format(&value), OutputFormat::Table); }
#[test]
fn test_parse_severity_low() {
let value = json!("low");
assert_eq!(parse_severity(&value), Some(SatdSeverity::Low));
}
#[test]
fn test_parse_severity_medium() {
let value = json!("medium");
assert_eq!(parse_severity(&value), Some(SatdSeverity::Medium));
}
#[test]
fn test_parse_severity_high() {
let value = json!("high");
assert_eq!(parse_severity(&value), Some(SatdSeverity::High));
}
#[test]
fn test_parse_severity_critical() {
let value = json!("critical");
assert_eq!(parse_severity(&value), Some(SatdSeverity::Critical));
}
#[test]
fn test_parse_severity_invalid() {
let value = json!("invalid");
assert_eq!(parse_severity(&value), None);
}
#[test]
fn test_parse_severity_null() {
let value = json!(null);
assert_eq!(parse_severity(&value), None);
}
#[test]
fn test_parse_severity_number() {
let value = json!(123);
assert_eq!(parse_severity(&value), None);
}
#[test]
fn test_parse_quality_profile_standard() {
let value = json!("standard");
assert_eq!(parse_quality_profile(&value), QualityProfile::Standard);
}
#[test]
fn test_parse_quality_profile_strict() {
let value = json!("strict");
assert_eq!(parse_quality_profile(&value), QualityProfile::Strict);
}
#[test]
fn test_parse_quality_profile_extreme() {
let value = json!("extreme");
assert_eq!(parse_quality_profile(&value), QualityProfile::Extreme);
}
#[test]
fn test_parse_quality_profile_toyota() {
let value = json!("toyota");
assert_eq!(parse_quality_profile(&value), QualityProfile::Toyota);
}
#[test]
fn test_parse_quality_profile_invalid() {
let value = json!("invalid");
assert_eq!(parse_quality_profile(&value), QualityProfile::Standard); }
#[test]
fn test_parse_quality_profile_null() {
let value = json!(null);
assert_eq!(parse_quality_profile(&value), QualityProfile::Standard); }
#[test]
fn test_parse_quality_profile_number() {
let value = json!(123);
assert_eq!(parse_quality_profile(&value), QualityProfile::Standard); }
#[test]
fn test_map_complexity_with_null_optional_params() {
let params = json!({
"path": valid_path(),
"max_cyclomatic": null,
"max_cognitive": null,
"max_halstead": null
});
let result = map_complexity_contract(¶ms);
assert!(result.is_ok());
}
#[test]
fn test_map_satd_with_boolean_false_defaults() {
let params = json!({
"path": valid_path(),
"critical_only": false,
"strict": false,
"fail_on_violation": false
});
let result = map_satd_contract(¶ms);
assert!(result.is_ok());
}
#[test]
fn test_map_dead_code_with_edge_values() {
let params = json!({
"path": valid_path(),
"min_dead_lines": 0,
"max_percentage": 0.0
});
let result = map_dead_code_contract(¶ms);
assert!(result.is_ok());
}
#[test]
fn test_map_tdg_with_zero_threshold() {
let params = json!({
"path": valid_path(),
"threshold": 0.0
});
let result = map_tdg_contract(¶ms);
assert!(result.is_ok());
}
#[test]
fn test_map_lint_hotspot_with_edge_confidence() {
let params = json!({
"path": valid_path(),
"min_confidence": 0.0,
"max_density": 0.0
});
let result = map_lint_hotspot_contract(¶ms);
assert!(result.is_ok());
}
#[test]
fn test_map_quality_gate_with_file() {
let params = json!({
"path": valid_path(),
"file": "Cargo.toml"
});
let result = map_quality_gate_contract(¶ms);
assert!(result.is_ok());
}
#[test]
fn test_map_refactor_auto_defaults() {
let params = json!({
"file": "Cargo.toml"
});
let result = map_refactor_auto_contract(¶ms);
assert!(result.is_ok());
}
#[test]
fn test_top_files_as_u64() {
let params = json!({
"path": valid_path(),
"top_files": 100u64
});
let result = parse_base_params(¶ms);
assert!(result.is_ok());
assert_eq!(result.unwrap().top_files, Some(100));
}
#[test]
fn test_timeout_as_u64() {
let params = json!({
"path": valid_path(),
"timeout": 300u64
});
let result = parse_base_params(¶ms);
assert!(result.is_ok());
assert_eq!(result.unwrap().timeout, 300);
}
#[test]
fn test_threshold_as_integer() {
let params = json!({
"path": valid_path(),
"threshold": 2
});
let result = map_tdg_contract(¶ms);
assert!(result.is_ok());
}
#[test]
fn test_all_format_types_in_context() {
let formats = vec!["table", "json", "yaml", "markdown", "csv", "summary"];
for format in formats {
let params = json!({
"path": valid_path(),
"format": format
});
let result = map_complexity_contract(¶ms);
assert!(result.is_ok(), "Failed for format: {}", format);
}
}
#[test]
fn test_full_complexity_analysis_workflow() {
let params = json!({
"path": valid_path(),
"format": "json",
"output": "complexity_report.json",
"top_files": 25,
"include_tests": true,
"timeout": 120,
"max_cyclomatic": 10,
"max_cognitive": 15,
"max_halstead": 50.0
});
let result = map_mcp_tool("analyze_complexity", params);
assert!(result.is_ok());
}
#[test]
fn test_full_satd_analysis_workflow() {
let params = json!({
"path": valid_path(),
"format": "markdown",
"severity": "high",
"critical_only": true,
"strict": true,
"fail_on_violation": false
});
let result = map_mcp_tool("analyze_satd", params);
assert!(result.is_ok());
}
#[test]
fn test_full_dead_code_analysis_workflow() {
let params = json!({
"path": valid_path(),
"format": "csv",
"include_unreachable": true,
"min_dead_lines": 5,
"max_percentage": 20.0,
"fail_on_violation": true
});
let result = map_mcp_tool("analyze_dead_code", params);
assert!(result.is_ok());
}
#[test]
fn test_full_tdg_analysis_workflow() {
let params = json!({
"path": valid_path(),
"format": "summary",
"threshold": 2.0,
"include_components": true,
"critical_only": false
});
let result = map_mcp_tool("analyze_tdg", params);
assert!(result.is_ok());
}
#[test]
fn test_full_quality_gate_workflow() {
let params = json!({
"path": valid_path(),
"format": "yaml",
"profile": "toyota",
"fail_on_violation": true,
"verbose": true
});
let result = map_mcp_tool("quality_gate", params);
assert!(result.is_ok());
}
}