#!/bin/bash # N13 - re-run the (L1-modified) code/export_stats.py on the master node into a scratch directory, read-only, # and diff the 29 baseline CSV exports against the regenerated ones (byte identity gate), then the new files. # usage (on M3U96b): bash scripts/a13_export_stats_check.sh (expects scripts/export_stats.py = worktree code/export_stats.py, # and baseline/ = the 29 CSV + stats.json of commit 678d233) set -u cd "$HOME/firc0001_review" || exit 1 OUT="results/export_check"; mkdir -p "$OUT/data" logs PY="$HOME/UQO_RESEARCH_DB/.venv/bin/python" echo "START $(date -Iseconds)"; T0=$(date +%s) nice -n 10 env OMP_NUM_THREADS=4 "$PY" -I scripts/export_stats.py "$HOME/UQO_RESEARCH_DB" "$OUT/data" > logs/a13_export_stats.log 2>&1 RC=$? echo "export_stats.py rc=$RC in $(( $(date +%s) - T0 )) s" { echo "# N13 export reconciliation — $(date -Iseconds) on $(hostname), rc=$RC, $(( $(date +%s) - T0 )) s" echo echo "## Byte identity of the 29 baseline CSV (commit 678d233) vs the regenerated exports" echo '```' IDENT=0; DIFF=0; MISSING=0 for f in baseline/*.csv; do b=$(basename "$f") if [ ! -f "$OUT/data/$b" ]; then echo "MISSING $b"; MISSING=$((MISSING+1)); continue; fi if cmp -s "$f" "$OUT/data/$b"; then echo "identical $b"; IDENT=$((IDENT+1)); else echo "DIFFERS $b"; DIFF=$((DIFF+1)); fi done echo "identical=$IDENT differs=$DIFF missing=$MISSING" echo '```' if [ "$DIFF" -gt 0 ]; then echo; echo "## Differences"; echo '```' for f in baseline/*.csv; do b=$(basename "$f"); [ -f "$OUT/data/$b" ] && ! cmp -s "$f" "$OUT/data/$b" && { echo "--- $b"; diff "$f" "$OUT/data/$b" | head -20; }; done echo '```' fi echo; echo "## New files"; echo '```' for f in "$OUT"/data/*; do b=$(basename "$f"); [ -f "baseline/$b" ] || echo "new: $b ($(wc -c < "$f") bytes)"; done echo '```' echo; echo "## stats.json: baseline keys vs regenerated keys"; echo '```' "$PY" -I - "$OUT/data/stats.json" baseline/stats.json <<'PYEOF' import json, sys new = json.load(open(sys.argv[1])); old = json.load(open(sys.argv[2])) print("baseline keys:", len(old), "| regenerated keys:", len(new)) print("added keys:", sorted(set(new) - set(old))) print("removed keys:", sorted(set(old) - set(new))) for k in sorted(set(old) & set(new)): if old[k] != new[k]: print("CHANGED", k, ":", json.dumps(old[k], default=str)[:200], "->", json.dumps(new[k], default=str)[:200]) PYEOF echo '```' echo; echo "## Tail of the run log"; echo '```'; tail -15 logs/a13_export_stats.log; echo '```' } > "$OUT/export_reconciliation.md" cat "$OUT/export_reconciliation.md" echo "END $(date -Iseconds)"