"""Recompute the Gamma-sampled T1 of every validated salt from inputs/<salt>/couplings_judged.json and compare with the
validator's signed value (inputs/<salt>/reported/validator_receipt_*.json). Seconds per salt; code/ only."""
import glob, json, sys
from pathlib import Path
HERE = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(HERE / "code"))
from t1_recompute import t1_gamma  # noqa: E402
worst = 0.0
for d in sorted((HERE / "inputs").iterdir()):
    rec = glob.glob(str(d / "reported" / "validator_receipt_*.json"))
    if not rec: continue
    exp = {s: v * 1e6 for s, v in json.load(open(rec[0]))["details"]["t1_s"].items()}
    got = t1_gamma(json.loads((d / "couplings_judged.json").read_text()), [5, 10, 20])
    dev = max(abs(got[s] / exp[s] - 1) for s in exp); worst = max(worst, dev)
    print(f"{d.name:12s} T1 (us) sigma 5/10/20: {got['5']:.4f} / {got['10']:.4f} / {got['20']:.4f}   max rel diff vs validator {dev:.1e}")
assert worst < 1e-6, worst
print("ALL VALIDATED SALTS REPRODUCED")
