{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/multi-agent-ecosystem/multi-agent-pipeline/pipeline/schemas/test-gen-gaps.schema.json",
  "title": "Multi-Agent Pipeline  -  test-gen gaps",
  "description": "The gap analysis of /multi-agent:test-gen, $RUN/gaps.json (multi-agent-refs/test-gen/stages.md). Written from the read-only analyst's answer: the selected inventory items set against the existing tests, each gap a scenario to write. `wrongly-covered` (a test exists but cannot see the failure) is kept apart from `missing`. dataNeeds[] says what test data a scenario needs and who provides it; it never holds a value, because values are entered by a person or resolved by secret reference at run time. unmeasured[] lists what the analysis could not measure, which is not the same as covered. test-gen-gate.mjs check --stage gaps checks this shape without a dependency.",
  "type": "object",
  "additionalProperties": false,
  "required": ["schemaVersion", "coverage", "gaps", "dataNeeds", "unmeasured"],
  "$defs": {
    "fileLine": { "type": "string", "pattern": "^[^\\s:]+:[1-9][0-9]*$" }
  },
  "properties": {
    "schemaVersion": { "const": "1.0.0" },
    "coverage": {
      "type": "object",
      "additionalProperties": false,
      "required": ["method", "measured"],
      "properties": {
        "method": {
          "enum": ["coverage_gap", "agent"],
          "description": "coverage_gap: the toolkit tool joined inventory and tests by identifier; agent: the analyst's own reading, on a toolkit without the tool."
        },
        "measured": { "type": "boolean" },
        "reason": { "type": "string", "minLength": 1 },
        "covered": { "type": "integer", "minimum": 0 },
        "uncovered": { "type": "integer", "minimum": 0 },
        "unmatched": { "type": "integer", "minimum": 0 }
      }
    },
    "gaps": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "inventoryId",
          "bucket",
          "title",
          "priority",
          "rationale",
          "expectation",
          "automation",
          "method"
        ],
        "properties": {
          "id": { "type": "string", "minLength": 1 },
          "inventoryId": { "type": "string", "minLength": 1 },
          "bucket": { "enum": ["missing", "wrongly-covered"] },
          "title": { "type": "string", "minLength": 1 },
          "priority": {
            "enum": ["bug-catching", "edge", "basic"],
            "description": "bug-catching: would catch a failure users hit; edge: a boundary or error path; basic: the happy path."
          },
          "rationale": {
            "type": "string",
            "minLength": 1,
            "description": "Why the business cares."
          },
          "expectation": {
            "type": "string",
            "minLength": 1,
            "description": "What the test asserts, measurable."
          },
          "automation": { "enum": ["yes", "no", "needs-code"] },
          "method": {
            "enum": ["exact", "inferred"],
            "description": "exact: matched by identifier; inferred: the analyst's judgement, kept apart."
          },
          "evidence": { "type": "array", "items": { "$ref": "#/$defs/fileLine" } },
          "handlesNeeded": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": ["target", "suggestion"],
              "properties": {
                "target": { "type": "string", "minLength": 1 },
                "suggestion": { "type": "string", "minLength": 1 }
              }
            }
          }
        }
      }
    },
    "dataNeeds": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "gapIds", "what", "kind"],
        "properties": {
          "id": { "type": "string", "minLength": 1 },
          "gapIds": {
            "type": "array",
            "minItems": 1,
            "items": { "type": "string", "minLength": 1 }
          },
          "what": { "type": "string", "minLength": 1 },
          "kind": { "enum": ["account", "seed", "fixture", "secret", "other"] },
          "secretRef": {
            "type": "string",
            "minLength": 1,
            "description": "Credential name a test resolves at run time; never the value."
          }
        }
      }
    },
    "unmeasured": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["reason"],
        "properties": {
          "inventoryId": { "type": "string", "minLength": 1 },
          "reason": { "type": "string", "minLength": 1 }
        }
      }
    }
  }
}
