#!/usr/bin/env python3
"""verify_bridge.py — don't trust the site's headline. Recompute it.

Solonic claims exactly one of 154 typed edges crosses a domain boundary
(Bell's theorem -> the measurement problem). This recomputes that from
atlas-edges.json. If it prints anything other than 1, the site is wrong and
you should tell them — that's what the errata page is for.
"""
import json, sys, os
E = json.load(open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "atlas-edges.json")))
nodes, edges = E["nodes"], E["edges"]
cross = [(nodes[a]["n"], nodes[a]["d"], nodes[b]["n"], nodes[b]["d"], t)
         for a, b, t in edges
         if nodes[a]["d"] != nodes[b]["d"] and "hub" not in (nodes[a]["d"], nodes[b]["d"])]
print(f"total edges: {len(edges)}")
print(f"cross-domain edges: {len(cross)}")
for f, fd, tt, td, ty in cross:
    print(f"  {f} ({fd}) --{ty}--> {tt} ({td})")
sys.exit(0 if len(cross) == 1 else 1)  # nonzero exit if the site's claim is stale
