pmat 3.17.0

PMAT - Zero-config AI context generation and code quality toolkit (CLI, MCP, HTTP)
//! Protocol adapter integration and cross-protocol equivalence
//! Target: <45s execution time, network simulation

use serde_json::json;
use std::collections::HashMap;

#[test]
fn test_json_rpc_format() {
    // Test basic JSON-RPC 2.0 format
    let request = json!({
        "jsonrpc": "2.0",
        "method": "test_method",
        "params": {"key": "value"},
        "id": 1
    });

    assert_eq!(request["jsonrpc"], "2.0");
    assert_eq!(request["method"], "test_method");
    assert_eq!(request["id"], 1);
}

#[test]
fn test_http_request_format() {
    // Test HTTP request format
    let mut headers = HashMap::new();
    headers.insert("content-type".to_string(), "application/json".to_string());
    headers.insert("accept".to_string(), "application/json".to_string());

    assert_eq!(
        headers.get("content-type"),
        Some(&"application/json".to_string())
    );
    assert_eq!(headers.get("accept"), Some(&"application/json".to_string()));
}

#[test]
fn test_cli_argument_parsing() {
    // Test CLI argument format
    let args = ["analyze", "complexity", ".", "--json"];

    assert_eq!(args[0], "analyze");
    assert_eq!(args[1], "complexity");
    assert_eq!(args[2], ".");
    assert!(args.contains(&"--json"));
}

#[test]
fn test_protocol_response_formats() {
    // Test different response formats

    // JSON-RPC response
    let jsonrpc_response = json!({
        "jsonrpc": "2.0",
        "result": {"status": "success"},
        "id": 1
    });

    // HTTP response
    let http_response = json!({
        "status": 200,
        "body": {"status": "success"}
    });

    // CLI response
    let cli_response = json!({
        "status": "success"
    });

    // All should contain success status
    assert_eq!(jsonrpc_response["result"]["status"], "success");
    assert_eq!(http_response["body"]["status"], "success");
    assert_eq!(cli_response["status"], "success");
}

#[test]
fn test_error_response_formats() {
    // Test error response formats across protocols

    // JSON-RPC error
    let jsonrpc_error = json!({
        "jsonrpc": "2.0",
        "error": {
            "code": -32601,
            "message": "Method not found"
        },
        "id": 1
    });

    // HTTP error
    let http_error = json!({
        "status": 404,
        "error": "Not Found"
    });

    // CLI error
    let cli_error = json!({
        "error": "Command not found"
    });

    assert_eq!(jsonrpc_error["error"]["code"], -32601);
    assert_eq!(http_error["status"], 404);
    assert!(cli_error["error"].is_string());
}

#[test]
fn test_parameter_normalization() {
    // Test that parameters are normalized across protocols

    let mcp_params = json!({
        "path": ".",
        "threshold": 10,
        "format": "json"
    });

    let http_params = json!({
        "path": ".",
        "options": {
            "threshold": 10,
            "format": "json"
        }
    });

    let cli_params = [".", "--threshold", "10", "--format", "json"];

    // Extract normalized values
    assert_eq!(mcp_params["path"], ".");
    assert_eq!(mcp_params["threshold"], 10);

    assert_eq!(http_params["path"], ".");
    assert_eq!(http_params["options"]["threshold"], 10);

    assert_eq!(cli_params[0], ".");
    assert!(cli_params.contains(&"--threshold"));
    assert!(cli_params.contains(&"10"));
}