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)
budget=rows("budget.csv");total=sum(int(r["quantity"])*int(r["unit_yuan"]) for r in budget)
check(total==680,"original budget recalculated: 680 yuan")
expected=["folder-chat-1","folder-chat-2","outside-new-chat"]
check([r["case"] for r in load("observations.json")["runs"]]==expected,"three independent cases declared")
def validate(v):
    if [r["case"] for r in v["runs"]]!=expected or any(not isinstance(r["answer"],str) or not r["answer"] for r in v["runs"]): raise ValueError("three actual answers required")
negative(validate,load("observations.json"),"pending observation does not prove product test")
if args.actual: validate(load(args.actual));checks.append("actual observation form complete, human source review remains")
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))
