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)
data=load("records.json")
selected=[r for r in data if r["file"]=="lake-project.md" and "2026-10-01"<=r["date"]<="2026-10-31" and "撤销" not in r["text"]]
check([r["id"] for r in selected]==["L03","L12"],"date/file/negative word baseline yields two records")
check(len(data)==6,"six original entries")
def validate(v):
    if [r["id"] for r in v]!=["L03","L12"]: raise ValueError("wrong source or date included")
negative(validate,selected+[data[0]],"September record rejected")
negative(validate,selected+[data[4]],"other file rejected")
Path("filter-result.json").write_text(json.dumps(selected,ensure_ascii=False,indent=2))
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))
