76 lines
2.1 KiB
Python
76 lines
2.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Verify the sol triage-review queue CSV.
|
|
|
|
Golden-master check: the CSV on disk must equal the GOLDEN table exactly
|
|
(header, 16 rows, no blank fields, priority as int). Exit 0 => correct,
|
|
nonzero => wrong. GOLDEN comes from the committed generator module.
|
|
"""
|
|
import csv
|
|
import sys
|
|
|
|
sys.path.insert(0, "/root/.hermes/wizard-outputs/sol")
|
|
import triage_review # noqa: E402
|
|
|
|
PATH = "/root/.hermes/wizard-outputs/sol/triage_review_queue.csv"
|
|
HEADERS = ["id", "text", "category", "priority", "reason"]
|
|
|
|
|
|
def norm(row):
|
|
return (row[0], row[1], row[2], int(row[3]), row[4])
|
|
|
|
|
|
def main():
|
|
problems = []
|
|
try:
|
|
with open(PATH, newline="") as f:
|
|
rows = list(csv.reader(f))
|
|
except Exception as exc: # noqa: BLE001
|
|
print(f"FAIL: cannot read {PATH}: {exc}")
|
|
return 1
|
|
|
|
if not rows:
|
|
print(f"FAIL: {PATH} is empty")
|
|
return 1
|
|
|
|
if rows[0] != HEADERS:
|
|
problems.append(f"header mismatch: {rows[0]!r} != {HEADERS!r}")
|
|
|
|
body = rows[1:]
|
|
if len(body) != 16:
|
|
problems.append(f"row count {len(body)} != 16")
|
|
|
|
expected = []
|
|
for tid, text in triage_review.ITEMS:
|
|
category, priority, reason = triage_review.GOLDEN[tid]
|
|
expected.append((tid, text, category, priority, reason))
|
|
|
|
actual = []
|
|
for r in body:
|
|
if len(r) != 5:
|
|
problems.append(f"row field count {len(r)} != 5: {r!r}")
|
|
continue
|
|
if any(x == "" for x in r):
|
|
problems.append(f"blank field in row: {r!r}")
|
|
actual.append(norm(r))
|
|
|
|
if actual != expected:
|
|
problems.append("rows do not match GOLDEN")
|
|
for i, (a, e) in enumerate(zip(actual, expected)):
|
|
if a != e:
|
|
problems.append(f"row {i} ({e[0]}): {a!r} != {e!r}")
|
|
if len(actual) != len(expected):
|
|
problems.append(f"length {len(actual)} != {len(expected)}")
|
|
|
|
if problems:
|
|
print("FAIL:")
|
|
for p in problems:
|
|
print(" -", p)
|
|
return 1
|
|
|
|
print(f"CHECK PASS: {PATH} matches GOLDEN ({len(body)} rows)")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|