fix(scripts): anchor the apm version check to its CLI banner

Match `CLI version X.Y.Z`, the banner apm prints, instead of any
`version X.Y.Z`, so other version-like text on stdout is not taken for
apm's version. Fail clearly when APM holds only whitespace, instead of
running an empty command.

The seam B test now pins both properties. The fake uv also writes a
banner-shaped `uv CLI version 0.0.1` to stderr, so a parser reading the
merged stream fails it (23 failures with the round-1 bug restored). A
stub that prints `version 0.40.0` before a 0.28.0 banner must still fail.
The git-env test's stub prints the real banner.

Refs: #271

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
This commit is contained in:
Defame1297andClaude Opus 5.5 committed 2026-12-02 10:11:28 +00:00
1 parent 0696ce31e7
commit 5089856c0d
3 files changed
+53 -11

No files matched your search

+38 -3
View File
@@ -48,9 +48,12 @@ if [[ "\${1:-}" != run || "\${2:-}" != --project || "\${4:-}" != --frozen || "\$
exit 97
fi
shift 5
# What a real \`uv run --frozen\` prints on stderr when it syncs first. The
# version check must parse apm's stdout, never this (review round 1 of #271).
# What a real \`uv run --frozen\` prints on stderr when it syncs first, plus a
# decoy shaped exactly like apm's banner. The version check must parse apm's
# stdout only: a parser reading the merged stream takes 0.0.1 from the decoy
# and fails a current apm (review rounds 1 and 2 of #271).
echo "Using CPython 3.14.6" >&2
echo "uv CLI version 0.0.1" >&2
exec "$BIN/apm" "\$@"
EOF
@@ -168,11 +171,37 @@ for pair in "apm-audit-ci:$AUDIT" "apm-pack-check-clean:$PACK"; do
done
reset_logs
run_gate "$FIXTURE" "$script" STUB_APM_OUTPUT="apm, version unknown"
[[ $RC -ne 0 ]] && grep -qF "printed no 'version X.Y.Z'" <<< "$OUT" \
[[ $RC -ne 0 ]] && grep -qF "printed no 'CLI version X.Y.Z' banner" <<< "$OUT" \
&& pass "$label: fails when the version cannot be read" \
|| fail "$label: an unreadable version must fail clearly (rc=$RC): $OUT"
done
echo ""
echo "--- the version is read from apm's stdout banner, nothing else ---"
# The fake uv writes a banner-shaped `uv CLI version 0.0.1` to stderr on every
# call, so these fail if stderr reaches the parser.
reset_logs
run_gate "$FIXTURE" "$PACK" STUB_APM_VERSION=0.39.3
[[ $RC -eq 0 ]] && pass "stdout only: apm 0.39.3 passes despite a 0.0.1 decoy on uv's stderr" \
|| fail "stdout only: 0.39.3 must pass, the stderr decoy was parsed: $OUT"
reset_logs
run_gate "$FIXTURE" "$PACK" STUB_APM_VERSION=0.28.0
[[ $RC -ne 0 ]] && grep -qF "apm 0.28.0 is below 0.39.2" <<< "$OUT" \
&& pass "stdout only: apm 0.28.0 still fails" || fail "stdout only: 0.28.0 must fail: $OUT"
# Other version-like text on stdout, before the banner, is not the version.
reset_logs
run_gate "$FIXTURE" "$PACK" \
STUB_APM_OUTPUT=$'reads lockfile version 0.40.0\nAgent Package Manager (APM) CLI version 0.28.0'
[[ $RC -ne 0 ]] && grep -qF "apm 0.28.0 is below 0.39.2" <<< "$OUT" \
&& pass "banner anchor: a 'version 0.40.0' line before the banner does not rescue 0.28.0" \
|| fail "banner anchor: the decoy line was taken for the version (rc=$RC): $OUT"
reset_logs
run_gate "$FIXTURE" "$PACK" \
STUB_APM_OUTPUT=$'reads lockfile version 0.40.0\nAgent Package Manager (APM) CLI version 0.39.3'
[[ $RC -eq 0 ]] && pass "banner anchor: the banner's 0.39.3 is the version read" \
|| fail "banner anchor: 0.39.3 behind a decoy line must pass (rc=$RC): $OUT"
echo ""
echo "--- no uv, and the APM override ---"
RC=0
@@ -187,6 +216,12 @@ OUT="$(cd "$FIXTURE" && env PATH="$NO_UV_PATH" APM="$BIN/apm" bash "$PACK" 2>&1)
&& pass "APM overrides the command and bypasses uv" \
|| fail "APM override not honoured (rc=$RC): $OUT"
RC=0
OUT="$(cd "$FIXTURE" && env PATH="$FAKE_PATH" APM=" " bash "$PACK" 2>&1)" || RC=$?
[[ $RC -ne 0 ]] && grep -qF "holds only whitespace" <<< "$OUT" \
&& pass "a whitespace-only APM fails clearly" \
|| fail "a whitespace-only APM must fail clearly (rc=$RC): $OUT"
reset_logs
RC=0
OUT="$(cd "$FIXTURE" && env PATH="$NO_UV_PATH" APM="$BIN/apm" STUB_APM_VERSION=0.28.0 bash "$PACK" 2>&1)" || RC=$?
+1 -1
View File
@@ -68,7 +68,7 @@ EOF
# --version answers above the gates' 0.39.2 floor and records nothing.
cat > "$dir/bin/apm" <<EOF
#!/usr/bin/env bash
if [[ "\${1:-}" == --version ]]; then echo "apm version 0.39.3"; exit 0; fi
if [[ "\${1:-}" == --version ]]; then echo "Agent Package Manager (APM) CLI version 0.39.3"; exit 0; fi
printf '%s\n' "\${GIT_DIR-<unset>}" >> "$dir/apm-saw-git-dir"
tmp="\$(mktemp -d)"
( cd "\$tmp" && git init -q . >/dev/null 2>&1; git checkout -q --detach $locked >/dev/null 2>&1 ) || true