|
| 1 | +#!/usr/bin/env python3 |
| 2 | +from pathlib import Path |
| 3 | +import json |
| 4 | +import sys |
| 5 | + |
| 6 | +ROOT = Path(__file__).resolve().parents[1] |
| 7 | +errors = [] |
| 8 | + |
| 9 | +def need(cond, name): |
| 10 | + if cond: |
| 11 | + print(f"[VERIFY] {name}") |
| 12 | + else: |
| 13 | + print(f"[FAIL] {name}") |
| 14 | + errors.append(name) |
| 15 | + |
| 16 | +accepted_path = ROOT / "epochs/current/accepted-epoch-0001.json" |
| 17 | +index_path = ROOT / "epochs/current/index.json" |
| 18 | +history_readme = ROOT / "epochs/history/README.md" |
| 19 | + |
| 20 | +for rel in [ |
| 21 | + "epochs/current/accepted-epoch-0001.json", |
| 22 | + "epochs/current/index.json", |
| 23 | + "epochs/history/README.md", |
| 24 | + "current/epoch.json", |
| 25 | + "current/graph.json", |
| 26 | + "current/trust-summary.json", |
| 27 | + "current/contradictions.json", |
| 28 | + "current/repairs.json", |
| 29 | + "current/quarantine.json", |
| 30 | + "current/digest.txt", |
| 31 | +]: |
| 32 | + need((ROOT / rel).is_file(), f"file-present {rel}") |
| 33 | + |
| 34 | +accepted = json.loads(accepted_path.read_text(encoding="utf-8")) |
| 35 | +index = json.loads(index_path.read_text(encoding="utf-8")) |
| 36 | + |
| 37 | +need(accepted.get("object_type") == "AcceptedEpoch", "accepted-epoch-type") |
| 38 | +need(accepted.get("status") == "ACTIVE_TRUTH", "accepted-epoch-status") |
| 39 | +need(accepted.get("historical_archive_ref") == "epochs/history/", "accepted-epoch-history-ref") |
| 40 | +need(accepted.get("epoch_ref") == "current/epoch.json", "accepted-epoch-epoch-ref") |
| 41 | +need(accepted.get("graph_ref") == "current/graph.json", "accepted-epoch-graph-ref") |
| 42 | +need(accepted.get("trust_summary_ref") == "current/trust-summary.json", "accepted-epoch-trust-summary-ref") |
| 43 | +need(accepted.get("contradictions_ref") == "current/contradictions.json", "accepted-epoch-contradictions-ref") |
| 44 | +need(accepted.get("repairs_ref") == "current/repairs.json", "accepted-epoch-repairs-ref") |
| 45 | +need(accepted.get("quarantine_ref") == "current/quarantine.json", "accepted-epoch-quarantine-ref") |
| 46 | +need(accepted.get("digest_ref") == "current/digest.txt", "accepted-epoch-digest-ref") |
| 47 | + |
| 48 | +need(index.get("object_type") == "AcceptedEpochIndex", "accepted-epoch-index-type") |
| 49 | +need(index.get("status") == "ACTIVE_TRUTH", "accepted-epoch-index-status") |
| 50 | +need(index.get("historical") is False, "accepted-epoch-index-historical-false") |
| 51 | +need(index.get("current_accepted_epoch_ref") == "epochs/current/accepted-epoch-0001.json", "accepted-epoch-index-binding") |
| 52 | + |
| 53 | +entries = index.get("entries", []) |
| 54 | +need(len(entries) >= 1, "accepted-epoch-index-entry-present") |
| 55 | +if entries: |
| 56 | + first = entries[0] |
| 57 | + need(first.get("accepted_epoch_id") == accepted.get("accepted_epoch_id"), "accepted-epoch-index-entry-id") |
| 58 | + need(first.get("path") == "epochs/current/accepted-epoch-0001.json", "accepted-epoch-index-entry-path") |
| 59 | + need(first.get("epoch_ref") == "current/epoch.json", "accepted-epoch-index-entry-epoch-ref") |
| 60 | + need(first.get("graph_ref") == "current/graph.json", "accepted-epoch-index-entry-graph-ref") |
| 61 | + |
| 62 | +epoch = json.loads((ROOT / accepted["epoch_ref"]).read_text(encoding="utf-8")) |
| 63 | +graph = json.loads((ROOT / accepted["graph_ref"]).read_text(encoding="utf-8")) |
| 64 | +trust = json.loads((ROOT / accepted["trust_summary_ref"]).read_text(encoding="utf-8")) |
| 65 | +contradictions = json.loads((ROOT / accepted["contradictions_ref"]).read_text(encoding="utf-8")) |
| 66 | +repairs = json.loads((ROOT / accepted["repairs_ref"]).read_text(encoding="utf-8")) |
| 67 | +quarantine = json.loads((ROOT / accepted["quarantine_ref"]).read_text(encoding="utf-8")) |
| 68 | + |
| 69 | +need("epoch_id" in epoch, "epoch-object-readable") |
| 70 | +need("law_version" in epoch, "epoch-law-version-present") |
| 71 | +need("graph_digest" in epoch, "epoch-graph-digest-present") |
| 72 | +need(isinstance(graph, dict) and len(graph) > 0, "graph-surface-readable") |
| 73 | +need(isinstance(trust, dict) and len(trust) > 0, "trust-summary-readable") |
| 74 | +need(isinstance(contradictions.get("items"), list), "contradictions-readable") |
| 75 | +need(isinstance(repairs.get("items"), list), "repairs-readable") |
| 76 | +need(isinstance(quarantine.get("items"), list), "quarantine-readable") |
| 77 | +need("current/epoch.json" in (ROOT / "current/digest.txt").read_text(encoding="utf-8"), "digest-covers-current-epoch") |
| 78 | +need("historical" in history_readme.read_text(encoding="utf-8").lower(), "history-archive-explicit") |
| 79 | + |
| 80 | +if errors: |
| 81 | + print("[FAIL] PHASE 4 / STEP 51 accepted-epoch minimum verification failed") |
| 82 | + for e in errors: |
| 83 | + print(f" - {e}") |
| 84 | + sys.exit(1) |
| 85 | + |
| 86 | +print("[PASS] PHASE 4 / STEP 51 accepted-epoch minimum verified") |
0 commit comments