from pathlib import Path
import argparse
import copy
import csv
import hashlib
import io
import json
import re

parser = argparse.ArgumentParser()
parser.add_argument("--actual")
parser.add_argument("--local-http", action="store_true")
args = parser.parse_args()
checks = []
def check(condition, label):
    if not condition:
        raise ValueError(label)
    checks.append(label)
def load(name): return json.loads(Path(name).read_text())
def rows(name): return list(csv.DictReader(io.StringIO(Path(name).read_text(encoding="utf-8-sig"))))
def negative(fn, value, label):
    try: fn(value)
    except (ValueError, AssertionError, KeyError, TypeError, IndexError): checks.append(label)
    else: raise AssertionError("Negative input accepted: " + label)
facts=load("task-facts.json")
check("QR-ERASE-071" in Path("manual.md").read_text(),"unique fictional marker present")
check(facts["expected_links"]["A-unlinked"]==["B"],"workspace removal keeps B reference in expected contract")
def validate(v):
    stages=v["stages"]
    if len(stages)!=3 or any(s["observed_links"] is None or not s["new_thread_answer"] for s in stages): raise ValueError("actual observations missing")
negative(validate,load("observations.json"),"empty erasure record not accepted as proof")
if args.actual: validate(load(args.actual));checks.append("observation record filled; actual erasure still needs product evidence")
report={"layer":"offline/material checks, not proof of unrun product or model", "checks":checks, "count":len(checks)}
Path("verification.json").write_text(json.dumps(report,ensure_ascii=False,indent=2))
print(json.dumps(report,ensure_ascii=False))
