{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://tenantatlas.local/specs/211-runtime-trend-recalibration/contracts/test-runtime-trend-history.schema.json",
  "title": "LaneTrendHistoryArtifact",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "laneId",
    "workflowProfile",
    "generatedAt",
    "policy",
    "history",
    "currentAssessment"
  ],
  "properties": {
    "schemaVersion": {
      "type": "string",
      "const": "1.0.0"
    },
    "laneId": {
      "type": "string",
      "enum": [
        "fast-feedback",
        "confidence",
        "heavy-governance",
        "browser",
        "junit",
        "profiling"
      ]
    },
    "workflowProfile": {
      "type": "string"
    },
    "generatedAt": {
      "type": "string",
      "format": "date-time"
    },
    "policy": {
      "$ref": "#/$defs/policy"
    },
    "history": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/historyRecord"
      }
    },
    "currentAssessment": {
      "$ref": "#/$defs/assessment"
    },
    "hotspotSnapshot": {
      "$ref": "#/$defs/hotspotSnapshot"
    },
    "recalibrationDecisions": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/recalibrationDecision"
      },
      "default": []
    },
    "warnings": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "default": []
    }
  },
  "$defs": {
    "policy": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "retentionLimit",
        "comparisonWindowSize",
        "minimumComparableSamples",
        "varianceFloorSeconds",
        "nearBudgetHeadroomSeconds",
        "hotspotFamilyLimit",
        "hotspotFileLimit",
        "slowestEntryRetention"
      ],
      "properties": {
        "retentionLimit": {
          "type": "integer",
          "minimum": 1
        },
        "comparisonWindowSize": {
          "type": "integer",
          "minimum": 1
        },
        "minimumComparableSamples": {
          "type": "integer",
          "minimum": 3
        },
        "varianceFloorSeconds": {
          "type": "integer",
          "minimum": 0
        },
        "nearBudgetHeadroomSeconds": {
          "type": "integer",
          "minimum": 0
        },
        "hotspotFamilyLimit": {
          "type": "integer",
          "minimum": 1
        },
        "hotspotFileLimit": {
          "type": "integer",
          "minimum": 1
        },
        "slowestEntryRetention": {
          "type": "integer",
          "minimum": 1
        },
        "recalibrationPolicy": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "baselineRequiresExplicitReview": {
              "type": "boolean"
            },
            "budgetRequiresExplicitReview": {
              "type": "boolean"
            },
            "minimumBudgetEvidenceSamples": {
              "type": "integer",
              "minimum": 1
            }
          }
        }
      }
    },
    "historyRecord": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "runRef",
        "laneId",
        "workflowId",
        "triggerClass",
        "generatedAt",
        "wallClockSeconds",
        "budgetSeconds",
        "budgetStatus",
        "blockingStatus",
        "comparisonFingerprint"
      ],
      "properties": {
        "runRef": {
          "type": "string"
        },
        "laneId": {
          "type": "string"
        },
        "workflowId": {
          "type": "string"
        },
        "triggerClass": {
          "type": "string",
          "enum": [
            "pull-request",
            "mainline-push",
            "manual",
            "scheduled",
            "local"
          ]
        },
        "generatedAt": {
          "type": "string",
          "format": "date-time"
        },
        "wallClockSeconds": {
          "type": "number",
          "minimum": 0
        },
        "baselineSeconds": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0
        },
        "baselineSource": {
          "type": [
            "string",
            "null"
          ]
        },
        "budgetSeconds": {
          "type": "number",
          "minimum": 0
        },
        "budgetStatus": {
          "type": "string"
        },
        "blockingStatus": {
          "type": "string"
        },
        "comparisonFingerprint": {
          "type": "string"
        },
        "classificationTotals": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/runtimeBucket"
          },
          "default": []
        },
        "familyTotals": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/runtimeBucket"
          },
          "default": []
        },
        "hotspotFiles": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/runtimeBucket"
          },
          "default": []
        },
        "slowestEntries": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/slowestEntry"
          },
          "default": []
        },
        "artifactRefs": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "summary": {
              "type": "string"
            },
            "report": {
              "type": "string"
            },
            "budget": {
              "type": "string"
            },
            "junit": {
              "type": "string"
            },
            "trendHistory": {
              "type": "string"
            }
          }
        }
      }
    },
    "assessment": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "healthClass",
        "recalibrationRecommendation",
        "budgetHeadroomSeconds",
        "summaryLine",
        "windowStatus",
        "sampleCount"
      ],
      "properties": {
        "healthClass": {
          "type": "string",
          "enum": [
            "healthy",
            "budget-near",
            "trending-worse",
            "regressed",
            "unstable"
          ]
        },
        "recalibrationRecommendation": {
          "type": "string",
          "enum": [
            "none",
            "investigate",
            "review-baseline",
            "review-budget"
          ]
        },
        "budgetHeadroomSeconds": {
          "type": "number"
        },
        "deltaToPreviousSeconds": {
          "type": [
            "number",
            "null"
          ]
        },
        "deltaToPreviousPercent": {
          "type": [
            "number",
            "null"
          ]
        },
        "deltaToBaselineSeconds": {
          "type": [
            "number",
            "null"
          ]
        },
        "deltaToBaselinePercent": {
          "type": [
            "number",
            "null"
          ]
        },
        "worseningStreak": {
          "type": "integer",
          "minimum": 0
        },
        "varianceObservedSeconds": {
          "type": "number",
          "minimum": 0
        },
        "windowStatus": {
          "type": "string",
          "enum": [
            "stable",
            "insufficient-history",
            "scope-changed",
            "noisy"
          ]
        },
        "sampleCount": {
          "type": "integer",
          "minimum": 0
        },
        "previousComparableRunRef": {
          "type": [
            "string",
            "null"
          ]
        },
        "summaryLine": {
          "type": "string"
        }
      }
    },
    "hotspotSnapshot": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "evidenceAvailability",
        "familyDeltas",
        "fileHotspots"
      ],
      "properties": {
        "evidenceAvailability": {
          "type": "string",
          "enum": [
            "available",
            "unavailable"
          ]
        },
        "familyDeltas": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/deltaBucket"
          }
        },
        "fileHotspots": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/deltaBucket"
          }
        },
        "newEntrants": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "default": []
        },
        "droppedEntrants": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "default": []
        }
      }
    },
    "recalibrationDecision": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "targetType",
        "decisionStatus",
        "evidenceRunRefs",
        "previousValueSeconds",
        "rationaleCode",
        "recordedIn",
        "notes"
      ],
      "properties": {
        "targetType": {
          "type": "string",
          "enum": [
            "baseline",
            "budget"
          ]
        },
        "decisionStatus": {
          "type": "string",
          "enum": [
            "candidate",
            "approved",
            "rejected"
          ]
        },
        "evidenceRunRefs": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string"
          }
        },
        "previousValueSeconds": {
          "type": "number",
          "minimum": 0
        },
        "proposedValueSeconds": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0
        },
        "rationaleCode": {
          "type": "string",
          "enum": [
            "lane-scope-change",
            "infrastructure-shift",
            "post-improvement-reset",
            "sustained-erosion",
            "noise-rejected",
            "manual-hold"
          ]
        },
        "recordedIn": {
          "type": "string",
          "description": "Active spec path or implementation PR reference for the approved or rejected recalibration decision."
        },
        "notes": {
          "type": "string"
        }
      }
    },
    "runtimeBucket": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name",
        "runtimeSeconds"
      ],
      "properties": {
        "name": {
          "type": "string"
        },
        "runtimeSeconds": {
          "type": "number",
          "minimum": 0
        }
      }
    },
    "slowestEntry": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "label",
        "runtimeSeconds"
      ],
      "properties": {
        "label": {
          "type": "string"
        },
        "runtimeSeconds": {
          "type": "number",
          "minimum": 0
        },
        "file": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "deltaBucket": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name",
        "currentSeconds",
        "previousSeconds",
        "deltaSeconds"
      ],
      "properties": {
        "name": {
          "type": "string"
        },
        "currentSeconds": {
          "type": "number",
          "minimum": 0
        },
        "previousSeconds": {
          "type": "number",
          "minimum": 0
        },
        "deltaSeconds": {
          "type": "number"
        },
        "deltaPercent": {
          "type": [
            "number",
            "null"
          ]
        },
        "direction": {
          "type": [
            "string",
            "null"
          ],
          "enum": [
            "up",
            "down",
            "flat",
            null
          ]
        }
      }
    }
  }
}