{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://github.com/ruvnet/ggen/schemas/mutation-report.json",
  "title": "Mutation Report Schema",
  "description": "Structured output for 'ggen test mutate' command. Contains mutation testing results, kill rates, and survived mutants.",
  "type": "object",
  "required": ["summary", "mutants", "metadata"],
  "properties": {
    "summary": {
      "type": "object",
      "description": "High-level mutation testing metrics",
      "required": [
        "total_mutants",
        "killed",
        "survived",
        "timeout",
        "compilation_error",
        "kill_rate",
        "execution_time_ms"
      ],
      "properties": {
        "total_mutants": {
          "type": "integer",
          "description": "Total number of mutants generated",
          "minimum": 0
        },
        "killed": {
          "type": "integer",
          "description": "Number of mutants killed by tests",
          "minimum": 0
        },
        "survived": {
          "type": "integer",
          "description": "Number of mutants that survived (tests did not catch)",
          "minimum": 0
        },
        "timeout": {
          "type": "integer",
          "description": "Number of mutants that timed out during execution",
          "minimum": 0
        },
        "compilation_error": {
          "type": "integer",
          "description": "Number of mutants that failed to compile",
          "minimum": 0
        },
        "kill_rate": {
          "type": "number",
          "description": "Percentage of mutants killed (killed / (total - compilation_error))",
          "minimum": 0.0,
          "maximum": 1.0
        },
        "execution_time_ms": {
          "type": "integer",
          "description": "Total mutation testing execution time in milliseconds",
          "minimum": 0
        },
        "target_met": {
          "type": "boolean",
          "description": "True if kill rate meets or exceeds target threshold"
        },
        "target_details": {
          "type": "object",
          "properties": {
            "target": {"type": "number", "minimum": 0.0, "maximum": 1.0},
            "actual": {"type": "number", "minimum": 0.0, "maximum": 1.0},
            "difference": {"type": "number"}
          }
        }
      }
    },
    "mutants": {
      "type": "array",
      "description": "Individual mutant results",
      "items": {
        "type": "object",
        "required": [
          "id",
          "file",
          "line",
          "column",
          "operator",
          "original",
          "mutated",
          "status"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique mutant identifier (e.g., 'mut_001')",
            "pattern": "^mut_\\d+$"
          },
          "file": {
            "type": "string",
            "description": "Relative path to source file containing mutation"
          },
          "line": {
            "type": "integer",
            "description": "Line number of mutation",
            "minimum": 1
          },
          "column": {
            "type": "integer",
            "description": "Column number of mutation",
            "minimum": 1
          },
          "operator": {
            "type": "string",
            "enum": [
              "replace-binary-op",
              "negate-condition",
              "remove-return",
              "replace-const",
              "swap-args",
              "remove-semicolon",
              "change-literal"
            ],
            "description": "Mutation operator applied"
          },
          "original": {
            "type": "string",
            "description": "Original source code snippet"
          },
          "mutated": {
            "type": "string",
            "description": "Mutated source code snippet"
          },
          "status": {
            "type": "string",
            "enum": ["killed", "survived", "timeout", "compilation_error"],
            "description": "Mutant execution status"
          },
          "killed_by": {
            "type": "array",
            "description": "List of test cases that killed this mutant (only if status = killed)",
            "items": {
              "type": "string",
              "description": "Test case identifier (e.g., 'tests/aci/tool_selection_tests.rs::test_best_match')"
            }
          },
          "execution_time_ms": {
            "type": "integer",
            "description": "Time to detect mutant (milliseconds)",
            "minimum": 0
          },
          "severity": {
            "type": "string",
            "enum": ["critical", "high", "medium", "low"],
            "description": "Severity if mutant survived (impact on production)"
          },
          "recommendation": {
            "type": "string",
            "description": "Suggested action if mutant survived (e.g., 'Add test for edge case X')"
          }
        }
      }
    },
    "operators": {
      "type": "array",
      "description": "Per-operator mutation statistics",
      "items": {
        "type": "object",
        "required": ["operator", "total", "killed", "survived", "kill_rate"],
        "properties": {
          "operator": {
            "type": "string",
            "description": "Mutation operator name"
          },
          "total": {
            "type": "integer",
            "description": "Total mutants for this operator",
            "minimum": 0
          },
          "killed": {
            "type": "integer",
            "description": "Mutants killed for this operator",
            "minimum": 0
          },
          "survived": {
            "type": "integer",
            "description": "Mutants survived for this operator",
            "minimum": 0
          },
          "kill_rate": {
            "type": "number",
            "description": "Kill rate for this operator (0.0-1.0)",
            "minimum": 0.0,
            "maximum": 1.0
          }
        }
      }
    },
    "files": {
      "type": "array",
      "description": "Per-file mutation statistics",
      "items": {
        "type": "object",
        "required": ["file", "total", "killed", "survived", "kill_rate"],
        "properties": {
          "file": {
            "type": "string",
            "description": "Relative path to source file"
          },
          "total": {
            "type": "integer",
            "description": "Total mutants in this file",
            "minimum": 0
          },
          "killed": {
            "type": "integer",
            "description": "Mutants killed in this file",
            "minimum": 0
          },
          "survived": {
            "type": "integer",
            "description": "Mutants survived in this file",
            "minimum": 0
          },
          "kill_rate": {
            "type": "number",
            "description": "Kill rate for this file (0.0-1.0)",
            "minimum": 0.0,
            "maximum": 1.0
          },
          "hotspots": {
            "type": "array",
            "description": "Code hotspots with low kill rates (needs more tests)",
            "items": {
              "type": "object",
              "properties": {
                "line_range": {
                  "type": "string",
                  "description": "Line range (e.g., '145-160')"
                },
                "kill_rate": {
                  "type": "number",
                  "minimum": 0.0,
                  "maximum": 1.0
                },
                "recommendation": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "metadata": {
      "type": "object",
      "description": "Command execution metadata",
      "required": [
        "command",
        "version",
        "timestamp",
        "arguments"
      ],
      "properties": {
        "command": {
          "type": "string",
          "description": "Full command executed",
          "const": "ggen test mutate"
        },
        "version": {
          "type": "string",
          "description": "ggen version (semver)",
          "pattern": "^\\d+\\.\\d+\\.\\d+$"
        },
        "timestamp": {
          "type": "string",
          "description": "ISO 8601 timestamp of execution",
          "format": "date-time"
        },
        "arguments": {
          "type": "object",
          "description": "Command-line arguments used",
          "properties": {
            "paths": {
              "type": "array",
              "items": {"type": "string"}
            },
            "mutators": {
              "type": "array",
              "items": {"type": "string"}
            },
            "timeout_multiplier": {"type": "number"},
            "kill_rate_target": {"type": "number"},
            "fail_on_target": {"type": "boolean"},
            "parallel": {"type": "integer"},
            "sample_rate": {"type": "number"}
          }
        },
        "execution_environment": {
          "type": "object",
          "properties": {
            "rust_version": {"type": "string"},
            "cargo_version": {"type": "string"},
            "os": {"type": "string"},
            "cpu_count": {"type": "integer"}
          }
        }
      }
    }
  },
  "examples": [
    {
      "summary": {
        "total_mutants": 342,
        "killed": 298,
        "survived": 44,
        "timeout": 0,
        "compilation_error": 0,
        "kill_rate": 0.871,
        "execution_time_ms": 45600,
        "target_met": true,
        "target_details": {
          "target": 0.80,
          "actual": 0.871,
          "difference": 0.071
        }
      },
      "mutants": [
        {
          "id": "mut_001",
          "file": "crates/ggen-core/src/graph/store.rs",
          "line": 145,
          "column": 20,
          "operator": "replace-binary-op",
          "original": "==",
          "mutated": "!=",
          "status": "killed",
          "killed_by": [
            "tests/graph/store_tests.rs::test_upsert",
            "tests/graph/store_tests.rs::test_get_existing"
          ],
          "execution_time_ms": 125
        },
        {
          "id": "mut_002",
          "file": "crates/ggen-core/src/graph/store.rs",
          "line": 89,
          "column": 15,
          "operator": "negate-condition",
          "original": "if cache.contains_key(key)",
          "mutated": "if !cache.contains_key(key)",
          "status": "survived",
          "execution_time_ms": 450,
          "severity": "high",
          "recommendation": "Add test case verifying cache hit behavior when key exists"
        }
      ],
      "operators": [
        {
          "operator": "replace-binary-op",
          "total": 180,
          "killed": 165,
          "survived": 15,
          "kill_rate": 0.917
        },
        {
          "operator": "negate-condition",
          "total": 120,
          "killed": 95,
          "survived": 25,
          "kill_rate": 0.792
        },
        {
          "operator": "remove-return",
          "total": 42,
          "killed": 38,
          "survived": 4,
          "kill_rate": 0.905
        }
      ],
      "files": [
        {
          "file": "crates/ggen-core/src/graph/store.rs",
          "total": 85,
          "killed": 72,
          "survived": 13,
          "kill_rate": 0.847,
          "hotspots": [
            {
              "line_range": "85-95",
              "kill_rate": 0.60,
              "recommendation": "Add tests for cache eviction logic"
            }
          ]
        }
      ],
      "metadata": {
        "command": "ggen test mutate",
        "version": "0.4.0",
        "timestamp": "2025-12-11T10:45:00Z",
        "arguments": {
          "paths": ["crates/ggen-core/src/"],
          "mutators": ["all"],
          "timeout_multiplier": 2.0,
          "kill_rate_target": 0.80,
          "fail_on_target": false,
          "parallel": 8,
          "sample_rate": 1.0
        },
        "execution_environment": {
          "rust_version": "1.74.0",
          "cargo_version": "1.74.0",
          "os": "linux",
          "cpu_count": 8
        }
      }
    }
  ]
}
