{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://aslice.sh/schematics/worker-capabilities.schema.json",
  "title": "worker-capabilities",
  "description": "Inventory is not authority. Null measurements and empty capabilities are pending; only authenticated qualified observations authorize scheduling. Semantics: docs/BUILD-INFRA.md capability inventory",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "format": {
      "const": 1
    },
    "worker_id": {
      "type": "string",
      "minLength": 1
    },
    "physical_builder_id": {
      "type": "string",
      "minLength": 1
    },
    "model": {
      "type": "string",
      "minLength": 1
    },
    "enrollment": {
      "anyOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "digest": {
              "type": "string",
              "pattern": "^sha256:[0-9a-f]{64}$"
            },
            "size": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            }
          },
          "required": [
            "digest",
            "size"
          ]
        },
        {
          "type": "null"
        }
      ]
    },
    "observed_at": {
      "anyOf": [
        {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        {
          "type": "null"
        }
      ]
    },
    "host_os": {
      "anyOf": [
        {
          "type": "string",
          "minLength": 1
        },
        {
          "type": "null"
        }
      ]
    },
    "cpu_features": {
      "anyOf": [
        {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 0,
          "uniqueItems": true
        },
        {
          "type": "null"
        }
      ]
    },
    "ram_bytes": {
      "anyOf": [
        {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        {
          "type": "null"
        }
      ]
    },
    "disk_bytes": {
      "anyOf": [
        {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        {
          "type": "null"
        }
      ]
    },
    "capabilities": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "os": {
            "type": "string",
            "minLength": 1
          },
          "flavor": {
            "enum": [
              "v1",
              "v2",
              "v3"
            ]
          },
          "cpu_features": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            },
            "minItems": 0,
            "uniqueItems": true
          },
          "os_register_state_verified": {
            "type": "boolean"
          },
          "image_digest": {
            "type": "string",
            "pattern": "^sha256:[0-9a-f]{64}$"
          },
          "hypervisor": {
            "type": "string",
            "minLength": 1
          },
          "ram_bytes": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "disk_bytes": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "build_seconds": {
            "anyOf": [
              {
                "type": "integer",
                "minimum": 0,
                "maximum": 9007199254740991
              },
              {
                "type": "null"
              }
            ]
          },
          "test_seconds": {
            "anyOf": [
              {
                "type": "integer",
                "minimum": 0,
                "maximum": 9007199254740991
              },
              {
                "type": "null"
              }
            ]
          },
          "vm_prepare_seconds": {
            "anyOf": [
              {
                "type": "integer",
                "minimum": 0,
                "maximum": 9007199254740991
              },
              {
                "type": "null"
              }
            ]
          },
          "qualification": {
            "enum": [
              "pending",
              "qualified",
              "failed"
            ]
          },
          "evidence": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "digest": {
                  "type": "string",
                  "pattern": "^sha256:[0-9a-f]{64}$"
                },
                "size": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 9007199254740991
                }
              },
              "required": [
                "digest",
                "size"
              ]
            },
            "minItems": 0,
            "uniqueItems": true
          }
        },
        "required": [
          "os",
          "flavor",
          "cpu_features",
          "os_register_state_verified",
          "image_digest",
          "hypervisor",
          "ram_bytes",
          "disk_bytes",
          "build_seconds",
          "test_seconds",
          "vm_prepare_seconds",
          "qualification",
          "evidence"
        ],
        "allOf": [
          {
            "if": {
              "properties": {
                "qualification": {
                  "const": "qualified"
                }
              }
            },
            "then": {
              "properties": {
                "os_register_state_verified": {
                  "const": true
                },
                "evidence": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                      "digest": {
                        "type": "string",
                        "pattern": "^sha256:[0-9a-f]{64}$"
                      },
                      "size": {
                        "type": "integer",
                        "minimum": 0,
                        "maximum": 9007199254740991
                      }
                    },
                    "required": [
                      "digest",
                      "size"
                    ]
                  },
                  "minItems": 1,
                  "uniqueItems": true
                },
                "ram_bytes": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 9007199254740991
                },
                "disk_bytes": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 9007199254740991
                },
                "build_seconds": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 9007199254740991
                },
                "test_seconds": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 9007199254740991
                },
                "vm_prepare_seconds": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 9007199254740991
                }
              }
            }
          }
        ]
      },
      "minItems": 0,
      "uniqueItems": true
    }
  },
  "required": [
    "format",
    "worker_id",
    "physical_builder_id",
    "model",
    "enrollment",
    "observed_at",
    "host_os",
    "cpu_features",
    "ram_bytes",
    "disk_bytes",
    "capabilities"
  ]
}
