{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:benchx:schema:env-identity:0.1.0",
  "title": "BenchX environment identity",
  "description": "The shape of coordinates.environment when coordinates.environment.schema_version is \"benchx/env-identity/0.1.0\" (docs/design/runner-schema.md §5.2). A fact goes in identity when it names the machine, and in system otherwise.",
  "$comment": "coordinates.environment.identity is deliberately open in schemas/measurement-result/0.1.0 (minProperties: 1 only), to allow other identity schemas. A validator applies this schema to a result's coordinates.environment object only when its schema_version field equals \"benchx/env-identity/0.1.0\". GPU UUIDs stay out of identity (in system) so that swapping a card of the same model does not split history; the device a result used is coordinates.resource_selection, not here.",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema_version", "identity"],
  "properties": {
    "schema_version": {
      "const": "benchx/env-identity/0.1.0"
    },
    "identity": {
      "type": "object",
      "additionalProperties": false,
      "required": ["machine_id", "cpu", "memory_bytes", "os", "virtualization", "policy", "enforced"],
      "properties": {
        "machine_id": {
          "description": "Salted hash of /etc/machine-id or equivalent.",
          "type": "string",
          "minLength": 1
        },
        "cpu": {
          "type": "object",
          "additionalProperties": false,
          "required": ["model", "logical_cores"],
          "properties": {
            "model": { "type": "string", "minLength": 1 },
            "logical_cores": { "type": "integer", "minimum": 1 }
          }
        },
        "memory_bytes": { "type": "integer", "minimum": 0 },
        "gpus": {
          "description": "Visible accelerators by model. GPU UUIDs are in system, not here.",
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["model", "memory_bytes"],
            "properties": {
              "model": { "type": "string", "minLength": 1 },
              "memory_bytes": { "type": "integer", "minimum": 0 }
            }
          }
        },
        "os": {
          "type": "object",
          "additionalProperties": false,
          "required": ["family"],
          "properties": {
            "family": { "type": "string", "minLength": 1 }
          }
        },
        "virtualization": {
          "enum": ["bare-metal", "vm", "container", "wsl"]
        },
        "policy": {
          "description": "The environment policy applied, as name@version (schemas/environment-policy/0.1.0).",
          "type": "string",
          "pattern": "^\\S+@\\S+$"
        },
        "enforced": {
          "description": "The values the policy actually applied, keyed by check name (runner-schema.md §4.1).",
          "type": "object"
        }
      }
    },
    "system": {
      "description": "Facts that do not name the machine: hostname, GPU UUIDs, BIOS/firmware strings, and the fields of runner-schema.md §5.3.",
      "type": "object"
    }
  }
}
