165 lines
7.9 KiB
Bash
Executable File
165 lines
7.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# CHECK-q164 -- the beam coverage census grades the tree, not this host's
|
|
# directory, so a scratch file beside the lane cannot move its verdict.
|
|
#
|
|
# The defect (Q164, 2026-11-03): `check_coverage.py` listed the lane with
|
|
# `glob(lane/*.py)`. At `a96da08` the worktree read 125 module(s) / 3 fault(s)
|
|
# and a `git archive HEAD` export of the SAME COMMIT read 124 / 2 -- the
|
|
# difference was `_run_regex.py`, untracked, which no clone of that commit
|
|
# contains. Same class as Q140/Q141 (a census that describes its host).
|
|
#
|
|
# Why the legs below count nothing by hand (Q165, 2026-11-03). `2829ff0` added
|
|
# `binary_search_bounds.py` and committed `_run_regex.py`; this guard's literal
|
|
# `124 module(s)` and its "names _run_regex in a note" expectation then both
|
|
# went red on a census that was reading the tree correctly. The expected module
|
|
# set is now DERIVED (`git ls-files`) and compared row for row, so a lane module
|
|
# added or removed is graded by the comparison rather than by a number someone
|
|
# has to remember to edit into this file.
|
|
#
|
|
# Seven legs:
|
|
# tree the census reads rc 0 with 0 faults and its rows name EXACTLY the
|
|
# tracked lane modules: the set `git ls-files` reports, no more (it
|
|
# graded a host file) and no fewer (it dropped a tree module)
|
|
# scratch a new untracked *.py dropped into the lane does NOT move the
|
|
# verdict (rc 0), is named in a note, and is ABSENT from the rows
|
|
# dir --enumerate dir on the same directory DOES grade it (rc 1), so
|
|
# the green above is the source of the list, not a lost tooth
|
|
# export a `git archive HEAD` export of the same commit reads rc 0 with
|
|
# the same module count: no clone can disagree with this worktree
|
|
# runner the committed hand runner `_run_regex` reads as a stated waiver
|
|
# naming the collected test it duplicates, not as UNCOVERED
|
|
# smoke the lane gate executes Q163's smoke cells (grep the CHECK line,
|
|
# run it, and read its coverage row as covered-gate)
|
|
# selftest the census's own fixture corpus, 17 cells, 0 failed
|
|
#
|
|
# Exit codes: 0 all legs passed, 1 a fault, 2 could not grade.
|
|
set -u
|
|
set -o pipefail
|
|
|
|
cd "$(dirname "${BASH_SOURCE[0]}")" || exit 2
|
|
ROOT="$(pwd)"
|
|
REL="wizard-work/beam"
|
|
LANE="$ROOT/$REL"
|
|
CENSUS="$LANE/check_coverage.py"
|
|
GATE="$LANE/CHECK"
|
|
SMOKE="$LANE/_smoke_intervals.py"
|
|
PROBE="$LANE/zz_q164_scratch_probe.py"
|
|
PY="${PYTHON:-python3}"
|
|
|
|
for f in "$CENSUS" "$GATE" "$SMOKE"; do
|
|
if [ ! -f "$f" ]; then
|
|
printf 'CANNOT GRADE: missing %s\n' "$f"
|
|
exit 2
|
|
fi
|
|
done
|
|
|
|
# Two legs grade the tree and one grades a revision, so a .git-less export
|
|
# cannot answer them: rc 2 is "could not grade", not a fault.
|
|
if ! git -C "$ROOT" rev-parse --show-toplevel >/dev/null 2>&1; then
|
|
printf 'CANNOT GRADE: %s is not a git work tree\n' "$ROOT"
|
|
exit 2
|
|
fi
|
|
|
|
WORK="$(mktemp -d "${TMPDIR:-/tmp}/check-q164.XXXXXX")" || exit 2
|
|
trap 'rm -f "$PROBE"; rm -rf "$WORK"' EXIT
|
|
|
|
passed=0
|
|
failed=0
|
|
row() { printf ' %-10s %s\n' "$1" "$2"; }
|
|
verdict() { if [ "$2" -eq 0 ]; then passed=$((passed + 1)); else failed=$((failed + 1)); fi; row "$1" "$3"; }
|
|
|
|
# The expected set: the lane's tracked *.py minus the collected tests. Read
|
|
# from the tree, so neither leg below can rot on a literal count.
|
|
git -C "$ROOT" ls-files -z -- "$REL" \
|
|
| tr '\0' '\n' \
|
|
| grep "^$REL/[^/]*\.py\$" \
|
|
| sed 's#.*/##; s/\.py$//' \
|
|
| grep -v '^test_' \
|
|
| sort > "$WORK/want" || exit 2
|
|
want="$(grep -c . "$WORK/want")"
|
|
|
|
# One module per line: the census's own state rows only (notes and summary
|
|
# lines share the stream), first occurrence per module (--list repeats the
|
|
# non-covered rows when it prints the report), waiver-table rows dropped
|
|
# because they grade the table rather than the lane's module list.
|
|
"$PY" "$CENSUS" --list 2>/dev/null \
|
|
| awk '$1 ~ /^(covered-|exempt$|UNCOVERED$)/ && !seen[$2]++ {print $2}' \
|
|
| sort > "$WORK/got"
|
|
|
|
# --- leg 1: the census reads the tree, and the tree is the truth ------------
|
|
out="$("$PY" "$CENSUS" 2>&1)"; trc=$?
|
|
last="$(printf '%s' "$out" | grep '^coverage: [0-9]' | tail -1)"
|
|
n_last="$(printf '%s' "$last" | sed -n 's/^coverage: \([0-9][0-9]*\) module(s).*/\1/p')"
|
|
extra="$(comm -13 "$WORK/want" "$WORK/got" | tr '\n' ' ')"
|
|
gone="$(comm -23 "$WORK/want" "$WORK/got" | tr '\n' ' ')"
|
|
badrow="$("$PY" "$CENSUS" --list 2>/dev/null | awk '$1 ~ /^(UNCOVERED|WAIVER-)/ {c++} END {print c+0}')"
|
|
verdict tree \
|
|
"$([ "$trc" -eq 0 ] && printf '%s' "$last" | grep -q ' 0 fault(s)' \
|
|
&& [ "$n_last" = "$want" ] && [ -z "$extra" ] && [ -z "$gone" ] \
|
|
&& [ "$badrow" -eq 0 ] && echo 0 || echo 1)" \
|
|
"rc=$trc ${last:-<no summary>} rows=$want extra=${extra:-none} missing=${gone:-none} faultRows=$badrow"
|
|
|
|
# --- leg 2: a host artifact cannot move the verdict -------------------------
|
|
printf 'print("scratch probe, never committed")\n' > "$PROBE"
|
|
out="$("$PY" "$CENSUS" 2>&1)"; src=$?
|
|
last="$(printf '%s' "$out" | grep '^coverage: [0-9]' | tail -1)"
|
|
note="$(printf '%s' "$out" | grep 'untracked, not graded: zz_q164_scratch_probe' | head -1)"
|
|
inrows="$("$PY" "$CENSUS" --list 2>/dev/null | awk '$2 == "zz_q164_scratch_probe" {c++} END {print c+0}')"
|
|
verdict scratch \
|
|
"$([ "$src" -eq 0 ] && printf '%s' "$last" | grep -q ' 0 fault(s)' \
|
|
&& [ -n "$note" ] && [ "$inrows" -eq 0 ] && echo 0 || echo 1)" \
|
|
"rc=$src ${last:-<no summary>} ${note:-<probe not named>} probeRows=$inrows"
|
|
|
|
# --- leg 3: the directory reading still has teeth ---------------------------
|
|
out="$("$PY" "$CENSUS" --enumerate dir 2>&1)"; drc=$?
|
|
faultline="$(printf '%s' "$out" | awk '$1 ~ /^(UNCOVERED|WAIVER-)/' | tr '\n' ';')"
|
|
verdict dir \
|
|
"$([ "$drc" -eq 1 ] && printf '%s' "$faultline" | grep -q 'zz_q164_scratch_probe' && echo 0 || echo 1)" \
|
|
"rc=$drc (want 1) ${faultline:-<no fault row>}"
|
|
rm -f "$PROBE"
|
|
|
|
# --- leg 4: the same commit, read from a clean export -----------------------
|
|
if git -C "$ROOT" archive HEAD 2>/dev/null | tar -x -C "$WORK" 2>/dev/null; then
|
|
out="$("$PY" "$WORK/$REL/check_coverage.py" 2>&1)"; erc=$?
|
|
last="$(printf '%s' "$out" | grep '^coverage: [0-9]' | tail -1)"
|
|
verdict export \
|
|
"$([ "$erc" -eq 0 ] && printf '%s' "$last" | grep -q ' 0 fault(s)' \
|
|
&& printf '%s' "$last" | grep -q " $want module(s)" && echo 0 || echo 1)" \
|
|
"rc=$erc ${last:-<no summary>} want=$want module(s)"
|
|
else
|
|
verdict export 1 "git archive HEAD would not export -- cannot read the commit"
|
|
fi
|
|
|
|
# --- leg 5: the committed hand runner is a waiver, not a fault --------------
|
|
tracked_regex="$(git -C "$ROOT" ls-files -- "$REL/_run_regex.py")"
|
|
rrow="$("$PY" "$CENSUS" --list 2>/dev/null | awk '$2 == "_run_regex" {print; exit}')"
|
|
rstate="$(printf '%s' "$rrow" | awk '{print $1}')"
|
|
verdict runner \
|
|
"$([ -n "$tracked_regex" ] && [ "$rstate" = "exempt" ] \
|
|
&& printf '%s' "$rrow" | grep -q 'test_regex_match' && echo 0 || echo 1)" \
|
|
"tracked=${tracked_regex:-no} state=${rstate:-<no row>}"
|
|
|
|
# --- leg 6: the lane gate runs the smoke ------------------------------------
|
|
line="$(grep -c '^python3 _smoke_intervals\.py$' "$GATE")"
|
|
out="$(cd "$LANE" && "$PY" _smoke_intervals.py 2>&1)"; mrc=$?
|
|
last="$(printf '%s' "$out" | tail -1)"
|
|
rowline="$("$PY" "$CENSUS" --list 2>&1 | grep 'covered-gate * _smoke_intervals' | head -1)"
|
|
verdict smoke \
|
|
"$([ "$line" -eq 1 ] && [ "$mrc" -eq 0 ] && printf '%s' "$last" | grep -q 'intervals smoke OK' \
|
|
&& [ -n "$rowline" ] && echo 0 || echo 1)" \
|
|
"check-line=$line rc=$mrc ${last:-<no output>} ${rowline:-<not covered-gate>}"
|
|
|
|
# --- leg 7: the census's fixture corpus -------------------------------------
|
|
out="$("$PY" "$CENSUS" --selftest 2>&1)"; crc=$?
|
|
last="$(printf '%s' "$out" | tail -1)"
|
|
verdict selftest \
|
|
"$([ "$crc" -eq 0 ] && printf '%s' "$last" | grep -q '17 cell(s), 0 failed' && echo 0 || echo 1)" \
|
|
"rc=$crc ${last:-<no output>}"
|
|
|
|
if [ "$failed" -eq 0 ]; then
|
|
echo "q164: $passed leg(s), 0 fault(s), rc 0"
|
|
exit 0
|
|
fi
|
|
echo "q164: $passed passed, $failed fault(s), rc 1"
|
|
exit 1
|