#!/usr/bin/env python3
"""E123 standalone verifier: METR comparison honesty."""
from __future__ import annotations
import hashlib, json, sys
from pathlib import Path
C=[]
def check(n,ok,d=""): C.append((n,bool(ok),str(d)))
def main():
    root=Path(sys.argv[1] if len(sys.argv)>1 else ".")
    import ast
    tree=ast.parse(Path(__file__).read_text()); banned=[]
    for node in ast.walk(tree):
        if isinstance(node,ast.Import): banned += [a.name for a in node.names if a.name.split(".")[0]=="cain"]
        elif isinstance(node,ast.ImportFrom) and (node.module or "").split(".")[0]=="cain": banned.append(node.module)
    check("verifier imports no CAIN code", not banned, banned)
    man=json.loads((root/"MANIFEST.json").read_text())
    bad=[r for r,h in man["files"].items() if not (root/r).exists() or hashlib.sha256((root/r).read_bytes()).hexdigest()!=h]
    check(f"manifest hashes ({len(man['files'])})", not bad, bad[:5])
    d=json.loads((root/"E123_METR_RESULTS.json").read_text())
    check("published METR table present", d["metr"]["n_models"]>=20, d["metr"]["n_models"])
    check("top frontier horizon >= 6h", d["metr"]["top"][0]["p50_hours"]>=6, d["metr"]["top"][0])
    check("CAIN has no METR p50", d["cain"]["metr_p50_minutes"] is None)
    check("CAIN suite not run is stated", d["cain"]["metr_suite_run"] is False)
    check("6h not claimed as completed", d["cain"]["six_hour_workload"]["state"]!="PASS", d["cain"]["six_hour_workload"]["state"])
    check("governance axis is separate", "does not measure" in d["governance_axis"]["metr_models"])
    check("verdict says unranked", "unranked" in d["verdict"].lower())
    check("no AGI claim", "AGI" not in d["verdict"] or "not" in d["verdict"].lower(), d["verdict"])
    passed=sum(1 for _,ok,_ in C if ok)
    for n,ok,x in C: print(("PASS " if ok else "FAIL ")+n+(f" [{x}]" if (not ok and x) else ""))
    print(f"\n{passed}/{len(C)} checks passed")
    return 0 if passed==len(C) else 1
if __name__=="__main__": raise SystemExit(main())
