mod tests {
    use super::*;
    use serde_json::json;

    // Helper to create a valid path for testing (current directory always exists)
    fn valid_path() -> &'static str {
        "."
    }

    // Tests for map_mcp_tool - main entry point

    #[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() {
        // Need to use an existing file
        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());
        let err = result.err().unwrap();
        assert!(err.to_string().contains("Unknown MCP tool"));
    }

    // Tests for map_complexity_contract

    #[test]
    fn test_map_complexity_contract_minimal() {
        let params = json!({
            "path": valid_path()
        });

        let result = map_complexity_contract(&params);
        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(&params);
        assert!(result.is_ok());
    }

    #[test]
    fn test_map_complexity_contract_missing_path() {
        let params = json!({});

        let result = map_complexity_contract(&params);
        assert!(result.is_err());
        let err = result.err().unwrap();
        assert!(err.to_string().contains("Missing required parameter: path"));
    }

    #[test]
    fn test_map_complexity_contract_invalid_halstead() {
        let params = json!({
            "path": valid_path(),
            "max_halstead": -1.0
        });

        let result = map_complexity_contract(&params);
        assert!(result.is_err());
        let err = result.err().unwrap();
        assert!(err.to_string().contains("max_halstead must be positive"));
    }

    // Tests for map_satd_contract

    #[test]
    fn test_map_satd_contract_minimal() {
        let params = json!({
            "path": valid_path()
        });

        let result = map_satd_contract(&params);
        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(&params);
            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(&params);
        assert!(result.is_ok());
    }

    #[test]
    fn test_map_satd_contract_invalid_severity() {
        let params = json!({
            "path": valid_path(),
            "severity": "invalid_severity"
        });

        // Invalid severity should result in None, not error
        let result = map_satd_contract(&params);
        assert!(result.is_ok());
    }

    // Tests for map_dead_code_contract

    #[test]
    fn test_map_dead_code_contract_minimal() {
        let params = json!({
            "path": valid_path()
        });

        let result = map_dead_code_contract(&params);
        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(&params);
        assert!(result.is_ok());
    }

    #[test]
    fn test_map_dead_code_contract_invalid_max_percentage() {
        let params = json!({
            "path": valid_path(),
            "max_percentage": 150.0
        });

        let result = map_dead_code_contract(&params);
        assert!(result.is_err());
        let err = result.err().unwrap();
        assert!(err.to_string().contains("max_percentage must be 0-100"));
    }

    #[test]
    fn test_map_dead_code_contract_negative_max_percentage() {
        let params = json!({
            "path": valid_path(),
            "max_percentage": -5.0
        });

        let result = map_dead_code_contract(&params);
        assert!(result.is_err());
    }

    // Tests for map_tdg_contract

    #[test]
    fn test_map_tdg_contract_minimal() {
        let params = json!({
            "path": valid_path()
        });

        let result = map_tdg_contract(&params);
        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(&params);
        assert!(result.is_ok());
    }

    #[test]
    fn test_map_tdg_contract_negative_threshold() {
        let params = json!({
            "path": valid_path(),
            "threshold": -1.0
        });

        let result = map_tdg_contract(&params);
        assert!(result.is_err());
        let err = result.err().unwrap();
        assert!(err.to_string().contains("threshold must be non-negative"));
    }

    // Tests for map_lint_hotspot_contract

    #[test]
    fn test_map_lint_hotspot_contract_minimal() {
        let params = json!({
            "path": valid_path()
        });

        let result = map_lint_hotspot_contract(&params);
        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(&params);
        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(&params);
        assert!(result.is_ok());
    }

    #[test]
    fn test_map_lint_hotspot_contract_invalid_confidence() {
        let params = json!({
            "path": valid_path(),
            "min_confidence": 1.5
        });

        let result = map_lint_hotspot_contract(&params);
        assert!(result.is_err());
        let err = result.err().unwrap();
        assert!(err.to_string().contains("min_confidence must be 0-1"));
    }

    #[test]
    fn test_map_lint_hotspot_contract_negative_confidence() {
        let params = json!({
            "path": valid_path(),
            "min_confidence": -0.5
        });

        let result = map_lint_hotspot_contract(&params);
        assert!(result.is_err());
    }

    #[test]
    fn test_map_lint_hotspot_contract_negative_density() {
        let params = json!({
            "path": valid_path(),
            "max_density": -1.0
        });

        let result = map_lint_hotspot_contract(&params);
        assert!(result.is_err());
        let err = result.err().unwrap();
        assert!(err.to_string().contains("max_density must be non-negative"));
    }

    // Tests for map_quality_gate_contract

    #[test]
    fn test_map_quality_gate_contract_minimal() {
        let params = json!({
            "path": valid_path()
        });

        let result = map_quality_gate_contract(&params);
        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(&params);
            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"
        });

        // Invalid profile should result in default (Standard), not error
        let result = map_quality_gate_contract(&params);
        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(&params);
        assert!(result.is_ok());
    }

    // Tests for map_refactor_auto_contract

    #[test]
    fn test_map_refactor_auto_contract_minimal() {
        let params = json!({
            "file": "Cargo.toml"
        });

        let result = map_refactor_auto_contract(&params);
        assert!(result.is_ok());
    }

    #[test]
    fn test_map_refactor_auto_contract_missing_file() {
        let params = json!({});

        let result = map_refactor_auto_contract(&params);
        assert!(result.is_err());
        let err = result.err().unwrap();
        assert!(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(&params);
        assert!(result.is_ok());
    }

    #[test]
    fn test_map_refactor_auto_contract_zero_target_complexity() {
        let params = json!({
            "file": "Cargo.toml",
            "target_complexity": 0
        });

        let result = map_refactor_auto_contract(&params);
        assert!(result.is_err());
        let err = result.err().unwrap();
        assert!(err.to_string().contains("target_complexity must be > 0"));
    }

    #[test]
    fn test_map_refactor_auto_contract_zero_timeout() {
        let params = json!({
            "file": "Cargo.toml",
            "timeout": 0
        });

        let result = map_refactor_auto_contract(&params);
        assert!(result.is_err());
        let err = result.err().unwrap();
        assert!(err.to_string().contains("timeout"));
    }

    // Tests for parse_base_params

    #[test]
    fn test_parse_base_params_minimal() {
        let params = json!({
            "path": valid_path()
        });

        let result = parse_base_params(&params);
        assert!(result.is_ok());

        let base = result.unwrap();
        assert_eq!(base.path.to_str().unwrap(), ".");
        assert_eq!(base.format, OutputFormat::Table); // default
        assert!(base.output.is_none());
        assert!(base.top_files.is_none());
        assert!(!base.include_tests);
        assert_eq!(base.timeout, 60); // default
    }

    #[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(&params);
        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(&params);
        assert!(result.is_err());
        let err = result.err().unwrap();
        assert!(err.to_string().contains("Missing required parameter: path"));
    }

    // Tests for parse_output_format

    #[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); // default
    }

    #[test]
    fn test_parse_output_format_null() {
        let value = json!(null);
        assert_eq!(parse_output_format(&value), OutputFormat::Table); // default
    }

    #[test]
    fn test_parse_output_format_number() {
        let value = json!(123);
        assert_eq!(parse_output_format(&value), OutputFormat::Table); // default
    }

    #[test]
    fn test_parse_output_format_boolean() {
        let value = json!(true);
        assert_eq!(parse_output_format(&value), OutputFormat::Table); // default
    }

    #[test]
    fn test_parse_output_format_empty_string() {
        let value = json!("");
        assert_eq!(parse_output_format(&value), OutputFormat::Table); // default
    }

    // Tests for parse_severity

    #[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_severity_empty_string() {
        let value = json!("");
        assert_eq!(parse_severity(&value), None);
    }

    #[test]
    fn test_parse_severity_case_sensitive() {
        // Should NOT match uppercase
        let value = json!("LOW");
        assert_eq!(parse_severity(&value), None);

        let value = json!("High");
        assert_eq!(parse_severity(&value), None);
    }

    // Tests for parse_quality_profile

    #[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); // default
    }

    #[test]
    fn test_parse_quality_profile_null() {
        let value = json!(null);
        assert_eq!(parse_quality_profile(&value), QualityProfile::Standard); // default
    }

    #[test]
    fn test_parse_quality_profile_number() {
        let value = json!(123);
        assert_eq!(parse_quality_profile(&value), QualityProfile::Standard); // default
    }

    #[test]
    fn test_parse_quality_profile_case_sensitive() {
        // Should NOT match uppercase
        let value = json!("STANDARD");
        assert_eq!(parse_quality_profile(&value), QualityProfile::Standard); // defaults

        let value = json!("Toyota");
        assert_eq!(parse_quality_profile(&value), QualityProfile::Standard); // defaults
    }

    // Edge case and error handling tests

    #[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(&params);
        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(&params);
        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(&params);
        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(&params);
        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(&params);
        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(&params);
        assert!(result.is_ok());
    }

    #[test]
    fn test_map_refactor_auto_defaults() {
        let params = json!({
            "file": "Cargo.toml"
        });

        let result = map_refactor_auto_contract(&params);
        assert!(result.is_ok());
        // Defaults: target_complexity=8, dry_run=false, timeout=60
    }

    // Tests with various JSON value types for type coercion

    #[test]
    fn test_top_files_as_u64() {
        let params = json!({
            "path": valid_path(),
            "top_files": 100u64
        });

        let result = parse_base_params(&params);
        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(&params);
        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(&params);
        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(&params);
            assert!(result.is_ok(), "Failed for format: {}", format);
        }
    }

    // Integration-style tests

    #[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());
    }

    // Path validation error tests

    #[test]
    fn test_nonexistent_path_returns_error() {
        let params = json!({
            "path": "/nonexistent/path/that/does/not/exist"
        });

        let result = map_complexity_contract(&params);
        assert!(result.is_err());
        let err = result.err().unwrap();
        assert!(err.to_string().contains("Path not found"));
    }

    #[test]
    fn test_nonexistent_file_in_refactor_auto() {
        let params = json!({
            "file": "/nonexistent/file.rs"
        });

        let result = map_refactor_auto_contract(&params);
        assert!(result.is_err());
        let err = result.err().unwrap();
        assert!(err.to_string().contains("Path not found"));
    }

    // Contract box behavior tests

    #[test]
    fn test_returned_contract_is_valid() {
        let params = json!({
            "path": valid_path()
        });

        let contract = map_mcp_tool("analyze_complexity", params).unwrap();
        // The contract was already validated, so this should succeed
        assert!(contract.validate().is_ok());
    }

    #[test]
    fn test_all_tools_return_box_dyn_contract() {
        let tools = vec![
            ("analyze_complexity", json!({"path": valid_path()})),
            ("analyze_satd", json!({"path": valid_path()})),
            ("analyze_dead_code", json!({"path": valid_path()})),
            ("analyze_tdg", json!({"path": valid_path()})),
            ("analyze_lint_hotspot", json!({"path": valid_path()})),
            ("quality_gate", json!({"path": valid_path()})),
            ("refactor_auto", json!({"file": "Cargo.toml"})),
        ];

        for (tool_name, params) in tools {
            let result = map_mcp_tool(tool_name, params);
            assert!(
                result.is_ok(),
                "Tool {} failed to create contract",
                tool_name
            );

            // Verify the returned contract is valid
            let contract = result.unwrap();
            assert!(
                contract.validate().is_ok(),
                "Contract for {} failed validation",
                tool_name
            );
        }
    }

    // Boundary value tests

    #[test]
    fn test_max_confidence_boundary() {
        // Exactly 1.0 should be valid
        let params = json!({
            "path": valid_path(),
            "min_confidence": 1.0
        });
        assert!(map_lint_hotspot_contract(&params).is_ok());

        // Exactly 0.0 should be valid
        let params = json!({
            "path": valid_path(),
            "min_confidence": 0.0
        });
        assert!(map_lint_hotspot_contract(&params).is_ok());
    }

    #[test]
    fn test_max_percentage_boundary() {
        // Exactly 100.0 should be valid
        let params = json!({
            "path": valid_path(),
            "max_percentage": 100.0
        });
        assert!(map_dead_code_contract(&params).is_ok());

        // Exactly 0.0 should be valid
        let params = json!({
            "path": valid_path(),
            "max_percentage": 0.0
        });
        assert!(map_dead_code_contract(&params).is_ok());
    }

    #[test]
    fn test_large_top_files_value() {
        let params = json!({
            "path": valid_path(),
            "top_files": 1000  // Maximum allowed
        });
        let result = parse_base_params(&params);
        assert!(result.is_ok());
    }

    #[test]
    fn test_too_large_top_files_value() {
        let params = json!({
            "path": valid_path(),
            "top_files": 1001  // Exceeds maximum
        });

        // parse_base_params itself doesn't validate, but the full contract does
        let result = map_complexity_contract(&params);
        assert!(result.is_err());
        let err = result.err().unwrap();
        assert!(err.to_string().contains("Too many files"));
    }
}


