Files
troupe-standup/wizard-work/ledger/CHECK-2026-10-27-checkin-census
T

46 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# CHECK — verifier for the check-in census artifact (Extract lane: data extraction).
#
# Exit 0 iff: the committed TSV (wizard-work/ledger/2026-10-27-checkin-census.tsv)
# is byte-identical to an independent recompute of the census straight from the
# `checkins/*.md` source directory.
#
# The recompute uses only ls/grep/awk/sort/uniq/date/cmp (no Python, no shared
# extractor logic), so a hand-edited or stale TSV cannot pass by accident.
#
# Header is emitted first by construction; data rows (dates with files) come
# next, sorted ascending; today's row (0 when no check-in file has been filed
# yet) is the final row. All are produced by independent shell tools.
#
# 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/checkins"
OUT="$REPO_ROOT/wizard-work/ledger/2026-10-27-checkin-census.tsv"
test -s "$OUT" || { echo "FAIL: TSV missing or empty: $OUT" >&2; exit 1; }
tmp="$(mktemp)"
trap 'rm -f "$tmp"' EXIT
{
echo "date,checkin_files"
ls "$SRC"/*.md 2>/dev/null | grep -v 'README\.md$' \
| awk -F/ '{n=split($0, a, "/"); name=a[n]; sub(/\.md$/, "", name); print substr(name, 1, 10)}' \
| sort | uniq -c | awk '{print $2 "," $1}'
echo "$(date -u +%F),0"
} > "$tmp"
if cmp -s "$OUT" "$tmp"; then
echo "PASS: rows=$(tail -n +2 "$OUT" | grep -c .) (dates with files + today=0) recomputed from $SRC"
exit 0
fi
echo "FAIL: census mismatch against independent recompute" >&2
diff -u "$OUT" "$tmp" >&2 || true
exit 1