{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://developer.reits.tech/schemas/runner-controller-installation-evidence.v1.schema.json",
  "title": "REITs D05 G07/G08 Controller Installation Evidence",
  "type": "object",
  "additionalProperties": false,
  "required": ["schemaVersion", "status", "observedAt", "observationMode", "program", "gateSummary", "gates", "host", "installation", "liveValidation", "verificationPacks", "operatorPlan", "safetyTruth"],
  "properties": {
    "schemaVersion": { "const": "developer.reits.tech/runner-controller-installation-evidence/v1" },
    "status": { "const": "G07_G08_DENIED_NO_HARDENED_INSTALLATION_OR_LIVE_RUNTIME_PROOFS" },
    "observedAt": { "type": "string", "format": "date-time" },
    "observationMode": { "const": "READ_ONLY_INSTALLATION_ENDPOINT_AND_WEBHOOK_AUDIT_NO_SERVICE_CHANGE" },
    "program": {
      "type": "object", "additionalProperties": false,
      "required": ["acceptedKnives", "totalKnives", "currentKnife", "closeoutCut", "remainingIncludingCurrent", "remainingAfterAcceptance", "d05Accepted"],
      "properties": {
        "acceptedKnives": { "const": 4 }, "totalKnives": { "const": 36 }, "currentKnife": { "const": "D05" }, "closeoutCut": { "const": 5 },
        "remainingIncludingCurrent": { "const": 32 }, "remainingAfterAcceptance": { "const": 31 }, "d05Accepted": { "const": false }
      }
    },
    "gateSummary": {
      "type": "object", "additionalProperties": false,
      "required": ["targetedGates", "satisfiedGates", "positiveAcceptanceReceipts", "missingInstallationReceipts", "missingLiveProofs", "decision"],
      "properties": {
        "targetedGates": { "const": 2 }, "satisfiedGates": { "const": 0 }, "positiveAcceptanceReceipts": { "const": 0 },
        "missingInstallationReceipts": { "const": 8 }, "missingLiveProofs": { "const": 8 },
        "decision": { "const": "DENY_AND_ESCALATE_TO_PLATFORM_SRE_AND_QA" }
      }
    },
    "gates": { "type": "array", "minItems": 2, "maxItems": 2, "items": { "$ref": "#/$defs/gate" } },
    "host": {
      "type": "object", "additionalProperties": false,
      "required": ["environment", "portalReleaseAtAudit", "portalSourceAtAudit", "checks"],
      "properties": {
        "environment": { "type": "string", "minLength": 10 },
        "portalReleaseAtAudit": { "type": "string", "pattern": "^developer-portal@[0-9a-f]{12}-[0-9a-f]{12}$" },
        "portalSourceAtAudit": { "type": "string", "pattern": "^[0-9a-f]{40}$" },
        "checks": { "type": "array", "minItems": 8, "maxItems": 8, "items": { "$ref": "#/$defs/hostCheck" } }
      }
    },
    "installation": {
      "type": "object", "additionalProperties": false,
      "required": ["sourceTemplate", "targetUnit", "serviceIdentity", "workingDirectory", "endpoint", "sourceStatus", "productionStatus", "hardening", "receiptRequirements"],
      "properties": {
        "sourceTemplate": { "const": "ops/runner-factory/reits-runner-factory-controller.service" },
        "targetUnit": { "const": "/etc/systemd/system/reits-runner-factory-controller.service" },
        "serviceIdentity": { "const": "reits-runner-factory:reits-runner-factory" },
        "workingDirectory": { "const": "/opt/reits-runner-factory/current" },
        "endpoint": { "const": "127.0.0.1:8110" },
        "sourceStatus": { "const": "IMPLEMENTED_PACKAGE_TEST_ONLY" },
        "productionStatus": { "const": "NOT_INSTALLED" },
        "hardening": { "type": "array", "minItems": 8, "maxItems": 8, "items": { "$ref": "#/$defs/hardening" } },
        "receiptRequirements": { "type": "array", "minItems": 8, "maxItems": 8, "items": { "$ref": "#/$defs/receipt" } }
      }
    },
    "liveValidation": {
      "type": "object", "additionalProperties": false,
      "required": ["listener", "listenerObserved", "probeAttempts", "applicationResponsesObserved", "proofsSatisfied", "connectionRefusalCountsAsDenialProof", "probes"],
      "properties": {
        "listener": { "const": "127.0.0.1:8110" }, "listenerObserved": { "const": 0 }, "probeAttempts": { "const": 8 },
        "applicationResponsesObserved": { "const": 0 }, "proofsSatisfied": { "const": 0 }, "connectionRefusalCountsAsDenialProof": { "const": false },
        "probes": { "type": "array", "minItems": 8, "maxItems": 8, "items": { "$ref": "#/$defs/probe" } }
      }
    },
    "verificationPacks": { "type": "array", "minItems": 4, "maxItems": 4, "items": { "$ref": "#/$defs/verificationPack" } },
    "operatorPlan": {
      "type": "object", "additionalProperties": false, "required": ["nextAction", "forbiddenActions"],
      "properties": {
        "nextAction": { "type": "string", "minLength": 160 },
        "forbiddenActions": { "type": "array", "minItems": 5, "maxItems": 5, "items": { "type": "string", "minLength": 50 } }
      }
    },
    "safetyTruth": {
      "type": "object", "additionalProperties": false,
      "required": ["readOnlyAuditPerformed", "loopbackProbeAttempts", "credentialsRecorded", "configurationWrites", "serviceInstallations", "systemdUnitsInstalled", "controllerServicesStarted", "listenerStarts", "applicationResponsesObserved", "negativeWebhookProofsIssued", "reverseProxyChanges", "externalReadsExecuted", "externalWritesExecuted", "paidResourcesCreated", "g07Satisfied", "g08Satisfied", "d05Accepted"],
      "properties": {
        "readOnlyAuditPerformed": { "const": true }, "loopbackProbeAttempts": { "const": 8 }, "credentialsRecorded": { "const": false },
        "configurationWrites": { "const": 0 }, "serviceInstallations": { "const": 0 }, "systemdUnitsInstalled": { "const": 0 },
        "controllerServicesStarted": { "const": 0 }, "listenerStarts": { "const": 0 }, "applicationResponsesObserved": { "const": 0 },
        "negativeWebhookProofsIssued": { "const": 0 }, "reverseProxyChanges": { "const": 0 }, "externalReadsExecuted": { "const": 0 },
        "externalWritesExecuted": { "const": 0 }, "paidResourcesCreated": { "const": false }, "g07Satisfied": { "const": false },
        "g08Satisfied": { "const": false }, "d05Accepted": { "const": false }
      }
    },
    "verification": { "type": "object" },
    "discovery": { "type": "object" }
  },
  "$defs": {
    "gate": {
      "type": "object", "additionalProperties": false, "required": ["id", "name", "owner", "target", "observed", "positiveReceiptsObserved", "decision"],
      "properties": {
        "id": { "enum": ["D05-G07", "D05-G08"] }, "name": { "type": "string" }, "owner": { "enum": ["PLATFORM_SRE", "QA"] },
        "target": { "type": "string", "minLength": 80 }, "observed": { "type": "string", "minLength": 60 }, "positiveReceiptsObserved": { "const": 0 },
        "decision": { "enum": ["DENIED_HARDENED_INSTALLATION_ABSENT", "DENIED_LIVE_RUNTIME_PROOFS_UNAVAILABLE"] }
      }
    },
    "hostCheck": {
      "type": "object", "additionalProperties": false, "required": ["id", "label", "target", "observed", "status"],
      "properties": {
        "id": { "pattern": "^INS-0[1-8]$" }, "label": { "type": "string" }, "target": { "type": "string" }, "observed": { "type": "string" },
        "status": { "enum": ["MISSING", "SAFE_ABSENT", "SAFE_CLOSED"] }
      }
    },
    "hardening": {
      "type": "object", "additionalProperties": false, "required": ["id", "requirement", "directives", "sourceStatus", "productionStatus"],
      "properties": {
        "id": { "type": "string" }, "requirement": { "type": "string", "minLength": 10 },
        "directives": { "type": "array", "minItems": 1, "items": { "type": "string", "minLength": 5 } },
        "sourceStatus": { "const": "IMPLEMENTED" }, "productionStatus": { "const": "MISSING" }
      }
    },
    "receipt": {
      "type": "object", "additionalProperties": false, "required": ["id", "proof", "status"],
      "properties": { "id": { "type": "string" }, "proof": { "type": "string", "minLength": 30 }, "status": { "const": "MISSING" } }
    },
    "probe": {
      "type": "object", "additionalProperties": false, "required": ["id", "category", "method", "path", "expected", "observedHttp", "observed", "proofStatus"],
      "properties": {
        "id": { "pattern": "^LIVE-0[1-8]$" },
        "category": { "enum": ["LIVENESS", "READINESS", "UNSIGNED_WEBHOOK", "INVALID_SIGNATURE", "STALE_DELIVERY", "REPLAY", "WRONG_SCOPE", "UNREADY"] },
        "method": { "enum": ["GET", "POST"] }, "path": { "enum": ["/healthz", "/readyz", "/webhooks/gitea"] },
        "expected": { "type": "string", "minLength": 30 }, "observedHttp": { "const": "000" },
        "observed": { "enum": ["CONNECTION_REFUSED_LISTENER_ABSENT", "NOT_EXECUTABLE_LISTENER_ABSENT"] },
        "proofStatus": { "const": "UNAVAILABLE_NOT_PASSED" }
      }
    },
    "verificationPack": {
      "type": "object", "additionalProperties": false, "required": ["id", "status", "fixtures", "accepted", "denied", "productionEffects"],
      "properties": {
        "id": { "enum": ["controller-service-package", "service-runtime-bootstrap", "activation-transaction", "target-host-driver-qualification"] },
        "status": { "type": "string", "pattern": "^PASS_(PACKAGE_TEST|FIXTURE)_ONLY$" }, "fixtures": { "type": "integer", "minimum": 1 },
        "accepted": { "type": "integer", "minimum": 0 }, "denied": { "type": "integer", "minimum": 0 }, "productionEffects": { "const": 0 }
      }
    }
  }
}
