test(wake): pin the BASH_LINENO continuation convention at runtime (#973)

The denominator artifact's site coordinates assume a backslash-continuation
helper call reports at its FIRST physical line. That convention was measured
on a developer bash (5.3.x, Fedora); CI runs the bash baked into ci-base
(node:24-alpine), which rebuilds only on push-to-main or tag — so the CI bash
version floats silently between rebuilds, and an artifact validated only
against a developer bash is unverified in the place the gate actually runs.

wake_assert_init now runs a probe under the SAME bash binary executing the
suite (subshell + continuation, the real call shape) and aborts loudly if the
convention does not hold, instead of letting coordinates skew by one line
under everyone. Microtest C10 proves the pin's abort arm fires, via a
test-only WAKE_ASSERT_PIN_BASH interpreter override ($BASH itself cannot be
spoofed — bash resets it at startup): a pin whose failure arm was never seen
firing is an undertaking, not a control.

Prompted by mos-dt's CI-bash-float finding (prereg addendum 4, ddea1bc7b).

Written-by: pepper (sb-it-1-dt)
Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NsKce8iZuSuRnu3gVMCBKB
This commit is contained in:
Jason Woltje
2026-07-31 02:04:56 -05:00
co-authored by Claude Fable 5
parent 10a7fe43c5
commit 8cb5866a3d
2 changed files with 58 additions and 0 deletions
@@ -239,9 +239,45 @@ _wake_init_dir() {
# silencing every abort thereafter. The fd is allocated dynamically (>= 10),
# so it cannot collide with the wake lock fds (8) or the detector run-loop
# lock (9).
#
# Init also PINS the BASH_LINENO convention the site coordinates depend on:
# a helper call written across a backslash continuation must report at its
# FIRST physical line (the denominator artifact's convention). That was
# measured on a developer bash (5.3.x); CI runs whatever bash its base image
# baked in, and that version floats silently between image rebuilds. A bash
# that disagrees would shift every continuation-site coordinate by one line
# UNDER the validation instead of in front of it — so the convention is
# asserted at runtime, in the same bash binary that runs the suite, and a
# disagreeing bash aborts the suite loudly instead of skewing coordinates.
_wake_assert_lineno_pin() {
local _wa_pin_tmp _wa_pin_got
_wa_pin_tmp="$(mktemp)" || {
_wake_assert_err_note "WAKE-ASSERT INIT ABORT: mktemp failed; cannot pin the BASH_LINENO convention — a pin that silently does not run is not a pin (#973)"
exit 97
}
cat >"$_wa_pin_tmp" <<'WAKE_ASSERT_PIN'
_wap() { printf '%s\n' "${BASH_LINENO[0]}"; }
(
_wap simple
_wap \
continuation
)
WAKE_ASSERT_PIN
# WAKE_ASSERT_PIN_BASH: test-only interpreter override so the pin's abort
# arm can be PROVEN to fire (microtest C10) — bash resets $BASH at startup,
# so the real probe interpreter cannot be spoofed from the environment.
_wa_pin_got="$("${WAKE_ASSERT_PIN_BASH:-${BASH:-bash}}" "$_wa_pin_tmp" 2>/dev/null)"
rm -f "$_wa_pin_tmp"
if [ "$_wa_pin_got" != "$(printf '3\n4')" ]; then
_wake_assert_err_note "WAKE-ASSERT INIT ABORT: BASH_LINENO convention violated on bash ${BASH_VERSION}: probe reported [${_wa_pin_got:-<no output>}], expected [3 4] (simple call at own line, continuation call at FIRST physical line) — site coordinates are untrustworthy on this bash (#973)"
exit 97
fi
}
wake_assert_init() {
if [ -z "${_wake_assert_err_fd:-}" ]; then
exec {_wake_assert_err_fd}>&2
_wake_assert_lineno_pin
fi
}
@@ -30,6 +30,10 @@
# broken (ARMED line, no abort). C3..C6 require the ARMED line AND the
# aborting site's ledger row (append lands BEFORE the grep runs, so an
# abort can never shorten the count it is part of).
# C10 the BASH_LINENO pin's abort arm fires: under a probe interpreter that
# misreports the continuation line, wake_assert_init aborts loudly and
# nothing past init executes — a pin whose failure arm was never seen
# firing is an undertaking, not a control.
set -uo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -225,6 +229,24 @@ else
check C9 1 "rc=$rc out=$(printf '%s' "$out" | tail -n 3 | tr '\n' ' ')"
fi
# --- C10: lineno pin aborts under an interpreter that breaks the convention -
cat >"$TMP/fake-bash" <<'FAKE'
#!/usr/bin/env bash
# stand-in for a bash whose BASH_LINENO convention differs: misreports the
# continuation call one line low (the exact skew the pin exists to catch)
printf '3\n5\n'
FAKE
chmod +x "$TMP/fake-bash"
out="$(WAKE_ASSERT_PIN_BASH="$TMP/fake-bash" bash -c '. "$WAKE_COMMON" && wake_assert_init && echo REACHED-PAST-INIT' 2>&1)"
rc=$?
if [ "$rc" -ne 0 ] &&
! printf '%s' "$out" | grep -q 'REACHED-PAST-INIT' &&
printf '%s' "$out" | grep -q 'WAKE-ASSERT INIT ABORT: BASH_LINENO convention violated'; then
check C10 0 ""
else
check C10 1 "rc=$rc out=$(printf '%s' "$out" | tail -n 2 | tr '\n' ' ')"
fi
echo
if [ "$fails" -gt 0 ]; then
echo "microtest-wake-assert: FAILED ($fails check(s))" >&2