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
|
||||
# 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.
|
||||
|
||||
@@ -41,6 +42,7 @@ APM_REPO_ROOT="$(CDPATH='' cd -- "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
# as disable-model-invocation (ADR-0034, "Minimum version").
|
||||
APM_MIN_VERSION="0.39.2"
|
||||
|
||||
APM_CMD=()
|
||||
if [[ -n "${APM:-}" ]]; then
|
||||
read -r -a APM_CMD <<<"$APM"
|
||||
else
|
||||
@@ -48,13 +50,18 @@ else
|
||||
fi
|
||||
|
||||
run_apm() {
|
||||
"${APM_CMD[@]}" "$@"
|
||||
${APM_CMD[@]+"${APM_CMD[@]}"} "$@"
|
||||
}
|
||||
|
||||
# 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.
|
||||
require_apm_version() {
|
||||
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
|
||||
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
|
||||
@@ -73,14 +80,14 @@ require_apm_version() {
|
||||
echo " Fix: run 'uv sync --frozen' at the repo root, then retry." >&2
|
||||
return 1
|
||||
fi
|
||||
# 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 }"
|
||||
# Anchored to apm's banner, `Agent Package Manager (APM) CLI version X.Y.Z`,
|
||||
# so no other version-like text on stdout can be taken for apm's version.
|
||||
version="$(grep -oE 'CLI version [0-9]+\.[0-9]+\.[0-9]+' <<<"$output" | head -n 1 || true)"
|
||||
version="${version#CLI version }"
|
||||
if [[ ! "$version" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
|
||||
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 "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
|
||||
return 1
|
||||
fi
|
||||
|
||||
Reference in new issue
Block a user