|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Validate the synthetic Runtime Impossibility Receipt example against the v0.1 schema. |
| 4 | +
|
| 5 | +Claim boundary: |
| 6 | +This script validates schema conformance for a synthetic path-local receipt. |
| 7 | +It does not prove production readiness, compliance, medical safety, adoption, or path-universal coverage. |
| 8 | +""" |
| 9 | + |
| 10 | +from __future__ import annotations |
| 11 | + |
| 12 | +import json |
| 13 | +from pathlib import Path |
| 14 | +from urllib.parse import urlparse |
| 15 | + |
| 16 | +try: |
| 17 | + import jsonschema |
| 18 | +except ImportError as exc: # pragma: no cover |
| 19 | + raise SystemExit( |
| 20 | + "Missing dependency: jsonschema\n" |
| 21 | + "Install it with: python -m pip install jsonschema" |
| 22 | + ) from exc |
| 23 | + |
| 24 | + |
| 25 | +ROOT = Path(__file__).resolve().parents[1] |
| 26 | +SCHEMA_PATH = ROOT / "docs" / "schemas" / "Runtime_Impossibility_Receipt_Schema_v0.1.json" |
| 27 | +RECEIPT_PATH = ROOT / "docs" / "schemas" / "examples" / "runtime_impossibility_receipt_email_refusal_v0.1.json" |
| 28 | + |
| 29 | + |
| 30 | +def _strip_unsupported_format_on_nullable_datetime(schema: object) -> object: |
| 31 | + """Keep the demo dependency-light by avoiding nullable date-time format edge cases. |
| 32 | +
|
| 33 | + The schema is still the source of truth. This only removes format checking from fields |
| 34 | + where the value may intentionally be null in a refusal example. |
| 35 | + """ |
| 36 | + if isinstance(schema, dict): |
| 37 | + cleaned = {} |
| 38 | + for key, value in schema.items(): |
| 39 | + if key == "format" and schema.get("type") == ["string", "null"]: |
| 40 | + continue |
| 41 | + cleaned[key] = _strip_unsupported_format_on_nullable_datetime(value) |
| 42 | + return cleaned |
| 43 | + if isinstance(schema, list): |
| 44 | + return [_strip_unsupported_format_on_nullable_datetime(item) for item in schema] |
| 45 | + return schema |
| 46 | + |
| 47 | + |
| 48 | +def load_json(path: Path) -> dict: |
| 49 | + with path.open("r", encoding="utf-8") as handle: |
| 50 | + return json.load(handle) |
| 51 | + |
| 52 | + |
| 53 | +def main() -> int: |
| 54 | + schema = load_json(SCHEMA_PATH) |
| 55 | + receipt = load_json(RECEIPT_PATH) |
| 56 | + |
| 57 | + validator_schema = _strip_unsupported_format_on_nullable_datetime(schema) |
| 58 | + jsonschema.validate(instance=receipt, schema=validator_schema) |
| 59 | + |
| 60 | + print("Runtime Impossibility Receipt: VALID") |
| 61 | + print(f"Verdict: {receipt['verdict']}") |
| 62 | + print(f"Attempted action: {receipt['attempted_action']}") |
| 63 | + print(f"Downstream effect prevented: {receipt['downstream_effect_prevented']}") |
| 64 | + print(f"Human review required: {str(receipt['human_review_required']).lower()}") |
| 65 | + print(f"Claim boundary: {receipt['claim_boundary']}") |
| 66 | + |
| 67 | + return 0 |
| 68 | + |
| 69 | + |
| 70 | +if __name__ == "__main__": |
| 71 | + raise SystemExit(main()) |
0 commit comments