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)
diff=Path("offline-diff.txt").read_text()
check("-开课日期：2026-10-20" in diff and "+开课日期：2026-10-22" in diff,"real local text diff contains only date mutation")
def validate(v):
    c=v["data"]["changeTracking"]
    if not v.get("success") or c["changeStatus"]!="changed" or not c.get("previousScrapeAt") or not c.get("diff"):raise ValueError("actual changed response missing fields")
negative(validate,{"success":True,"data":{"changeTracking":{"changeStatus":"changed"}}},"changed without previous timestamp/diff rejected")
if args.actual:validate(load(args.actual));checks.append("actual response structure valid; manually compare diff to source")
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))
