{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://tenantpilot.local/specs/210/contracts/ci-lane-matrix.schema.json",
  "title": "CI Lane Matrix Contract",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "version",
    "mainlineBranch",
    "workflowProfiles",
    "laneBindings",
    "budgetEnforcementProfiles",
    "failureClasses"
  ],
  "properties": {
    "version": {
      "type": "integer",
      "minimum": 1
    },
    "mainlineBranch": {
      "type": "string",
      "minLength": 1
    },
    "workflowProfiles": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/definitions/workflowProfile"
      }
    },
    "laneBindings": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/definitions/laneBinding"
      }
    },
    "budgetEnforcementProfiles": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/definitions/budgetEnforcementProfile"
      }
    },
    "artifactPublicationContracts": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/artifactPublicationContract"
      }
    },
    "failureClasses": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/definitions/failureClassification"
      }
    }
  },
  "definitions": {
    "workflowProfile": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "workflowId",
        "filePath",
        "triggerClass",
        "gitEvents",
        "runnerLabel",
        "blockingDefault",
        "laneBindings"
      ],
      "properties": {
        "workflowId": {
          "type": "string",
          "minLength": 1
        },
        "filePath": {
          "type": "string",
          "pattern": "^\\.gitea/workflows/.+\\.ya?ml$"
        },
        "triggerClass": {
          "enum": [
            "pull-request",
            "mainline-push",
            "scheduled",
            "manual"
          ]
        },
        "gitEvents": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "branchFilters": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "runnerLabel": {
          "type": "string",
          "minLength": 1
        },
        "blockingDefault": {
          "type": "boolean"
        },
        "scheduleCron": {
          "type": [
            "string",
            "null"
          ]
        },
        "laneBindings": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    },
    "laneBinding": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "laneId",
        "executionWrapper",
        "reportWrapper",
        "commandRef",
        "governanceClass",
        "requiredArtifacts"
      ],
      "properties": {
        "laneId": {
          "enum": [
            "fast-feedback",
            "confidence",
            "heavy-governance",
            "browser",
            "profiling",
            "junit"
          ]
        },
        "executionWrapper": {
          "const": "scripts/platform-test-lane"
        },
        "reportWrapper": {
          "const": "scripts/platform-test-report"
        },
        "commandRef": {
          "type": "string",
          "minLength": 1
        },
        "governanceClass": {
          "enum": [
            "fast",
            "confidence",
            "heavy",
            "support"
          ]
        },
        "parallelMode": {
          "enum": [
            "required",
            "optional",
            "forbidden"
          ]
        },
        "requiredArtifacts": {
          "type": "array",
          "minItems": 1,
          "items": {
            "enum": [
              "summary.md",
              "budget.json",
              "report.json",
              "junit.xml",
              "profile.txt"
            ]
          }
        },
        "optionalArtifacts": {
          "type": "array",
          "items": {
            "enum": [
              "summary.md",
              "budget.json",
              "report.json",
              "junit.xml",
              "profile.txt"
            ]
          }
        },
        "artifactExportProfile": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "budgetEnforcementProfile": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "policyId",
        "laneId",
        "triggerClass",
        "thresholdSource",
        "baseThresholdSeconds",
        "varianceAllowanceSeconds",
        "effectiveThresholdSeconds",
        "enforcementMode",
        "lifecycleState"
      ],
      "properties": {
        "policyId": {
          "type": "string",
          "minLength": 1
        },
        "laneId": {
          "type": "string",
          "minLength": 1
        },
        "triggerClass": {
          "enum": [
            "pull-request",
            "mainline-push",
            "scheduled",
            "manual"
          ]
        },
        "thresholdSource": {
          "enum": [
            "lane-budget",
            "governance-contract"
          ]
        },
        "baseThresholdSeconds": {
          "type": "number",
          "minimum": 0
        },
        "varianceAllowanceSeconds": {
          "type": "number",
          "minimum": 0
        },
        "effectiveThresholdSeconds": {
          "type": "number",
          "minimum": 0
        },
        "enforcementMode": {
          "enum": [
            "hard-fail",
            "soft-warn",
            "trend-only"
          ]
        },
        "lifecycleState": {
          "type": "string",
          "minLength": 1
        },
        "reviewCadence": {
          "type": "string"
        }
      }
    },
    "artifactPublicationContract": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "contractId",
        "laneId",
        "sourceDirectory",
        "requiredFiles",
        "stagingDirectory",
        "stagedNamePattern",
        "uploadGroupName"
      ],
      "properties": {
        "contractId": {
          "type": "string",
          "minLength": 1
        },
        "laneId": {
          "type": "string",
          "minLength": 1
        },
        "sourceDirectory": {
          "const": "storage/logs/test-lanes"
        },
        "sourcePatterns": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "requiredFiles": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "optionalFiles": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "stagingDirectory": {
          "type": "string",
          "minLength": 1
        },
        "stagedNamePattern": {
          "type": "string",
          "minLength": 1
        },
        "uploadGroupName": {
          "type": "string",
          "minLength": 1
        },
        "retentionClass": {
          "enum": [
            "pr-short",
            "mainline-medium",
            "scheduled-medium"
          ]
        }
      }
    },
    "failureClassification": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "failureClassId",
        "sourceStep",
        "blockingOn",
        "summaryLabel",
        "remediationHint"
      ],
      "properties": {
        "failureClassId": {
          "enum": [
            "test-failure",
            "wrapper-failure",
            "budget-breach",
            "artifact-publication-failure",
            "infrastructure-failure"
          ]
        },
        "sourceStep": {
          "type": "string",
          "minLength": 1
        },
        "blockingOn": {
          "type": "array",
          "items": {
            "enum": [
              "pull-request",
              "mainline-push",
              "scheduled",
              "manual"
            ]
          }
        },
        "summaryLabel": {
          "type": "string",
          "minLength": 1
        },
        "remediationHint": {
          "type": "string",
          "minLength": 1
        }
      }
    }
  }
}