Files

85 lines
2.7 KiB
Python

#!/usr/bin/env python3
"""CHECK: verify the extracted wizard roster against the source table.
Exit 0 = artifact matches the source table and summary is internally consistent.
Exit 1 = mismatch (verdict: wrong).
"""
import csv
import json
import re
import sys
SRC = "/root/troupe-standup/WIZARDS-TABLE.md"
CSV_PATH = "/root/troupe-standup/wizard-work/ledger/wizard-roster.csv"
JSON_PATH = "/root/troupe-standup/wizard-work/ledger/roster-summary.json"
problems = []
# --- Re-parse the source roster table ---
with open(SRC, "r", encoding="utf-8") as f:
src_lines = f.read().splitlines()
header_found = False
expected = []
for ln in src_lines:
cells = [c.strip() for c in ln.split("|")]
cells = [c for c in cells if c != ""]
if cells == ["Wizard", "Model", "Lane", "Latest check-in", "Current unit"]:
header_found = True
continue
if header_found and cells and all(re.fullmatch(r"-+", c) for c in cells):
# separator line -> skip
continue
if header_found:
# heading or end of table
if ln.startswith("#") or not ln:
continue
if len(cells) == 5:
expected.append(cells)
continue
if not header_found:
problems.append("source header not found")
if len(expected) != 10:
problems.append(f"source has {len(expected)} roster rows (want 10)")
# --- Read produced CSV ---
with open(CSV_PATH, newline="", encoding="utf-8") as f:
reader = csv.DictReader(f)
csv_rows = list(reader)
csv_fields = reader.fieldnames
want_fields = ["Wizard", "Model", "Lane", "Latest check-in", "Current unit"]
if csv_fields != want_fields:
problems.append(f"CSV fields {csv_fields} != {want_fields}")
if len(csv_rows) != 10:
problems.append(f"CSV has {len(csv_rows)} data rows (want 10)")
csv_wizards = [r["Wizard"] for r in csv_rows]
if csv_wizards != [e[0] for e in expected]:
problems.append("CSV wizard order/names != source")
empty_cells = [r["Wizard"] for r in csv_rows if any(not (c or "").strip() for c in r.values())]
if empty_cells:
problems.append(f"empty cells in CSV: {empty_cells}")
# --- Read produced JSON ---
with open(JSON_PATH, encoding="utf-8") as f:
summary = json.load(f)
if summary.get("total_wizards") != 10:
problems.append(f"summary.total_wizards={summary.get('total_wizards')}")
if summary.get("staffed") != ["Argus", "Beam", "Sentinel", "Volt"]:
problems.append(f"summary.staffed={summary.get('staffed')}")
if [w["Wizard"] for w in summary.get("wizards", [])] != csv_wizards:
problems.append("summary.wizards != CSV wizards")
if problems:
print("CHECK FAILED")
for p in problems:
print(" -", p)
sys.exit(1)
print("CHECK PASSED: 10 wizards, fields match, summary consistent, no empty cells")