73 lines
2.3 KiB
Bash
Executable File
73 lines
2.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# CHECK -- ledger: queue-register extraction (ledger lane).
|
|
# Verdict: exit 0 iff the committed CSV/MD equal a fresh re-derivation of
|
|
# the work-queue Q-block register from WORK-QUEUE.md.
|
|
set -u
|
|
cd "$(dirname "$0")" || exit 2
|
|
ROOT="$(git -C "$(dirname "$0")" rev-parse --show-toplevel 2>/dev/null)"
|
|
SRC="$ROOT/WORK-QUEUE.md"
|
|
CSV="2026-11-01-queue-register.csv"
|
|
MD="2026-11-01-queue-register.md"
|
|
|
|
python3 - "$SRC" "$CSV" "$MD" <<'PY'
|
|
import csv, re, sys
|
|
|
|
src, csv_path, md_path = sys.argv[1:4]
|
|
|
|
HEAD = re.compile(r'^##\s+(Q\d+)\s+[-—–]?\s*(.+?)\s*\*\((.*)\)\*$')
|
|
HEAD_NO = re.compile(r'^##\s+(Q\d+)\s+(.+)$')
|
|
|
|
rows = []
|
|
seen = set()
|
|
with open(src, encoding='utf-8') as f:
|
|
for i, line in enumerate(f, 1):
|
|
line = line.rstrip('\n')
|
|
m = HEAD.match(line)
|
|
if m:
|
|
q, title, clause = m.group(1), m.group(2).strip(), m.group(3).strip()
|
|
if q in seen:
|
|
continue
|
|
seen.add(q)
|
|
rows.append([q, title, clause, i])
|
|
continue
|
|
m2 = HEAD_NO.match(line)
|
|
if m2 and m2.group(1) not in seen:
|
|
seen.add(m2.group(1))
|
|
rows.append([m2.group(1), m2.group(2).strip(), '— (no status clause)', i])
|
|
|
|
def load_csv():
|
|
with open(csv_path, encoding='utf-8', newline='') as f:
|
|
return [list(r.values()) for r in csv.DictReader(f)]
|
|
|
|
def load_md():
|
|
out = []
|
|
for line in open(md_path, encoding='utf-8'):
|
|
s = line.strip()
|
|
if not s.startswith('|'):
|
|
continue
|
|
if s.startswith('| Q |') or s.startswith('|---|---|---|---|'):
|
|
continue
|
|
out.append([c.strip() for c in s.strip('|').split('|')])
|
|
return out
|
|
|
|
fail = 0
|
|
def check(name, got, exp):
|
|
global fail
|
|
if got == exp:
|
|
print('PASS ' + name)
|
|
else:
|
|
fail = 1
|
|
print('FAIL ' + name + ': expected %r, got %r' % (exp, got))
|
|
|
|
check('csv row count', len(load_csv()), len(rows))
|
|
check('md row count', len(load_md()), len(rows))
|
|
source_str = [[r[0], r[1], r[2], str(r[3])] for r in rows]
|
|
check('csv == source register', load_csv(), source_str)
|
|
check('Q45 title', [r for r in load_csv() if r and r[0] == 'Q45'], [['Q45', '§9 follow-on — the home-directory channel', 'Helm lane; Merlin', '7594']])
|
|
|
|
sys.exit(fail)
|
|
PY
|
|
rc=$?
|
|
echo "CHECK: ledger queue-register rc=$rc"
|
|
exit $rc
|