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)
source=Path("course.md").read_text();ref=Path("reference.mmd").read_text()
check(source.count("## ")==3,"three original chapters")
for value in ["背景声","脚步声","交通声"]: check(value in source and value in ref,"source/reference contain "+value)
def validate(v):
    if any(x not in v for x in ["记录现场","整理录音","复习与检查"]):raise ValueError("chapter missing")
validate(ref);negative(validate,ref.replace("整理录音",""),"missing branch rejected")
check(load("product-observations.json")["actual_map_file"] is None,"manual reference is not mislabeled as product output")
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))
