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
@@ -25,6 +25,20 @@ project_dir="${CLAUDE_PROJECT_DIR:-$PWD}"
|
||||
# installed this plugin natively. Say nothing and cost nothing.
|
||||
[[ -f "$project_dir/apm.lock.yaml" ]] || exit 0
|
||||
|
||||
# Every apm call below is bounded, and stock macOS ships no `timeout`; Homebrew
|
||||
# coreutils installs it as `gtimeout`. Without either, nothing can be bounded,
|
||||
# so the hook stays silent on every path rather than risk holding the session
|
||||
# open — or misreporting an apm whose version it could not read. It is chosen
|
||||
# before the apm, so no notice is printed either. The budget test in
|
||||
# tests/test-apm-current-hook.sh sums every `"$to" N` and `timeout N` here.
|
||||
if command -v timeout > /dev/null 2>&1; then
|
||||
to=timeout
|
||||
elif command -v gtimeout > /dev/null 2>&1; then
|
||||
to=gtimeout
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Choose the apm once, and use it for every call below (ADR-0034):
|
||||
# 1. the repo's own pin, run as `uv run`, when the project pins apm-cli AND
|
||||
# uv is on PATH;
|
||||
@@ -53,6 +67,7 @@ project_dir="${CLAUDE_PROJECT_DIR:-$PWD}"
|
||||
# literals and is never built from command output. apm_cmd is never seeded
|
||||
# empty: every branch below either sets it or exits, which keeps its expansions
|
||||
# safe under `set -u` on bash 3.2 (tests/test-vale-wrap.sh scans for this).
|
||||
|
||||
# Only ever emit fixed text plus a digit-checked count — never interpolate
|
||||
# command output into the JSON, which would need escaping this cannot do safely.
|
||||
emit() {
|
||||
@@ -78,19 +93,6 @@ else
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Every apm call below is bounded, and stock macOS ships no `timeout`; Homebrew
|
||||
# coreutils installs it as `gtimeout`. Without either, nothing can be bounded,
|
||||
# so the hook stays silent rather than risk holding the session open — or
|
||||
# misreporting an apm whose version it could not read. The budget test in
|
||||
# tests/test-apm-current-hook.sh sums every `"$to" N` and `timeout N` here.
|
||||
if command -v timeout > /dev/null 2>&1; then
|
||||
to=timeout
|
||||
elif command -v gtimeout > /dev/null 2>&1; then
|
||||
to=gtimeout
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Every apm call below must see the same directory the guard just checked —
|
||||
# `apm outdated` and `apm update` both resolve the lockfile from the cwd.
|
||||
cd "$project_dir" || exit 0
|
||||
@@ -124,7 +126,7 @@ if [[ $version_status -ne 0 ]]; then
|
||||
if [[ "$apm_label" == "uv" && $version_status -eq 1 ]]; then
|
||||
emit false "\`uv run apm\` is older than apm 0.39.2, so the apm install was not checked for staleness (older apm refuses lockfile v4 and would report it as up to date). The project environment is probably not synced to its pin. Run: uv sync --frozen"
|
||||
elif [[ "$apm_label" == "uv" ]]; then
|
||||
emit false "Could not read the version of \`uv run apm\` (it failed or timed out), so the apm install was not checked for staleness. Check that this works: uv run apm --version"
|
||||
emit false "Could not read the version of \`uv run apm\` (it failed or timed out), so the apm install was not checked for staleness. Check that this works: uv run apm --version, or run: uv sync --frozen"
|
||||
elif [[ $version_status -eq 1 ]]; then
|
||||
emit false "\`apm\` on PATH is older than apm 0.39.2, so the apm install was not checked for staleness (older apm refuses lockfile v4 and would report it as up to date). Upgrade the apm on PATH to 0.39.2 or later, or pin apm-cli in this project with uv."
|
||||
else
|
||||
|
||||
@@ -105,14 +105,14 @@ check below catches an old one.
|
||||
|
||||
**It needs `timeout` or `gtimeout`.** Every apm call is bounded. Stock macOS ships no `timeout`, and
|
||||
Homebrew coreutils installs it as `gtimeout`, so the hook uses whichever exists. With neither, it
|
||||
exits 0 silently rather than run an unbounded call.
|
||||
exits 0 silently on every path, before choosing an apm, rather than run an unbounded call.
|
||||
|
||||
**apm older than 0.39.2 is not trusted.** Before the outdated check the hook reads `--version`. If the
|
||||
chosen apm is older than 0.39.2, or its version cannot be read, the hook prints a fixed notice that
|
||||
names the chosen binary and skips the check. The reason is that an older apm refuses a lockfile v4 and
|
||||
would then report the install as up to date. "Too old" and "could not read the version" are separate
|
||||
notices. On the uv path, too old says to run `uv sync --frozen`, and unreadable (the call failed or
|
||||
timed out) says to check `uv run apm --version`. On the `PATH` path, too old says to upgrade or pin
|
||||
timed out) says to check `uv run apm --version` or to run `uv sync --frozen`. On the `PATH` path, too old says to upgrade or pin
|
||||
apm, and unreadable says to check `apm --version`.
|
||||
|
||||
**Advice text is fixed.** Every notice is a literal string, and the only variable part is a
|
||||
@@ -131,9 +131,9 @@ behaviour, not an unset-variable error.
|
||||
|
||||
**The `timeout` in `hooks.json` must exceed the script's own budget.** The script spends at most
|
||||
15s on `apm --version`, 60s on `apm outdated` and 300s on `apm update`, 375s in all. The hook entry
|
||||
declares `timeout: 400`, the sum plus a buffer. Set it lower and a slow remote gets the hook SIGKILLed mid-`apm update`, leaving a
|
||||
partially redeployed `.claude/skills/` and emitting no notice — precisely the silent failure the hook
|
||||
exists to prevent. `tests/test-apm-current-hook.sh` pins the relationship (host timeout > sum of the
|
||||
declares `timeout: 400`, the sum plus a buffer. Set it lower and a slow remote gets the hook
|
||||
SIGKILLed mid-`apm update`, leaving a partially redeployed `.claude/skills/` and emitting no notice —
|
||||
precisely the silent failure the hook exists to prevent. `tests/test-apm-current-hook.sh` pins the relationship (host timeout > sum of the
|
||||
script's internal timeouts) rather than the literal, so raising either side alone fails the suite.
|
||||
|
||||
**Staleness is detected by matching apm's summary line, and both spellings count.** `apm outdated`
|
||||
|
||||
Reference in new issue
Block a user