fix(scripts): parse the apm version from stdout and its banner only
require_apm_version merged stderr into the --version output and took the first X.Y.Z. When `uv run --frozen` syncs first, uv prints `Using CPython 3.14.6` on stderr, so the check parsed 3.14.6 and passed whatever apm reported. It now reads stdout only, matches apm's `version X.Y.Z` banner, and shows the captured stderr only on failure. The fake uv in the seam B test now writes that line to stderr, so the regression stays pinned. Resolve the repo root with CDPATH cleared. 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
a48f0fdf5b
commit
615d3dd881
2 files changed
+22
-6
No files matched your search
+18
-5
@@ -35,7 +35,7 @@
|
|||||||
# shellcheck source=scripts/lib/clean-git-env.sh
|
# shellcheck source=scripts/lib/clean-git-env.sh
|
||||||
source "$(dirname "${BASH_SOURCE[0]}")/clean-git-env.sh"
|
source "$(dirname "${BASH_SOURCE[0]}")/clean-git-env.sh"
|
||||||
|
|
||||||
APM_REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
APM_REPO_ROOT="$(CDPATH='' cd -- "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||||
# 0.39.2 is the lowest apm that reads and writes lockfile v4 in a form later
|
# 0.39.2 is the lowest apm that reads and writes lockfile v4 in a form later
|
||||||
# versions accept, and it is above 0.39.0, which keeps Claude command keys such
|
# versions accept, and it is above 0.39.0, which keeps Claude command keys such
|
||||||
# as disable-model-invocation (ADR-0034, "Minimum version").
|
# as disable-model-invocation (ADR-0034, "Minimum version").
|
||||||
@@ -54,24 +54,37 @@ run_apm() {
|
|||||||
# 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
|
local output version stderr_file
|
||||||
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
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
if ! output="$(run_apm --version 2>&1)"; then
|
# stdout only. uv writes its own lines to stderr when `uv run` syncs first
|
||||||
|
# (`Using CPython 3.14.6`, `Installed 62 packages`), and a merged stream
|
||||||
|
# would hand the parser uv's numbers instead of apm's. stderr is kept aside
|
||||||
|
# and shown only when the check fails.
|
||||||
|
stderr_file="$(mktemp)"
|
||||||
|
if ! output="$(run_apm --version 2>"$stderr_file")"; then
|
||||||
|
cat "$stderr_file" >&2
|
||||||
printf '%s\n' "$output" >&2
|
printf '%s\n' "$output" >&2
|
||||||
|
rm -f "$stderr_file"
|
||||||
echo "FAIL: could not run '${APM_CMD[*]} --version', so the apm version is unknown." >&2
|
echo "FAIL: could not run '${APM_CMD[*]} --version', 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
|
||||||
version="$(grep -oE '[0-9]+\.[0-9]+\.[0-9]+' <<<"$output" | head -n 1 || true)"
|
# Anchored to apm's banner, `... CLI version X.Y.Z`, so no other number on
|
||||||
|
# the line can be taken for the version.
|
||||||
|
version="$(grep -oE 'version [0-9]+\.[0-9]+\.[0-9]+' <<<"$output" | head -n 1 || true)"
|
||||||
|
version="${version#version }"
|
||||||
if [[ ! "$version" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
|
if [[ ! "$version" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
|
||||||
echo "FAIL: '${APM_CMD[*]} --version' printed no version, so the apm version is unknown." >&2
|
cat "$stderr_file" >&2
|
||||||
|
rm -f "$stderr_file"
|
||||||
|
echo "FAIL: '${APM_CMD[*]} --version' printed no 'version X.Y.Z', 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
|
||||||
|
rm -f "$stderr_file"
|
||||||
local -a have=("${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}" "${BASH_REMATCH[3]}")
|
local -a have=("${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}" "${BASH_REMATCH[3]}")
|
||||||
local -a need
|
local -a need
|
||||||
IFS=. read -r -a need <<<"$APM_MIN_VERSION"
|
IFS=. read -r -a need <<<"$APM_MIN_VERSION"
|
||||||
|
|||||||
@@ -48,6 +48,9 @@ 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
|
||||||
|
# version check must parse apm's stdout, never this (review round 1 of #271).
|
||||||
|
echo "Using CPython 3.14.6" >&2
|
||||||
exec "$BIN/apm" "\$@"
|
exec "$BIN/apm" "\$@"
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
@@ -165,7 +168,7 @@ 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" <<< "$OUT" \
|
[[ $RC -ne 0 ]] && grep -qF "printed no 'version X.Y.Z'" <<< "$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
|
||||||
|
|||||||
Reference in new issue
Block a user