Files
troupe-standup/wizard-work/sol/_jobboard_triage_verify.py
T

101 lines
3.6 KiB
Python

#!/usr/bin/env python3
"""Independent re-derivation of the jobboard triage registry.
Recomputes the triage_status and source counts straight from the raw records in
jobboard_triage.json (the board-source roles). Two evidence traces. Diffs both
against the values stated in INDEX.md. Classification + evidence pass for the
Sol lane. Exits 0 only when every count reproduces.
"""
import json
import re
import sys
from collections import Counter
RAW = "/root/.hermes/wizard-outputs/sol/jobboard_triage.json"
INDEX = "/root/.hermes/wizard-outputs/sol/INDEX.md"
OUT = "/root/.hermes/wizard-outputs/sol/_jobboard_triage_registry.json"
def main():
records = json.load(open(RAW, "rb"))["records"]
total = len(records)
# Trace 1: count the triage_status field exactly as the record declares it.
field_status = Counter(r["triage_status"] for r in records)
# Trace 2: re-derive by the stated rule (isListed).
derived = {"ACTIVE": 0, "OPEN": 0, "REMOVED": 0, "NEEDS_REVIEW": 0}
for r in records:
il = r.get("isListed")
if il is True:
derived["ACTIVE"] += 1
elif il is False:
derived["REMOVED"] += 1
elif il in (None, ""):
derived["OPEN"] += 1
else:
derived["NEEDS_REVIEW"] += 1
sources = Counter(r["source"] for r in records)
expected = {
"generated_by": "sol",
"total_records": total,
"counts": {
"triage_status": dict(field_status),
"source": dict(sorted(sources.items())),
},
"note": "trace1 = on-record triage_status field; trace2 = isListed rule",
}
json.dump(expected, open(OUT, "w"), indent=2)
index_txt = open(INDEX).read()
problems = []
ts = re.search(r"## Triage status counts\n\n\|\s*triage_status\s*\|\s*count\s*\|\s*\|.*?\n((?:\|\s*[^\n]+\|\n?)+)", index_txt, re.S)
if ts:
for line in ts.group(1).splitlines():
mm = re.match(r"\|\s*(ACTIVE|OPEN|REMOVED|NEEDS_REVIEW)\s*\|\s*(\d+)\s*\|", line)
if mm:
key, val = mm.group(1), int(mm.group(2))
expect = field_status.get(key, 0)
if expect != val:
problems.append("triage_status %s: INDEX.md=%d, records=%d"
% (key, val, expect))
else:
problems.append("triage status table not found in INDEX.md")
sb = re.search(r"## By source\n\n\|\s*source\s*\|\s*count\s*\|\s*\|.*?\n((?:\|\s*[^\n]+\|\n?)+)", index_txt, re.S)
if sb:
for line in sb.group(1).splitlines():
mm = re.match(r"\|\s*(ashby|greenhouse|more)\s*\|\s*(\d+)\s*\|", line)
if mm:
key, val = mm.group(1), int(mm.group(2))
if sources.get(key, 0) != val:
problems.append("source %s: INDEX.md=%d, records=%d"
% (key, val, sources.get(key, 0)))
else:
problems.append("source table not found in INDEX.md")
tm = re.search(r"\*\*(\d+)\*\*", index_txt)
if tm and int(tm.group(1)) != total:
problems.append("total: INDEX.md=%d, records=%d" % (int(tm.group(1)), total))
ok = not problems
print("records", total)
print("field_status", json.dumps(dict(field_status), sort_keys=True))
print("derived", json.dumps(derived, sort_keys=True))
print("source", json.dumps(dict(sources), sort_keys=True))
print("registry_json", OUT)
if ok:
print("VERIFY OK: triage_status + source counts reproduce from raw records; INDEX.md matches")
sys.exit(0)
print("VERIFY FAIL:")
for p in problems:
print(" -", p)
sys.exit(1)
if __name__ == "__main__":
main()