Files
troupe-standup/wizard-work/ledger/verify_workflow.py
T

58 lines
1.8 KiB
Python

#!/usr/bin/env python3
"""Verify the work-queue extraction (the CHECK for the ledger artifact).
Re-parses /root/troupe-standup/WORK-QUEUE.md and /root/.hermes/wizard-outputs/
ledger/workflow.tsv and asserts they agree. Exit code 0 = correct, nonzero = wrong.
"""
import hashlib
import re
import sys
SRC = "/root/troupe-standup/WORK-QUEUE.md"
TSV = "/root/.hermes/wizard-outputs/ledger/workflow.tsv"
with open(SRC, encoding="utf-8") as fh:
src = fh.read()
with open(TSV, encoding="utf-8") as fh:
tsv = fh.read()
q_re = re.compile(r"^## (Q\d+)")
expected_ids = []
for line in src.split("\n"):
m = q_re.match(line.strip())
if m:
expected_ids.append(m.group(1))
expected_unique = []
seen = set()
for qid in expected_ids:
if qid not in seen:
seen.add(qid)
expected_unique.append(qid)
rows = [l for l in tsv.split("\n") if l.strip()]
header, data = rows[0], rows[1:]
EXPECTED_HEADER = ["q_id", "heading_line", "title", "meta", "dup_count",
"has_done", "has_closure", "pipe_runs", "closure_sha", "sha_refs"]
EXPECTED_ROWS = len(expected_unique) # 45
errors = []
if header != "\t".join(EXPECTED_HEADER):
errors.append("header mismatch: got %r want %r" % (header.split("\t"), EXPECTED_HEADER))
if len(data) != EXPECTED_ROWS:
errors.append("row count mismatch: tsv=%d expected=%d" % (len(data), EXPECTED_ROWS))
actual_ids = [r.split("\t")[0] for r in data]
if actual_ids != expected_unique:
errors.append("q_id order mismatch:\ntsv=%r\nexpected=%r" % (actual_ids, expected_unique))
digest = hashlib.sha256(tsv.encode("utf-8")).hexdigest()
if errors:
print("FAIL")
for e in errors:
print(" -", e)
sys.exit(1)
print("OK rows=%d headings=%d unique=%d sha256=%s" % (
len(data), len(expected_ids), len(expected_unique), digest))