"""Check a statement-review route: every item translated, sourced and judged; two signatures other than the author.""" import json, sys from pathlib import Path VERDICTS = {"match", "differs"} def fail(msg): print(f"rejected: {msg}") sys.exit(1) def main(): if len(sys.argv) != 2: fail("usage: python3 verify.py ") f = Path(sys.argv[1]) / "statement-review.json" if not f.exists(): fail("statement-review.json missing") try: d = json.loads(f.read_text(encoding="utf-8")) except ValueError as e: fail(f"statement-review.json is not JSON: {e}") if d.get("example"): print("EXAMPLE ONLY: fictional names and signatures; not evidence") items = d.get("items") if not isinstance(items, list) or not items: fail("items must be a nonempty list") seen = set() for i, it in enumerate(items, 1): for k in ("lean", "plain", "reference", "verdict"): if not isinstance(it.get(k), str) or not it[k].strip(): fail(f"item {i}: {k} missing") if it["lean"] in seen: fail(f"item {i}: {it['lean']} listed twice") seen.add(it["lean"]) if it["verdict"] not in VERDICTS: fail(f"item {i}: verdict must be match or differs") if it["verdict"] == "differs" and not str(it.get("note", "")).strip(): fail(f"item {i}: {it['lean']} differs but the note saying how is missing") author = str(d.get("author", "")).strip() if not author: fail("author missing") sigs = {s.strip() for s in d.get("signatures", []) if isinstance(s, str) and s.strip()} sigs.discard(author) if len(sigs) < 2: fail(f"need 2 signatures other than the author, found {len(sigs)}") differs = sum(it["verdict"] == "differs" for it in items) if differs: print(f"note: {differs} item(s) differ from the textbook; see their notes") print(f"statement: {len(items)} items reviewed, {len(sigs)} signatures ok") main()