#!/usr/bin/env python3
"""py_diff_v2v.py — filtered real-CPython arm report.
Same corpus+classify as py_diff.py, but prints ONLY the summary counts and
any verdict-vs-verdict divergences (the dangerous class: both arms return a
verdict and they disagree). Crash-vs-verdict divergences are the documented
v1.0.2 out-of-domain edges; they are counted, not listed.

Self-locating; read-only. Usage: python3 py_diff_v2v.py
"""
import json, os, sys, datetime, importlib.util

DIR = os.path.dirname(os.path.abspath(__file__))
spec = importlib.util.spec_from_file_location("pointer_check", os.path.join(DIR, "pointer_check.py"))
pc = importlib.util.module_from_spec(spec)
spec.loader.exec_module(pc)

def run_py(ptr, fr, now_ms):
    now = datetime.datetime.fromtimestamp(now_ms / 1000, tz=datetime.timezone.utc)
    try:
        return pc.classify(ptr, fr, now)
    except Exception as e:
        return "CRASH:" + type(e).__name__

total = cvt = v2v = 0
v2v_ex = []
for line in open(os.path.join(DIR, "diff_corpus.jsonl")):
    c = json.loads(line)
    total += 1
    got = run_py(c["ptr"], c["fr"], c["now_ms"])
    want = c["js"]
    if (got == want) or (got.startswith("CRASH:") and want.startswith("CRASH:")):
        continue
    if got.startswith("CRASH:") or want.startswith("CRASH:"):
        cvt += 1
    else:
        v2v += 1
        if len(v2v_ex) < 10:
            v2v_ex.append({"js": want, "py": got, "ptr": c["ptr"], "fr": c["fr"]})

print("cases=%d crash_vs_verdict=%d VERDICT_VS_VERDICT=%d" % (total, cvt, v2v))
for e in v2v_ex:
    print(json.dumps(e)[:400])
sys.exit(0)
