131 lines
4.4 KiB
Bash
Executable File
131 lines
4.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# check-triage.sh — verifies the work-queue triage classification artifact
|
|
# against a fresh parse of WORK-QUEUE.md.
|
|
#
|
|
# Verdict: exit 0 iff the triage report matches a re-derivation of the
|
|
# documented rules; nonzero otherwise.
|
|
set -u
|
|
|
|
python3 - "$@" <<'PY'
|
|
import re
|
|
import sys
|
|
|
|
SRC = "/root/troupe-standup/WORK-QUEUE.md"
|
|
REPORT = sys.argv[1] if len(sys.argv) > 1 else "/root/troupe-standup/wizard-work/sol/triage-queue.md"
|
|
|
|
def parse_items(path):
|
|
text = open(path, encoding="utf-8").read()
|
|
lines = text.split("\n")
|
|
items = []
|
|
cur = None
|
|
for ln in lines:
|
|
if re.match(r"^##\s+Q\d", ln):
|
|
if cur:
|
|
items.append(cur)
|
|
cur = {"header": ln.strip(), "body": [], "status": ""}
|
|
elif cur is not None:
|
|
cur["body"].append(ln)
|
|
if cur:
|
|
items.append(cur)
|
|
for it in items:
|
|
for bl in it["body"]:
|
|
s = bl.strip()
|
|
if s.startswith("**Status") or s.startswith("- **Status") or s.startswith("+ **Status"):
|
|
it["status"] = s
|
|
break
|
|
return items
|
|
|
|
def is_done(s):
|
|
return s[:20].lower() and any(w in s[:20].lower() for w in
|
|
("closed", "done", "complete", "resolved", "finished", "verified"))
|
|
|
|
def is_open(s):
|
|
return s[:20].lower().startswith("open")
|
|
|
|
def label_for(it):
|
|
header = it["header"]
|
|
if len(set(re.findall(r"^##\s+Q(\d+)", header))) != 1:
|
|
return "Duplicate"
|
|
st = it["status"]
|
|
if st:
|
|
s = st.replace("**", "").replace("Status:", "").strip()
|
|
if is_done(s):
|
|
return "Closed"
|
|
if is_open(s):
|
|
return "Open"
|
|
if s.startswith(("WAITING", "BLOCKED")) or "adoption is blocked" in s:
|
|
return "Blocked"
|
|
return "Pending"
|
|
if "not yet opened" in header:
|
|
return "Unopened"
|
|
if "opened by the pipe" in header or "claimed by this pipe" in header:
|
|
return "In-flight"
|
|
if "blocked" in header or "adoption is blocked" in header:
|
|
return "Blocked"
|
|
return "Open"
|
|
|
|
def rule_set(items):
|
|
labels = []
|
|
for it in items:
|
|
labels.append(label_for(it))
|
|
hdr_ids = []
|
|
for it in items:
|
|
m = re.match(r"^##\s+Q(\d+)", it["header"])
|
|
if m:
|
|
hdr_ids.append(m.group(1))
|
|
dup = sorted({int(n) for n in set(hdr_ids) if hdr_ids.count(n) > 1})
|
|
return labels, dup
|
|
|
|
def main():
|
|
items = parse_items(SRC)
|
|
expected_labels, expected_dup = rule_set(items)
|
|
|
|
rep = open(REPORT, encoding="utf-8").read()
|
|
|
|
# count labels in the report
|
|
rep_counts = {}
|
|
for lab in ["Closed", "Pending", "Open", "Blocked", "Duplicate", "Unopened", "In-flight"]:
|
|
rep_counts[lab] = len(re.findall(rf"\|\s*Q\d+\s*\|\s*.*\s*\|\s*{lab}\s*\|", rep))
|
|
|
|
# duplicate line in report
|
|
m_dup = re.search(r"Duplicates \(numeric id in 2\+\s*item headers\):\s*(.+)", rep)
|
|
rep_dup = [int(x.replace("Q", "")) for x in m_dup.group(1).split(", ") if x.strip()] if m_dup else []
|
|
|
|
problems = []
|
|
if rep_counts != {k: expected_labels.count(k) for k in set(expected_labels) | set(rep_counts)}:
|
|
problems.append("label counts differ: report=%s expected=%s" % (rep_counts, {k: expected_labels.count(k) for k in set(expected_labels)}))
|
|
if rep_dup != expected_dup:
|
|
problems.append("duplicate ids differ: report=%s expected=%s" % (rep_dup, expected_dup))
|
|
|
|
# per-item label comparison
|
|
rows = re.findall(r"\|\s*Q(\d+)\s*\|\s*(.*?)\s*\|\s*`?(.*?)`?\s*\|\s*([A-Za-z-]+)\s*\|", rep)
|
|
rep_label = {}
|
|
for q, title, status, lab in rows:
|
|
rep_label[int(q)] = lab
|
|
if len(rows) != len(items):
|
|
problems.append("report has %d item rows, source has %d" % (len(rows), len(items)))
|
|
|
|
for i, it in enumerate(items, 1):
|
|
exp = expected_labels[i-1]
|
|
got = rep_label.get(i)
|
|
if got != exp:
|
|
problems.append("item Q%d: report=%s expected=%s" % (i, got, exp))
|
|
|
|
# print verdict
|
|
print("triage check")
|
|
print(" items=%d closed=%d pending=%d open=%d dup=%s" %
|
|
(len(items), expected_labels.count("Closed"), expected_labels.count("Pending"),
|
|
expected_labels.count("Open"), expected_dup))
|
|
print(" report rows=%d" % len(rows))
|
|
if problems:
|
|
print("FAIL")
|
|
for p in problems:
|
|
print(" -", p)
|
|
sys.exit(1)
|
|
print("PASS — report matches a fresh re-derivation of the documented rules.")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
PY
|
|
exit $?
|