fix(kyberforge): pick the timeout binary first and tidy review-round-2 points
Review round 2 of #270, all non-blocking. - Resolve `timeout`/`gtimeout` before choosing apm, so a machine with neither stays silent on every path, the uv not-synced notice included. - The uv-path unreadable-version notice also offers `uv sync --frozen`. - Tests: a `timeout` shim replaces the real binary in the whitelisted PATH (and backs `gtimeout`), so the suite runs on macOS without coreutils; add a PATH-route case where `apm --version` exits 1, and a no-timeout case on the uv path; fix two stale comments. - ADR-0034: contract item 1 now spells out `--frozen --no-sync --offline` and the missing-environment short-circuit; amendment dated 2026-12-02. - ADR-0019: the 2026-12-02 amendment moves below the 2026-09-16 one. - docs/hooks.md: rewrap an over-long line. Refs: #270 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
This commit is contained in:
1 parent
367cc1c259
commit
45d740eef1
5 files changed
+74
-31
No files matched your search
@@ -311,10 +311,16 @@ PIN_BIN="$(mktemp -d)"
|
||||
PATH_APM_BIN="$(mktemp -d)"
|
||||
PINNED="$(mktemp -d)"
|
||||
trap 'rm -rf "$FAKE_BIN" "$WORK" "$TOOLS" "$UV_BIN" "$PIN_BIN" "$PATH_APM_BIN" "$PINNED" "${PROBE:-}"' EXIT
|
||||
for tool in bash grep timeout git cat touch head; do
|
||||
for tool in bash grep git cat touch head; do
|
||||
src="$(command -v "$tool" || true)"
|
||||
[[ -n "$src" ]] && ln -s "$src" "$TOOLS/$tool"
|
||||
done
|
||||
# A fake `timeout` that drops its duration and runs the command unbounded, so
|
||||
# the suite does not need coreutils (stock macOS has no `timeout`). The real
|
||||
# bound is the hook's business; these cases only need it to resolve one.
|
||||
TIMEOUT_SHIM="$TOOLS/timeout"
|
||||
printf '#!/usr/bin/env bash\nshift\nexec "$@"\n' > "$TIMEOUT_SHIM"
|
||||
chmod +x "$TIMEOUT_SHIM"
|
||||
|
||||
# A fake apm at $1 that records, under $2, which phases ran. $3 is the
|
||||
# `apm outdated` line, $4 the `apm update` exit code, $5 the version string.
|
||||
@@ -526,7 +532,7 @@ run_pinned "uv apm" > /dev/null
|
||||
rm -f "$PINNED/pyproject.toml"
|
||||
mv "$PINNED/pyproject.toml.off" "$PINNED/pyproject.toml"
|
||||
|
||||
# --- no apm at all: silent, exit 0, with or without the pin ---
|
||||
# --- no apm at all (the pin is present, uv and apm are not): silent, exit 0 ---
|
||||
reset_calls
|
||||
out="$(run_pinned "")"; rc=$?
|
||||
[[ $rc -eq 0 && -z "$out" ]] && pass "no uv, no apm: silent, exit 0" \
|
||||
@@ -604,6 +610,7 @@ for how in "uv run exits non-zero" "no pinned apm to exec"; do
|
||||
out="$(run_pinned "uv")"; rc=$?
|
||||
ctx="$(ctx_of "$out")"
|
||||
[[ $rc -eq 0 ]] && grep -qF "Could not read the version of \`uv run apm\` (it failed or timed out)" <<< "$ctx" \
|
||||
&& grep -qF "or run: uv sync --frozen" <<< "$ctx" \
|
||||
&& ! grep -qF "not synced" <<< "$ctx" \
|
||||
&& pass "pin + uv, $how: exits 0 with the fixed unreadable-version notice, not the not-synced one" \
|
||||
|| fail "pin + uv, $how: expected the unreadable-version notice, got rc=$rc: $out"
|
||||
@@ -618,19 +625,49 @@ mkdir -p "$NO_TO" "$G_TO"
|
||||
for tool in bash grep git cat touch head; do
|
||||
[[ -e "$TOOLS/$tool" ]] && ln -s "$(readlink "$TOOLS/$tool")" "$NO_TO/$tool" && ln -s "$(readlink "$TOOLS/$tool")" "$G_TO/$tool"
|
||||
done
|
||||
ln -s "$(readlink "$TOOLS/timeout")" "$G_TO/gtimeout"
|
||||
ln -s "$TIMEOUT_SHIM" "$G_TO/gtimeout"
|
||||
make_fake_apm "$PATH_APM_BIN" path "$STALE" 0 "$V_NEW"
|
||||
reset_calls
|
||||
out="$(RUN_TOOLS="$NO_TO" run_pinned "apm")"; rc=$?
|
||||
[[ $rc -eq 0 && -z "$out" && -z "$(calls_of path)" ]] \
|
||||
&& pass "no timeout or gtimeout on PATH: silent, exit 0, apm not called" \
|
||||
|| fail "no timeout binary: expected silence and no apm call, got rc=$rc calls=$(calls_of path | tr '\n' '|') out=$out"
|
||||
# Chosen before the apm, so the uv path stays silent too: a pin with uv and no
|
||||
# project environment would otherwise print its not-synced notice.
|
||||
rm -rf "$PINNED/.venv"
|
||||
reset_calls
|
||||
out="$(RUN_TOOLS="$NO_TO" run_pinned "uv apm")"; rc=$?
|
||||
[[ $rc -eq 0 && -z "$out" && -z "$(calls_of uv)" ]] \
|
||||
&& pass "no timeout or gtimeout, pin + uv without .venv: still silent, uv not called" \
|
||||
|| fail "no timeout binary on the uv path: expected silence, got rc=$rc out=$out"
|
||||
mkdir -p "$PINNED/.venv"
|
||||
reset_calls
|
||||
out="$(RUN_TOOLS="$G_TO" run_pinned "apm")"
|
||||
grep -q "^update" <<< "$(calls_of path)" && [[ "$(json_field reloadSkills <<< "$out" 2>/dev/null)" == "True" ]] \
|
||||
&& pass "only gtimeout on PATH (Homebrew coreutils on macOS): uses it and refreshes" \
|
||||
|| fail "gtimeout should stand in for timeout, got calls=$(calls_of path | tr '\n' '|') out=$out"
|
||||
|
||||
# --- PATH apm whose `--version` exits non-zero: unreadable, not too old ---
|
||||
make_fake_apm "$PATH_APM_BIN" path "$STALE" 0 "$V_NEW"
|
||||
cat > "$PATH_APM_BIN/apm" << EOF
|
||||
#!/usr/bin/env bash
|
||||
echo "\$*" >> "$WORK/path-calls"
|
||||
case "\$1" in
|
||||
--version) echo "$V_NEW"; exit 1 ;;
|
||||
outdated) cat "$WORK/path-outdated.txt"; exit 0 ;;
|
||||
esac
|
||||
exit 0
|
||||
EOF
|
||||
reset_calls
|
||||
mv "$PINNED/pyproject.toml" "$PINNED/pyproject.toml.off"
|
||||
out="$(run_pinned "apm")"; rc=$?
|
||||
ctx="$(ctx_of "$out")"
|
||||
[[ $rc -eq 0 ]] && grep -qF "Could not read the version of \`apm\` on PATH (it failed or timed out)" <<< "$ctx" \
|
||||
&& ! grep -qF "older than" <<< "$ctx" && ! grep -q "^outdated" <<< "$(calls_of path)" \
|
||||
&& pass "PATH apm --version exits 1: unreadable-version notice, no outdated check" \
|
||||
|| fail "PATH apm --version exits 1: expected the unreadable notice, got rc=$rc calls=$(calls_of path | tr '\n' '|') out=$out"
|
||||
mv "$PINNED/pyproject.toml.off" "$PINNED/pyproject.toml"
|
||||
|
||||
# --- hostile command output never reaches the advice text ---
|
||||
# Every advice string is a fixed literal; only a digit-checked count is
|
||||
# spliced in. Output stuffed with ANSI escapes, command substitutions,
|
||||
@@ -722,8 +759,8 @@ echo "--- the greped phrase, against the real apm ---"
|
||||
|
||||
# Everything above mocks `apm`, so an apm release that reworded its summary line
|
||||
# would revert this hook to its pre-fix behaviour with a fully green suite.
|
||||
# `apm outdated` has no --json/machine-readable flag (verified against 0.28.0),
|
||||
# so the phrase match cannot be replaced — it can only be pinned.
|
||||
# `apm outdated` has no --json/machine-readable flag (verified against 0.28.0
|
||||
# and 0.39.3), so the phrase match cannot be replaced — it can only be pinned.
|
||||
#
|
||||
# The probe stages a genuinely outdated dependency with no network: a local git
|
||||
# repo stands in for the upstream, reached through `url.<path>.insteadOf`
|
||||
|
||||
Reference in new issue
Block a user