|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""Validate SourceOS projection fixture shape without depending on sourceos-spec checkout.""" |
| 3 | + |
| 4 | +from __future__ import annotations |
| 5 | + |
| 6 | +import json |
| 7 | +from pathlib import Path |
| 8 | + |
| 9 | +ROOT = Path(__file__).resolve().parents[1] |
| 10 | +FIXTURE_DIR = ROOT / "fixtures" / "sourceos-spec" |
| 11 | + |
| 12 | +EXPECTED = { |
| 13 | + "sourceosmodelcarryref.json": "SourceOSModelCarryRef", |
| 14 | + "inferenceprovider.json": "InferenceProvider", |
| 15 | + "modelresidency.json": "ModelResidency", |
| 16 | + "placementfact.json": "PlacementFact", |
| 17 | + "agentmachinereceipt.json": "AgentMachineReceipt", |
| 18 | +} |
| 19 | + |
| 20 | +REQUIRED = { |
| 21 | + "SourceOSModelCarryRef": ["id", "type", "specVersion", "modelRef", "governanceRef", "routerProfileRef", "mutableModelState"], |
| 22 | + "InferenceProvider": ["id", "type", "specVersion", "providerClass", "endpointMode", "executionProfile", "trustPosture"], |
| 23 | + "ModelResidency": ["id", "type", "specVersion", "machineRef", "modelCarryRef", "providerRef", "residencyState", "observedAt"], |
| 24 | + "PlacementFact": ["id", "type", "specVersion", "machineRef", "observedAt", "hardware", "isolation", "trustPosture"], |
| 25 | + "AgentMachineReceipt": ["id", "type", "specVersion", "machineRef", "receiptClass", "issuedAt", "placementFactRefs", "policyDecisionRef", "verdict"], |
| 26 | +} |
| 27 | + |
| 28 | + |
| 29 | +def load(path: Path) -> dict: |
| 30 | + with path.open("r", encoding="utf-8") as handle: |
| 31 | + data = json.load(handle) |
| 32 | + if not isinstance(data, dict): |
| 33 | + raise AssertionError(f"{path}: root must be a JSON object") |
| 34 | + return data |
| 35 | + |
| 36 | + |
| 37 | +def main() -> int: |
| 38 | + for filename, expected_type in EXPECTED.items(): |
| 39 | + path = FIXTURE_DIR / filename |
| 40 | + if not path.exists(): |
| 41 | + raise AssertionError(f"missing fixture: {path.relative_to(ROOT)}") |
| 42 | + data = load(path) |
| 43 | + actual_type = data.get("type") |
| 44 | + if actual_type != expected_type: |
| 45 | + raise AssertionError(f"{path}: expected type {expected_type!r}, got {actual_type!r}") |
| 46 | + for field in REQUIRED[expected_type]: |
| 47 | + if field not in data: |
| 48 | + raise AssertionError(f"{path}: missing required projection field {field!r}") |
| 49 | + if not str(data.get("id", "")).startswith("urn:srcos:"): |
| 50 | + raise AssertionError(f"{path}: id must use urn:srcos prefix") |
| 51 | + print(f"VALID SourceOS projection fixture {path.relative_to(ROOT)}") |
| 52 | + return 0 |
| 53 | + |
| 54 | + |
| 55 | +if __name__ == "__main__": |
| 56 | + raise SystemExit(main()) |
0 commit comments