#!/usr/bin/env bash
# CHECK -- ledger: Q-census 2026-10-31 extraction.
# Exit 0 iff the committed wizard-work/ledger/q-census.csv re-derives the
# per-sublane totals and file/byte counts from the raw wizard-work tree.
cd /root/troupe-standup || exit 1
python3 - <<'PY'
import csv, os, hashlib, sys
rows = list(csv.DictReader(open('wizard-work/ledger/q-census.csv')))
ok = len(rows) == 5061
tot = 0
seen = set()
for r in rows:
    p = os.path.join('wizard-work', r['relpath'])
    if not os.path.exists(p):
        ok = False
        continue
    tot += int(r['size_bytes'])
    if (r['sublane'], r['relpath']) in seen:
        ok = False
    seen.add((r['sublane'], r['relpath']))
    h = hashlib.sha256(open(p, 'rb').read()).hexdigest()
    if h != r['sha256']:
        ok = False
ok = ok and tot == 222214367
print('rows=%d bytes=%d ok=%s' % (len(rows), tot, ok))
sys.exit(0 if ok else 1)
PY
