#!/usr/bin/env python3 """Final CHECK for the arXiv cs.LG table extraction. Usage: python3 verify_arxiv_csv.py Exit 0 => artifact valid; nonzero => invalid. """ import csv import re import sys def _check(cond, msg="check failed"): """Explicit failure path -- survives `python3 -O`, where `assert` is compiled away.""" if not cond: raise SystemExit(f"FAIL: {msg}") EXPECTED_HEADER = ["arxiv_id", "title", "authors", "published", "abstract"] ID_RE = re.compile(r"^[0-9]{4}\.[0-9]{4,5}$") DATE_RE = re.compile(r"^[0-9]{4}-[0-9]{2}-[0-9]{2}$") def main(): path = sys.argv[1] if len(sys.argv) > 1 else "/root/troupe-standup/wizard-work/ledger/arxiv-lg-recent.csv" with open(path, newline="", encoding="utf-8") as f: rows = list(csv.DictReader(f)) _check(rows, "no data rows") _check(list(rows[0].keys()) == EXPECTED_HEADER, f"bad header {list(rows[0].keys())}") _check(len(rows) == 20, f"expected 20 rows, got {len(rows)}") for i, r in enumerate(rows, start=1): _check(ID_RE.match(r["arxiv_id"].strip()), f"row {i} bad arxiv_id {r['arxiv_id']!r}") _check(DATE_RE.match(r["published"].strip()), f"row {i} bad date {r['published']!r}") for col in ("title", "authors", "abstract"): _check((r[col] or "").strip(), f"row {i} empty {col}") dates = sorted({r["published"] for r in rows}) print(f"rows_ok=20 header_ok=1 ids_ok=1 dates_ok=1 date_range={dates[0]}..{dates[-1]}") print("sample=" + rows[0]["arxiv_id"] + " " + rows[0]["title"][:50]) if __name__ == "__main__": main()