Derive the lib prefix in the music_parallelism drift guard

The pre-push gate was failing on a layout that is actually correct. The
script sources ../../lib/common.sh, which is right for where it sits after
the flattening; the test's guard still hardcoded ../lib/common.sh from
before the move, so it reported drift against itself.

The prefix is now read out of the script under test, so the two cannot
desynchronise the next time the tree moves. Verified non-vacuous: rewriting
the script to ../../../lib/common.sh in a throwaway worktree still fails
the guard, and it now names the real prefix.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
This commit is contained in:
Krzysztof Rudnicki 2026-08-23 19:53:17 +02:00
parent 7cb23e8a81
commit 9aeeb005dd
2 changed files with 56 additions and 2 deletions

View File

@ -0,0 +1,41 @@
{
"intent": "Unblock every push: the pre-push ci-mirror was failing on test_music_parallelism.sh, whose worktree drift guard still assumed the pre-flattening layout.",
"scope": [
"linux_configuration/tests/test_music_parallelism.sh - derive the lib prefix instead of hardcoding it",
"Non-goal: music_parallelism.sh itself, which is correct - it sources ../../lib/common.sh, matching where lib/ actually sits after the flattening."
],
"changes": [
"The guard hardcoded ../lib/common.sh while the script sources ../../lib/common.sh. The flattening that moved the script from scripts/periodic_background/... up to periodic_background/... changed its depth, so the test failed on a layout that is in fact correct.",
"The prefix is now read out of the script under test with sed, so a future reorganisation cannot desynchronise the two again. The failure message reports the real prefix rather than a fixed string.",
"Matching the literal text $SCRIPT_DIR meant matching a dollar sign as data, which shellcheck flags as SC2016. Spelled the byte via printf '\\\\x24' rather than adding a suppression."
],
"verification": [
{
"command": "bash linux_configuration/tests/test_music_parallelism.sh",
"result": "pass",
"evidence": "'music_parallelism.sh regression checks passed.' Previously failed with 'worktree layout drift: ... resolves ../lib/common.sh ...'."
},
{
"command": "Mutation check in a detached worktree: rewrote the script to source ../../../lib/common.sh",
"result": "pass",
"evidence": "The guard failed as intended and named the real prefix (../../../). Confirms the guard is non-vacuous rather than merely passing."
},
{
"command": "pre-commit run --files linux_configuration/tests/test_music_parallelism.sh",
"result": "pass",
"evidence": "shellcheck and shfmt clean; SC2016 resolved without a suppression."
},
{
"command": "systemd-run --scope -p MemoryMax=2G -p MemorySwapMax=0 /usr/bin/time -v python -m pytest ...",
"result": "pass",
"evidence": "1798 passed in 20.88s, Maximum RSS 293872 KB (~0.29 GB) under the existing 2G cap. The earlier 'Killed' was transient host pressure, not an inadequate ceiling; no cap change needed."
}
],
"risks": [
"The sed pattern matches the specific shape of the source line. If that line is rewritten to a different form the test fails loudly with 'cannot determine how ... sources lib/common.sh' rather than silently passing, which is the intended direction."
],
"rollback": [
"git revert the commit; the test returns to its hardcoded prefix and the pre-push gate fails again until the layout matches.",
"After rollback, run bash linux_configuration/tests/test_music_parallelism.sh to confirm the expected failure."
]
}

View File

@ -56,9 +56,22 @@ cp -r "$(dirname "$TARGET_SCRIPT")/lib" "$(dirname "$WORKTREE_SCRIPT")/lib"
# Fail loudly if the copy cannot reach the stub, rather than letting the script
# fall through to the real library and produce a misleading behavioural failure.
STUB_FROM_SCRIPT="$(dirname "$WORKTREE_SCRIPT")/../lib/common.sh"
#
# The relative prefix is read out of the script rather than written here. It is
# a function of how deep the script sits below the repo root, so the flattening
# that moved it from scripts/periodic_background/... up to
# periodic_background/... changed it from ../lib to ../../lib, and a hardcoded
# copy of it fails the moment the tree is reorganised again.
# The source line names SCRIPT_DIR literally; matching it means matching a
# dollar sign as data. Spelling that byte as \x24 keeps the pattern free of a
# literal $ so it reads unambiguously as text rather than an expansion.
SOURCE_REL="$(sed -n "s|.*source \"$(printf '\\x24')SCRIPT_DIR/\(\.\./[^\"]*lib/common\.sh\)\".*|\1|p" "$TARGET_SCRIPT" | head -1)"
if [[ -z "$SOURCE_REL" ]]; then
fail "cannot determine how $TARGET_SCRIPT sources lib/common.sh"
fi
STUB_FROM_SCRIPT="$(dirname "$WORKTREE_SCRIPT")/$SOURCE_REL"
if [[ "$(realpath -m "$STUB_FROM_SCRIPT")" != "$(realpath -m "$WORKTREE_LIB")" ]]; then
fail "worktree layout drift: script at $WORKTREE_SCRIPT resolves ../lib/common.sh to $(realpath -m "$STUB_FROM_SCRIPT"), not the stub at $WORKTREE_LIB"
fail "worktree layout drift: script at $WORKTREE_SCRIPT resolves $SOURCE_REL to $(realpath -m "$STUB_FROM_SCRIPT"), not the stub at $WORKTREE_LIB"
fi
cat >"$WORKTREE_LIB" <<'EOF'