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:
1 parent
0696ce31e7
commit
5089856c0d
3 files changed
+53
-11
No files matched your search
+14
-7
@@ -28,7 +28,8 @@
|
|||||||
#
|
#
|
||||||
# APM overrides the command, as a seam for tests (ADR-0034, "Invocation"). It is
|
# APM overrides the command, as a seam for tests (ADR-0034, "Invocation"). It is
|
||||||
# split on whitespace, so it can name a stub or a full command line. The
|
# split on whitespace, so it can name a stub or a full command line. The
|
||||||
# minimum-version check applies to it too.
|
# minimum-version check applies to it too, and an APM that holds only
|
||||||
|
# whitespace fails that check rather than silently running the default.
|
||||||
#
|
#
|
||||||
# Not meant to be executed directly.
|
# Not meant to be executed directly.
|
||||||
|
|
||||||
@@ -41,6 +42,7 @@ APM_REPO_ROOT="$(CDPATH='' cd -- "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
|||||||
# as disable-model-invocation (ADR-0034, "Minimum version").
|
# as disable-model-invocation (ADR-0034, "Minimum version").
|
||||||
APM_MIN_VERSION="0.39.2"
|
APM_MIN_VERSION="0.39.2"
|
||||||
|
|
||||||
|
APM_CMD=()
|
||||||
if [[ -n "${APM:-}" ]]; then
|
if [[ -n "${APM:-}" ]]; then
|
||||||
read -r -a APM_CMD <<<"$APM"
|
read -r -a APM_CMD <<<"$APM"
|
||||||
else
|
else
|
||||||
@@ -48,13 +50,18 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
run_apm() {
|
run_apm() {
|
||||||
"${APM_CMD[@]}" "$@"
|
${APM_CMD[@]+"${APM_CMD[@]}"} "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Fails, with a message naming the fix, when the apm this helper resolves is
|
# Fails, with a message naming the fix, when the apm this helper resolves is
|
||||||
# missing, unreadable, or below APM_MIN_VERSION. Returns 0 when it is new enough.
|
# missing, unreadable, or below APM_MIN_VERSION. Returns 0 when it is new enough.
|
||||||
require_apm_version() {
|
require_apm_version() {
|
||||||
local output version stderr_file
|
local output version stderr_file
|
||||||
|
if [[ ${#APM_CMD[@]} -eq 0 ]]; then
|
||||||
|
echo "FAIL: APM is set but holds only whitespace, so there is no apm command to run." >&2
|
||||||
|
echo " Fix: unset APM to run the repo-pinned apm, or set it to a command." >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
if [[ -z "${APM:-}" ]] && ! command -v uv >/dev/null 2>&1; then
|
if [[ -z "${APM:-}" ]] && ! command -v uv >/dev/null 2>&1; then
|
||||||
echo "FAIL: uv is not on PATH, and this repo runs apm as 'uv run --frozen apm' (ADR-0034)." >&2
|
echo "FAIL: uv is not on PATH, and this repo runs apm as 'uv run --frozen apm' (ADR-0034)." >&2
|
||||||
echo " Fix: install uv, then run 'uv sync --frozen' at the repo root." >&2
|
echo " Fix: install uv, then run 'uv sync --frozen' at the repo root." >&2
|
||||||
@@ -73,14 +80,14 @@ require_apm_version() {
|
|||||||
echo " Fix: run 'uv sync --frozen' at the repo root, then retry." >&2
|
echo " Fix: run 'uv sync --frozen' at the repo root, then retry." >&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
# Anchored to apm's banner, `... CLI version X.Y.Z`, so no other number on
|
# Anchored to apm's banner, `Agent Package Manager (APM) CLI version X.Y.Z`,
|
||||||
# the line can be taken for the version.
|
# so no other version-like text on stdout can be taken for apm's version.
|
||||||
version="$(grep -oE 'version [0-9]+\.[0-9]+\.[0-9]+' <<<"$output" | head -n 1 || true)"
|
version="$(grep -oE 'CLI version [0-9]+\.[0-9]+\.[0-9]+' <<<"$output" | head -n 1 || true)"
|
||||||
version="${version#version }"
|
version="${version#CLI version }"
|
||||||
if [[ ! "$version" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
|
if [[ ! "$version" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
|
||||||
cat "$stderr_file" >&2
|
cat "$stderr_file" >&2
|
||||||
rm -f "$stderr_file"
|
rm -f "$stderr_file"
|
||||||
echo "FAIL: '${APM_CMD[*]} --version' printed no 'version X.Y.Z', so the apm version is unknown." >&2
|
echo "FAIL: '${APM_CMD[*]} --version' printed no 'CLI version X.Y.Z' banner, so the apm version is unknown." >&2
|
||||||
echo " Fix: run 'uv sync --frozen' at the repo root, then retry." >&2
|
echo " Fix: run 'uv sync --frozen' at the repo root, then retry." >&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -48,9 +48,12 @@ if [[ "\${1:-}" != run || "\${2:-}" != --project || "\${4:-}" != --frozen || "\$
|
|||||||
exit 97
|
exit 97
|
||||||
fi
|
fi
|
||||||
shift 5
|
shift 5
|
||||||
# What a real \`uv run --frozen\` prints on stderr when it syncs first. The
|
# What a real \`uv run --frozen\` prints on stderr when it syncs first, plus a
|
||||||
# version check must parse apm's stdout, never this (review round 1 of #271).
|
# 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 "Using CPython 3.14.6" >&2
|
||||||
|
echo "uv CLI version 0.0.1" >&2
|
||||||
exec "$BIN/apm" "\$@"
|
exec "$BIN/apm" "\$@"
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
@@ -168,11 +171,37 @@ for pair in "apm-audit-ci:$AUDIT" "apm-pack-check-clean:$PACK"; do
|
|||||||
done
|
done
|
||||||
reset_logs
|
reset_logs
|
||||||
run_gate "$FIXTURE" "$script" STUB_APM_OUTPUT="apm, version unknown"
|
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" \
|
&& pass "$label: fails when the version cannot be read" \
|
||||||
|| fail "$label: an unreadable version must fail clearly (rc=$RC): $OUT"
|
|| fail "$label: an unreadable version must fail clearly (rc=$RC): $OUT"
|
||||||
done
|
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 ""
|
||||||
echo "--- no uv, and the APM override ---"
|
echo "--- no uv, and the APM override ---"
|
||||||
RC=0
|
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" \
|
&& pass "APM overrides the command and bypasses uv" \
|
||||||
|| fail "APM override not honoured (rc=$RC): $OUT"
|
|| 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
|
reset_logs
|
||||||
RC=0
|
RC=0
|
||||||
OUT="$(cd "$FIXTURE" && env PATH="$NO_UV_PATH" APM="$BIN/apm" STUB_APM_VERSION=0.28.0 bash "$PACK" 2>&1)" || RC=$?
|
OUT="$(cd "$FIXTURE" && env PATH="$NO_UV_PATH" APM="$BIN/apm" STUB_APM_VERSION=0.28.0 bash "$PACK" 2>&1)" || RC=$?
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ EOF
|
|||||||
# --version answers above the gates' 0.39.2 floor and records nothing.
|
# --version answers above the gates' 0.39.2 floor and records nothing.
|
||||||
cat > "$dir/bin/apm" <<EOF
|
cat > "$dir/bin/apm" <<EOF
|
||||||
#!/usr/bin/env bash
|
#!/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"
|
printf '%s\n' "\${GIT_DIR-<unset>}" >> "$dir/apm-saw-git-dir"
|
||||||
tmp="\$(mktemp -d)"
|
tmp="\$(mktemp -d)"
|
||||||
( cd "\$tmp" && git init -q . >/dev/null 2>&1; git checkout -q --detach $locked >/dev/null 2>&1 ) || true
|
( cd "\$tmp" && git init -q . >/dev/null 2>&1; git checkout -q --detach $locked >/dev/null 2>&1 ) || true
|
||||||
|
|||||||
Reference in new issue
Block a user