Files
improvise/scripts/assemble-stamp-test.sh
T
Edward Langley 1d4d9107cf fix(tooling): three findings from reviewing this branch against itself
1. A self-test case that was a duplicate wearing different clothes. "a heading
cargo's listing does not carry is an orphan however the source reads" passed on
an empty listing -- which is the first case in the table, already. Once defined
comes from cargo, the Rust beside a fixture is not read at all, so four cases
for the four source shapes would be four copies of one assertion dressed as
coverage. Deleted; the evidence for those shapes is the real-tree injection, and
context/code/tooling.md now says which half a fixture can carry and which it
cannot. This is exactly the shape improvise-84wp's prose, applied two commits
ago, tells a reviewer to look for.

2. assemble-stamp.sh grepped its patterns as REGEXES, inherited from the inline
version it was extracted from. The `.` in improvise_wasm_client.js?v=abc matches
any character, so a stamp corrupted in that position read as present -- a pass in
the one direction a guard must not fail in. grep -F, plus a case proved by
injection: dropping the -F flips it.

3. A missing cargo raised a traceback out of --check-evidence. It now names the
flag that takes a saved listing instead.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FC2jVn8Au7E9JPkw6bwXXH
2026-09-20 21:17:41 -07:00

81 lines
3.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# check_the_checker for scripts/assemble-stamp.sh. The gate it holds was
# deleted on PR #69 by injection and the assembly still exited 0 with both
# failures printed -- a guard nobody had watched fail (improvise-w8ih).
set -uo pipefail
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
RUN="$here/assemble-stamp.sh"
work="$(mktemp -d)"
trap 'rm -rf "$work"' EXIT
pass=0; fail=0
ok() { printf ' ok %s\n' "$1"; pass=$((pass+1)); }
bad() { printf ' FAIL %s (exit %s, wanted %s)\n' "$1" "$2" "$3"; fail=$((fail+1)); }
# $1 name, $2 expected exit, $3 expected stderr substring ("" for none), rest: args
run_case() {
local name="$1" want="$2" says="$3"; shift 3
local err
err="$(sh "$RUN" "$@" 2>&1 >/dev/null)"
local got=$?
if [ "$got" != "$want" ]; then
bad "$name" "$got" "$want"
elif [ -n "$says" ] && [[ "$err" != *"$says"* ]]; then
bad "$name: stderr did not name it" "$err" "$says"
else
ok "$name"
fi
}
printf 'import "./pkg/improvise_wasm_client.js?v=abc";\n' > "$work/stamped.js"
printf 'import "./worker-pkg/improvise_worker_server.js?v=abc";\n' > "$work/stamped2.js"
printf 'import "./pkg/improvise_wasm_client.js";\n' > "$work/bare.js"
printf 'import "./worker-pkg/improvise_worker_server.js";\n' > "$work/bare2.js"
run_case "a stamped file passes" 0 "" \
"$work/stamped.js" "pkg/improvise_wasm_client.js?v=abc"
run_case "an unstamped file is refused and named" 1 "bare.js" \
"$work/bare.js" "pkg/improvise_wasm_client.js?v=abc"
# The bug the gate exists for: without the final `test -z`, the misses print
# and the script exits 0. Both must be NAMED, which is what exiting on the
# first one cost.
run_case "two misses are both named, not just the first" 1 "bare2.js" \
"$work/bare.js" "pkg/improvise_wasm_client.js?v=abc" \
"$work/bare2.js" "worker-pkg/improvise_worker_server.js?v=abc"
run_case "a miss among hits is still refused" 1 "bare2.js" \
"$work/stamped.js" "pkg/improvise_wasm_client.js?v=abc" \
"$work/bare2.js" "worker-pkg/improvise_worker_server.js?v=abc"
run_case "all four stamped is the shipping case" 0 "" \
"$work/stamped.js" "pkg/improvise_wasm_client.js?v=abc" \
"$work/stamped2.js" "worker-pkg/improvise_worker_server.js?v=abc"
# A file the assembly never copied is indistinguishable from an unstamped one
# to `grep`, which errors rather than failing quietly -- but only because the
# -f test runs first. Without it `set -e` would abort mid-list and the later
# files would go unreported, which is the failure this gate was built to end.
run_case "a file that does not exist is a miss, not an abort" 1 "vanished.js" \
"$work/vanished.js" "anything" \
"$work/bare2.js" "worker-pkg/improvise_worker_server.js?v=abc"
# A caller that drops one argument would otherwise have the last FILE read as
# a PATTERN over the file before it -- a check that passes by accident.
# The pattern is a literal. As a regex, `.` matches any character, so a stamp
# corrupted in exactly that position would read as present -- the one direction
# a guard must not fail in.
printf 'import "./pkg/improvise_wasm_clientXjs?v=abc";\n' > "$work/corrupt.js"
run_case "a pattern is matched literally, not as a regex" 1 "corrupt.js" \
"$work/corrupt.js" "pkg/improvise_wasm_client.js?v=abc"
run_case "an odd number of arguments is a usage error" 2 "pairs" \
"$work/stamped.js" "pkg/improvise_wasm_client.js?v=abc" "$work/bare.js"
run_case "no arguments at all is a usage error, not a pass" 2 "usage"
printf '\nassemble-stamp-test: %d passed, %d failed\n' "$pass" "$fail"
[ "$fail" -eq 0 ]