#!/usr/bin/env python3 """Dependency-free structural checks for the draft profile and synthetic run.""" from __future__ import annotations import json import re from pathlib import Path ROOT = Path(__file__).resolve().parents[1] profile = json.loads((ROOT / "profile" / "sandbox-boundary-profile-v0.1.json").read_text()) schema = json.loads((ROOT / "schemas" / "observation.schema.json").read_text()) run = json.loads((ROOT / "examples" / "synthetic-characterization.json").read_text()) coverage_matrix = (ROOT / "examples" / "coverage-matrix.md").read_text() DIGEST = re.compile(r"^[a-f0-9]{64}$") RESULTS = {"pass", "fail", "indeterminate", "not_applicable", "stopped"} assert profile["version"] == "0.1.0" assert profile["output_type"] == "characterization" assert set(profile["result_states"]) == RESULTS def refs(value): if isinstance(value, dict): for key, child in value.items(): if key == "$ref": yield child yield from refs(child) elif isinstance(value, list): for child in value: yield from refs(child) assert all(ref.startswith("#/$defs/") for ref in refs(schema)) case_ids = [case["id"] for case in profile["cases"]] assert len(case_ids) == len(set(case_ids)) == 9 assert "CM-01" in case_ids assert run["classification"] == "simulation" assert run["output_type"] == "characterization" assert set(record["case"]["id"] for record in run["observations"]) == set(case_ids) assert len(run["observations"]) == len(case_ids) # The human-readable matrix is a release artifact, not decorative prose. Keep # it bound to the machine-readable profile so a renamed case cannot drift. matrix_rows = re.findall( r"^\|\s*([A-Z]{2}-\d{2})\s*\|\s*(yes|no)\s*\|\s*(yes|no)\s*\|\s*(yes|no)\s*\|\s*(pass|fail|indeterminate|not_applicable|stopped)\s*\|$", coverage_matrix, flags=re.MULTILINE, ) assert [row[0] for row in matrix_rows] == case_ids assert len(matrix_rows) == len(case_ids) assert all(row[1:4] == ("yes", "yes", "yes") for row in matrix_rows) result_by_case = {record["case"]["id"]: record["result"]["state"] for record in run["observations"]} assert {row[0]: row[4] for row in matrix_rows} == result_by_case for record in run["observations"]: assert record["profile"] == {"name": profile["profile_name"], "version": profile["version"], "output_type": "characterization"} assert record["case"]["version"] == "0.1" assert record["result"]["state"] in RESULTS assert record["result"]["classification"] == "characterization" for field in ("target_configuration_digest", "schema_dependency_digest"): assert DIGEST.fullmatch(record[field]) assert DIGEST.fullmatch(record["evidence"]["digest"]) assert record["controls"]["positive"]["valid"] is True assert record["controls"]["negative"]["valid"] is True if record["case"]["id"] == "LC-01": ts = record["timestamps"] assert ts["revocation_propagation_ms"] <= ts["declared_max_observation_window_ms"] print(f"valid: {len(case_ids)} cases, coverage matrix, and one complete synthetic characterization run")