{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:orbiplex:schema:federation-run:v1",
  "title": "Federation Run v1",
  "description": "Redacted aggregate manifest for one leased federation acceptance run.",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema", "schema/v", "run/id", "scenario/ref", "topology/digest", "profile/digest", "owner/slot", "topology/evidence", "nodes", "started/at", "status"],
  "properties": {
    "schema": { "const": "federation-run.v1" },
    "schema/v": { "const": 1 },
    "run/id": { "type": "string", "pattern": "^federation-run:[^\\s]+$", "maxLength": 256 },
    "scenario/ref": { "type": "string", "pattern": "^story-[A-Za-z0-9._:-]+$", "maxLength": 256 },
    "topology/digest": { "$ref": "#/$defs/digest" },
    "profile/digest": { "$ref": "#/$defs/digest" },
    "owner/slot": { "type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]*$", "maxLength": 64 },
    "topology/evidence": { "$ref": "#/$defs/topologyEvidence" },
    "nodes": { "type": "array", "minItems": 2, "maxItems": 32, "items": { "$ref": "federation-node.v1.schema.json" } },
    "story/evidence": { "$ref": "#/$defs/storyEvidence" },
    "assertions": {
      "type": "array",
      "minItems": 1,
      "maxItems": 64,
      "items": { "$ref": "#/$defs/assertionResult" }
    },
    "started/at": { "type": "string", "format": "date-time" },
    "ended/at": { "type": "string", "format": "date-time" },
    "status": { "enum": ["planned", "running", "passed", "failed", "refused"] }
  },
  "$defs": {
    "digest": { "type": "string", "pattern": "^sha256:[A-Za-z0-9_-]{43}$" },
    "rawDigest": { "type": "string", "pattern": "^sha256:[a-f0-9]{64}$" },
    "token": { "type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9._:/-]*$", "maxLength": 256 },
    "topologyEvidence": {
      "type": "object",
      "additionalProperties": false,
      "required": ["host-posture", "logical-node-count", "physical-host-count", "shared-failure-domains", "evidence/ceiling"],
      "properties": {
        "host-posture": { "enum": ["distinct-physical-hosts", "shared-physical-hosts"] },
        "logical-node-count": { "type": "integer", "minimum": 2, "maximum": 32 },
        "physical-host-count": { "type": "integer", "minimum": 1, "maximum": 32 },
        "shared-failure-domains": {
          "type": "array",
          "maxItems": 16,
          "items": {
            "type": "array",
            "minItems": 2,
            "maxItems": 32,
            "uniqueItems": true,
            "items": { "$ref": "#/$defs/token" }
          }
        },
        "profile-claim/ref": {
          "enum": [
            "acceptance-claim:story-012-two-physical-host-three-node-codex-reviewer-v1",
            "acceptance-claim:story-012-three-physical-host-three-node-codex-reviewer-v1"
          ]
        },
        "evidence/ceiling": { "enum": ["profile-defined", "diagnostic-not-promotable"] }
      },
      "allOf": [{
        "if": {
          "required": ["host-posture"],
          "properties": { "host-posture": { "const": "shared-physical-hosts" } }
        },
        "then": { "properties": {
          "shared-failure-domains": { "minItems": 1 }
        } },
        "else": { "properties": {
          "shared-failure-domains": { "maxItems": 0 },
          "evidence/ceiling": { "const": "profile-defined" }
        } }
      }, {
        "if": {
          "required": ["host-posture", "evidence/ceiling"],
          "properties": {
            "host-posture": { "const": "shared-physical-hosts" },
            "evidence/ceiling": { "const": "profile-defined" }
          }
        },
        "then": {
          "required": ["profile-claim/ref"],
          "properties": {
            "profile-claim/ref": {
              "const": "acceptance-claim:story-012-two-physical-host-three-node-codex-reviewer-v1"
            }
          }
        }
      }, {
        "if": {
          "required": ["evidence/ceiling"],
          "properties": { "evidence/ceiling": { "const": "diagnostic-not-promotable" } }
        },
        "then": { "not": { "required": ["profile-claim/ref"] } }
      }, {
        "if": {
          "required": ["host-posture"],
          "properties": {
            "host-posture": { "const": "distinct-physical-hosts" }
          }
        },
        "then": {
          "properties": {
            "profile-claim/ref": {
              "const": "acceptance-claim:story-012-three-physical-host-three-node-codex-reviewer-v1"
            }
          }
        }
      }]
    },
    "storyEvidence": {
      "type": "object",
      "additionalProperties": false,
      "required": ["report/schema", "report/profile-id", "report/raw-digest", "checks", "measurements", "status"],
      "properties": {
        "report/schema": { "$ref": "#/$defs/token" },
        "report/profile-id": { "$ref": "#/$defs/token" },
        "report/raw-digest": { "$ref": "#/$defs/rawDigest" },
        "checks": { "type": "array", "minItems": 1, "maxItems": 128, "uniqueItems": true, "items": { "$ref": "#/$defs/token" } },
        "measurements": {
          "type": "object",
          "additionalProperties": false,
          "required": ["duration/ms", "deliberation/ms"],
          "properties": {
            "duration/ms": { "type": "integer", "minimum": 0, "maximum": 7200000 },
            "deliberation/ms": { "type": "integer", "minimum": 0, "maximum": 1800000 }
          }
        },
        "status": { "const": "passed" }
      }
    },
    "assertionResult": {
      "type": "object",
      "additionalProperties": false,
      "required": ["assertion/id", "status"],
      "properties": {
        "assertion/id": { "$ref": "#/$defs/token" },
        "node/ref": { "$ref": "#/$defs/token" },
        "status": { "const": "passed" }
      }
    }
  }
}
