{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://torneo.ai/schemas/restore_drill.v1",
  "title": "restore_drill.v1",
  "description": "Receipt of the backup and full-restore drill on a scratch platform (tools/restore_drill.py run_drill). A PASS has no problem, every hash verified, SQLite integrity ok, clean event chains and identical verify_run, decide and attestation answers on the restored copy. It never proves a restore of production storage (does_not_prove).",
  "type": "object",
  "required": [
    "schema",
    "scratch",
    "started_at",
    "budget_seconds",
    "backup_seconds",
    "restore_seconds",
    "phases",
    "archive",
    "refused_secret_like",
    "checks",
    "problems",
    "verdict",
    "proves",
    "does_not_prove"
  ],
  "additionalProperties": false,
  "properties": {
    "schema": {
      "const": "restore_drill.v1"
    },
    "scratch": {
      "const": true
    },
    "started_at": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
    },
    "budget_seconds": {
      "type": "integer",
      "minimum": 0
    },
    "backup_seconds": {
      "type": "number",
      "minimum": 0
    },
    "restore_seconds": {
      "type": "number",
      "minimum": 0
    },
    "phases": {
      "type": "object",
      "required": [
        "extract_and_hash",
        "verify"
      ],
      "additionalProperties": false,
      "properties": {
        "extract_and_hash": {
          "type": "number",
          "minimum": 0
        },
        "verify": {
          "type": "number",
          "minimum": 0
        }
      }
    },
    "archive": {
      "type": "object",
      "required": [
        "bytes",
        "sha256"
      ],
      "additionalProperties": false,
      "properties": {
        "bytes": {
          "type": "integer",
          "minimum": 0
        },
        "sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        }
      }
    },
    "refused_secret_like": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "checks": {
      "type": "object",
      "additionalProperties": false,
      "description": "Empty when the restore itself was refused (a tampered or unsafe archive).",
      "properties": {
        "files": {
          "type": "integer",
          "minimum": 0
        },
        "hashes_verified": {
          "type": "integer",
          "minimum": 0
        },
        "scheduler_logs": {
          "type": "object",
          "additionalProperties": {
            "type": "integer",
            "minimum": 0
          }
        },
        "sqlite_integrity": {
          "oneOf": [
            {
              "const": "ok"
            },
            {
              "type": "array",
              "minItems": 1,
              "items": {
                "type": "string"
              }
            }
          ]
        },
        "event_chain_problems": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "events": {
          "type": "object",
          "additionalProperties": {
            "type": "integer",
            "minimum": 0
          }
        },
        "registries": {
          "type": "object",
          "additionalProperties": {
            "type": "integer",
            "minimum": 0
          }
        },
        "verify_run": {
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "required": [
              "source",
              "restored",
              "identical"
            ],
            "additionalProperties": false,
            "properties": {
              "source": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "restored": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "identical": {
                "type": "boolean"
              }
            }
          }
        },
        "decide": {
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "required": [
              "verdict",
              "identical_to_source"
            ],
            "additionalProperties": false,
            "properties": {
              "verdict": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "identical_to_source": {
                "type": "boolean"
              }
            }
          }
        },
        "attestations": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "attestation_id",
              "verdict"
            ],
            "additionalProperties": false,
            "properties": {
              "attestation_id": {
                "type": "string",
                "pattern": "^[0-9a-f]{64}$"
              },
              "verdict": {
                "type": "string"
              }
            }
          }
        }
      }
    },
    "problems": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "verdict": {
      "enum": [
        "PASS",
        "FAIL"
      ]
    },
    "proves": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "does_not_prove": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "scratch_platform": {
      "type": "object",
      "required": [
        "built_from",
        "attestations_issued"
      ],
      "additionalProperties": false,
      "properties": {
        "built_from": {
          "type": "string"
        },
        "attestations_issued": {
          "type": "integer",
          "minimum": 0
        }
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "verdict": {
            "const": "PASS"
          }
        },
        "required": [
          "verdict"
        ]
      },
      "then": {
        "properties": {
          "problems": {
            "maxItems": 0
          },
          "checks": {
            "required": [
              "files",
              "hashes_verified",
              "scheduler_logs",
              "sqlite_integrity",
              "event_chain_problems",
              "events",
              "registries",
              "verify_run",
              "decide",
              "attestations"
            ],
            "properties": {
              "sqlite_integrity": {
                "const": "ok"
              },
              "event_chain_problems": {
                "maxItems": 0
              },
              "verify_run": {
                "additionalProperties": {
                  "properties": {
                    "identical": {
                      "const": true
                    }
                  }
                }
              },
              "decide": {
                "additionalProperties": {
                  "properties": {
                    "identical_to_source": {
                      "const": true
                    }
                  }
                }
              },
              "attestations": {
                "items": {
                  "properties": {
                    "verdict": {
                      "const": "VALID"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  ]
}
