Files
troupe-standup/wizard-work/ledger/CHECK
T

59 lines
2.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# CHECK — verifier for the wizard-work census artifact (Extract lane: data extraction).
#
# Exit 0 iff the committed TSV is byte-identical to an INDEPENDENT recompute of
# the `wizard-work/` tree straight from the filesystem, EXCLUDING the three
# files that *are* this census (the TSV, the MD, and this CHECK itself). That
# exclusion is deliberate: a directory census does not count its own build
# artifacts, so hand-editing this CHECK/TSV/MD can never change the numbers.
# Recompute uses only find/awk (no Python, no shared extractor logic).
#
# Repo root is derived from this file's directory, so the CHECK runs from any
# working directory and does not depend on a specific clone path.
set -u
cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1
REPO_ROOT="$(cd ../.. && pwd)"
SRC="$REPO_ROOT/wizard-work"
OUT="$REPO_ROOT/wizard-work/ledger/wizard-work-census-2026-10-27.tsv"
test -s "$OUT" || { echo "FAIL: TSV missing or empty: $OUT" >&2; exit 1; }
tmp="$(mktemp)"
trap 'rm -f "$tmp"' EXIT
{
echo "dir,files,bytes"
for d in $(cd "$SRC" && find . -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | sort); do
[ -n "$d" ] || continue
n="$(find "$SRC/$d" -type f \
! -name wizard-work-census-2026-10-27.tsv \
! -name wizard-work-census-2026-10-27.md \
! -name CHECK | wc -l)"
b="$(find "$SRC/$d" -type f \
! -name wizard-work-census-2026-10-27.tsv \
! -name wizard-work-census-2026-10-27.md \
! -name CHECK -printf '%s\n' | awk '{s+=$1} END {print s}')"
echo "$d,$n,$b"
done
tn="$(find "$SRC" -type f \
! -name wizard-work-census-2026-10-27.tsv \
! -name wizard-work-census-2026-10-27.md \
! -name CHECK | wc -l)"
tb="$(find "$SRC" -type f \
! -name wizard-work-census-2026-10-27.tsv \
! -name wizard-work-census-2026-10-27.md \
! -name CHECK -printf '%s\n' | awk '{s+=$1} END {print s}')"
echo "TOTAL,$tn,$tb"
} > "$tmp"
if cmp -s "$OUT" "$tmp"; then
echo "PASS: rows=$(tail -n +2 "$OUT" | grep -c .) (10 wizard dirs + TOTAL) recomputed from $SRC (excluding self)"
exit 0
fi
echo "FAIL: census mismatch against independent recompute" >&2
diff -u "$OUT" "$tmp" >&2 || true
exit 1