Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
45d740eef1 | ||
|
|
367cc1c259 | ||
|
|
1fb8cc797b |
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "holocron",
|
"name": "holocron",
|
||||||
"description": "AI development skills for Claude Code, and for GitHub Copilot through apm — factory, design, implement, review, and cross-cutting workflows.",
|
"description": "AI development skills for Claude Code, and for GitHub Copilot through apm — factory, design, implement, review, and cross-cutting workflows.",
|
||||||
"version": "0.9.0",
|
"version": "0.9.1",
|
||||||
"owner": {
|
"owner": {
|
||||||
"name": "Mortis",
|
"name": "Mortis",
|
||||||
"url": "https://git.rkdr.net/Mortis/"
|
"url": "https://git.rkdr.net/Mortis/"
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
{
|
{
|
||||||
"name": "kyberforge",
|
"name": "kyberforge",
|
||||||
"description": "Skills and agents for creating, maintaining, and managing an apm plugin marketplace for Claude Code and GitHub Copilot.",
|
"description": "Skills and agents for creating, maintaining, and managing an apm plugin marketplace for Claude Code and GitHub Copilot.",
|
||||||
"version": "2.2.1",
|
"version": "2.3.0",
|
||||||
"category": "Developer Tools",
|
"category": "Developer Tools",
|
||||||
"source": "./plugins/kyberforge"
|
"source": "./plugins/kyberforge"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name: holocron
|
name: holocron
|
||||||
version: 0.9.0
|
version: 0.9.1
|
||||||
description: AI development skills for Claude Code, and for GitHub Copilot through apm — factory, design, implement, review, and cross-cutting workflows.
|
description: AI development skills for Claude Code, and for GitHub Copilot through apm — factory, design, implement, review, and cross-cutting workflows.
|
||||||
license: MIT
|
license: MIT
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ dependencies:
|
|||||||
# an apm mechanic.
|
# an apm mechanic.
|
||||||
executables:
|
executables:
|
||||||
allow:
|
allow:
|
||||||
kyberforge#2.2.1:
|
kyberforge#2.3.0:
|
||||||
hooks: true
|
hooks: true
|
||||||
bin: true
|
bin: true
|
||||||
# delivery ships the guard hook (ADR-0032 enforcement layer 2). Same
|
# delivery ships the guard hook (ADR-0032 enforcement layer 2). Same
|
||||||
@@ -86,7 +86,7 @@ marketplace:
|
|||||||
# top-level apm.yml description:/version: above are NOT inherited into the
|
# top-level apm.yml description:/version: above are NOT inherited into the
|
||||||
# compiled output despite being used elsewhere (e.g. by `apm audit`).
|
# compiled output despite being used elsewhere (e.g. by `apm audit`).
|
||||||
description: AI development skills for Claude Code, and for GitHub Copilot through apm — factory, design, implement, review, and cross-cutting workflows.
|
description: AI development skills for Claude Code, and for GitHub Copilot through apm — factory, design, implement, review, and cross-cutting workflows.
|
||||||
version: 0.9.0
|
version: 0.9.1
|
||||||
owner:
|
owner:
|
||||||
name: Mortis
|
name: Mortis
|
||||||
url: https://git.rkdr.net/Mortis/
|
url: https://git.rkdr.net/Mortis/
|
||||||
|
|||||||
@@ -144,6 +144,11 @@ value to be larger — so changing either side without the other fails the suite
|
|||||||
> Re-measured: ~24–26 s for the same six-behind refresh, warm, on a LAN remote — well inside the
|
> Re-measured: ~24–26 s for the same six-behind refresh, warm, on a LAN remote — well inside the
|
||||||
> 380 s above.
|
> 380 s above.
|
||||||
|
|
||||||
|
> **Amendment (2026-12-02, holocron#270) — the budget is now 375 s and the host timeout 400 s.** The
|
||||||
|
> hook also reads `apm --version` under a 15 s bound before the outdated check (ADR-0034), and calls
|
||||||
|
> `timeout` or `gtimeout` through a variable, which the budget test parses too. The current numbers
|
||||||
|
> and their breakdown live in `plugins/kyberforge/docs/hooks.md`.
|
||||||
|
|
||||||
**Reading a human-readable CLI for a control decision cost a silent failure, again.** `apm outdated`
|
**Reading a human-readable CLI for a control decision cost a silent failure, again.** `apm outdated`
|
||||||
has no `--json` or other machine-readable flag (confirmed against 0.28.0), so the hook must match
|
has no `--json` or other machine-readable flag (confirmed against 0.28.0), so the hook must match
|
||||||
its prose. The first attempt matched `outdated dependencies found` — plural only. apm emits
|
its prose. The first attempt matched `outdated dependencies found` — plural only. apm emits
|
||||||
|
|||||||
@@ -2,6 +2,14 @@
|
|||||||
|
|
||||||
**Status: accepted (2026-12-01).**
|
**Status: accepted (2026-12-01).**
|
||||||
|
|
||||||
|
*Amended 2026-12-02 (holocron#270): the hook's test seam is a `PATH` stub of `uv`, not an `APM`
|
||||||
|
environment override. `tests/test-apm-current-hook.sh` puts a fake `uv` first on a `PATH` that
|
||||||
|
excludes the machine's real `uv` and `apm`. The fake records every invocation and reaches the pinned
|
||||||
|
fake apm only through `uv run`, so the shipped hook carries no test-only override. The `APM` variable
|
||||||
|
under Invocation still applies to repo scripts, not to the hook. The hook also passes `--no-sync` and
|
||||||
|
`--offline` to `uv run`. A plain `uv run --frozen` syncs the environment before running, which is the
|
||||||
|
uv sync and the network access this contract forbids.*
|
||||||
|
|
||||||
## Context
|
## Context
|
||||||
|
|
||||||
Issue #265. apm is installed once per machine with pipx, at 0.28.0, and every repo and the
|
Issue #265. apm is installed once per machine with pipx, at 0.28.0, and every repo and the
|
||||||
@@ -35,12 +43,19 @@ Issue #265. apm is installed once per machine with pipx, at 0.28.0, and every re
|
|||||||
scripts and their tests) follows as one PR. The order matters because the deployed hook comes from
|
scripts and their tests) follows as one PR. The order matters because the deployed hook comes from
|
||||||
the `main` commit that `apm.lock.yaml` records. If the v4 lock landed first, the old hook would run
|
the `main` commit that `apm.lock.yaml` records. If the v4 lock landed first, the old hook would run
|
||||||
`PATH` apm 0.28.0, which refuses the lock, and staleness detection would be lost with no error.
|
`PATH` apm 0.28.0, which refuses the lock, and staleness detection would be lost with no error.
|
||||||
|
The cost of this order: between the hook landing and the cutover, this repo has no pin, so the hook
|
||||||
|
runs `PATH` apm 0.28.0 and prints the fixed too-old notice at every session start. Auto-refresh
|
||||||
|
is paused here until the #271 cutover adds the pin.
|
||||||
- **The cutover PR commits a lock rewrite (v1 to v4) on purpose.** It is the one sanctioned exception
|
- **The cutover PR commits a lock rewrite (v1 to v4) on purpose.** It is the one sanctioned exception
|
||||||
to the rule that `apm.lock.yaml` churn is discarded on feature branches (ADR-0019).
|
to the rule that `apm.lock.yaml` churn is discarded on feature branches (ADR-0019).
|
||||||
- **Consumer hook contract.** The shipped hook (`check-apm-current.sh`) resolves apm in this order:
|
- **Consumer hook contract.** The shipped hook (`check-apm-current.sh`) resolves apm in this order:
|
||||||
1. `uv run --frozen`, when the project pins `apm-cli` and uv exists.
|
1. `uv run --frozen --no-sync --offline`, when the project pins `apm-cli` (a quoted `apm-cli`
|
||||||
|
requirement in `pyproject.toml` plus a `uv.lock`) and uv exists. If the project environment
|
||||||
|
(`$UV_PROJECT_ENVIRONMENT`, else `<root>/.venv`) does not exist, the hook prints a fixed "not
|
||||||
|
synced, run `uv sync --frozen`" notice and never calls uv, because even `--no-sync` creates an
|
||||||
|
empty `.venv`.
|
||||||
2. `apm` on `PATH`.
|
2. `apm` on `PATH`.
|
||||||
3. Neither: exit 0.
|
3. Neither: exit 0. So does a machine with no `timeout` or `gtimeout`, on every path.
|
||||||
|
|
||||||
It never triggers a uv sync, and on a cold cache it must not touch the network inside the
|
It never triggers a uv sync, and on a cold cache it must not touch the network inside the
|
||||||
`SessionStart` timeout. It never reports "up to date" when it ran on an apm older than 0.39.2. Its
|
`SessionStart` timeout. It never reports "up to date" when it ran on an apm older than 0.39.2. Its
|
||||||
|
|||||||
@@ -24,26 +24,49 @@ project_dir="${CLAUDE_PROJECT_DIR:-$PWD}"
|
|||||||
# No lockfile means nothing was installed through apm here — e.g. a host that
|
# No lockfile means nothing was installed through apm here — e.g. a host that
|
||||||
# installed this plugin natively. Say nothing and cost nothing.
|
# installed this plugin natively. Say nothing and cost nothing.
|
||||||
[[ -f "$project_dir/apm.lock.yaml" ]] || exit 0
|
[[ -f "$project_dir/apm.lock.yaml" ]] || exit 0
|
||||||
command -v apm > /dev/null 2>&1 || exit 0
|
|
||||||
|
|
||||||
# Every apm call below must see the same directory the guard just checked —
|
# Every apm call below is bounded, and stock macOS ships no `timeout`; Homebrew
|
||||||
# `apm outdated` and `apm update` both resolve the lockfile from the cwd.
|
# coreutils installs it as `gtimeout`. Without either, nothing can be bounded,
|
||||||
cd "$project_dir" || exit 0
|
# 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
|
||||||
|
|
||||||
# `apm outdated` exits 0 whether or not anything is stale, so the answer has to
|
# Choose the apm once, and use it for every call below (ADR-0034):
|
||||||
# come from its output. ~0.7s against six remote refs; a hung remote must not
|
# 1. the repo's own pin, run as `uv run`, when the project pins apm-cli AND
|
||||||
# hold the session open.
|
# uv is on PATH;
|
||||||
|
# 2. otherwise the `apm` on PATH;
|
||||||
|
# 3. otherwise nothing: exit silently.
|
||||||
#
|
#
|
||||||
# There is no --json/machine-readable flag on `apm outdated` (verified against
|
# "Pins apm-cli" means a pyproject.toml whose text carries a quoted apm-cli
|
||||||
# apm 0.28.0), so the phrase match is forced rather than chosen. Note the
|
# requirement (`"apm-cli==0.39.3"`, `'apm_cli>=0.39'`, ...) AND a uv.lock next
|
||||||
# singular: apm prints "1 outdated dependency found" when exactly one package is
|
# to it. It is a text match, not a TOML parse: the hook must not depend on a
|
||||||
# behind, so matching only "dependencies" would silently miss a one-package
|
# Python being on PATH, and a quoted `apm-cli` requirement string has no other
|
||||||
# drift. tests/test-apm-current-hook.sh pins both spellings against the real apm.
|
# plausible meaning in a pyproject.toml. The uv.lock is required because
|
||||||
outdated_output="$(timeout 60 apm outdated 2>&1)" || exit 0
|
# `--frozen` runs from the lock and has nothing to run without one; a pin with
|
||||||
grep -qE 'outdated dependenc(y|ies) found' <<< "$outdated_output" || exit 0
|
# no lock falls through to PATH apm and its version check.
|
||||||
|
#
|
||||||
stale_count="$(grep -oE '[0-9]+ outdated dependenc(y|ies) found' <<< "$outdated_output" | grep -oE '^[0-9]+' || true)"
|
# uv is only ever invoked as `uv run`, and with `--no-sync`: a plain `uv run`
|
||||||
[[ "$stale_count" =~ ^[0-9]+$ ]] || stale_count="some"
|
# syncs the environment first, which installs packages and can reach the
|
||||||
|
# network, and a SessionStart hook must do neither. `--offline` closes the
|
||||||
|
# remaining gap (uv fetching a Python). Even `--no-sync` creates an empty
|
||||||
|
# .venv when none exists, so a project environment that is missing altogether
|
||||||
|
# (`$UV_PROJECT_ENVIRONMENT`, else <root>/.venv) gets a fixed "not synced"
|
||||||
|
# notice and uv is never called. One that exists but was never synced has no
|
||||||
|
# apm of its own, so `uv run` falls through to whatever apm is on PATH, and the
|
||||||
|
# version check below catches an old one and tells the reader to sync.
|
||||||
|
#
|
||||||
|
# apm_label names the chosen binary in advice text. It selects between fixed
|
||||||
|
# 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
|
# 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.
|
# command output into the JSON, which would need escaping this cannot do safely.
|
||||||
@@ -51,6 +74,83 @@ emit() {
|
|||||||
printf '{"hookSpecificOutput":{"hookEventName":"SessionStart","reloadSkills":%s,"additionalContext":"%s"}}\n' "$1" "$2"
|
printf '{"hookSpecificOutput":{"hookEventName":"SessionStart","reloadSkills":%s,"additionalContext":"%s"}}\n' "$1" "$2"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apm_label=""
|
||||||
|
if [[ -f "$project_dir/pyproject.toml" && -f "$project_dir/uv.lock" ]] \
|
||||||
|
&& grep -qiE "[\"']apm[-_.]cli[^a-z0-9_.-]" "$project_dir/pyproject.toml" 2> /dev/null \
|
||||||
|
&& command -v uv > /dev/null 2>&1; then
|
||||||
|
uv_env="${UV_PROJECT_ENVIRONMENT:-$project_dir/.venv}"
|
||||||
|
[[ "$uv_env" == /* ]] || uv_env="$project_dir/$uv_env"
|
||||||
|
if [[ ! -d "$uv_env" ]]; then
|
||||||
|
emit false "This project pins apm with uv but its environment has not been synced, so the apm install was not checked for staleness. Run: uv sync --frozen"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
apm_cmd=(uv run --project "$project_dir" --frozen --no-sync --offline apm)
|
||||||
|
apm_label="uv"
|
||||||
|
elif command -v apm > /dev/null 2>&1; then
|
||||||
|
apm_cmd=(apm)
|
||||||
|
apm_label="path"
|
||||||
|
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
|
||||||
|
|
||||||
|
# apm older than 0.39.2 refuses a lockfile v4 and would then report it as up to
|
||||||
|
# date, so its `outdated` verdict is worthless (ADR-0034). Below the minimum, or
|
||||||
|
# when the version cannot be read at all, say so in a fixed line and skip the
|
||||||
|
# check: a silent pass here is exactly the false "up to date" to avoid. Only the
|
||||||
|
# first dotted triple is taken, and only its digits are compared.
|
||||||
|
#
|
||||||
|
# Returns 0 when new enough, 1 when the version was read and is too old, and 2
|
||||||
|
# when it could not be read (the call failed or timed out, or printed no
|
||||||
|
# version), so the notice can say which.
|
||||||
|
version_ok() {
|
||||||
|
local version_output version
|
||||||
|
version_output="$("$to" 15 "${apm_cmd[@]}" --version 2> /dev/null)" || return 2
|
||||||
|
version="$(grep -oE '[0-9]+\.[0-9]+\.[0-9]+' <<< "$version_output" | head -n 1)"
|
||||||
|
[[ "$version" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]] || return 2
|
||||||
|
local -a have=("${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}" "${BASH_REMATCH[3]}") need=(0 39 2)
|
||||||
|
local i
|
||||||
|
for i in 0 1 2; do
|
||||||
|
((10#${have[i]} > need[i])) && return 0
|
||||||
|
((10#${have[i]} < need[i])) && return 1
|
||||||
|
done
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
version_ok
|
||||||
|
version_status=$?
|
||||||
|
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, 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
|
||||||
|
emit false "Could not read the version of \`apm\` on PATH (it failed or timed out), so the apm install was not checked for staleness. Check that this works: apm --version"
|
||||||
|
fi
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# `apm outdated` exits 0 whether or not anything is stale, so the answer has to
|
||||||
|
# come from its output. Measured ~0.7s against six remote refs on apm 0.28.0
|
||||||
|
# from PATH, and ~3.6s through `uv run` on 0.39.3; a hung remote must not hold
|
||||||
|
# the session open.
|
||||||
|
#
|
||||||
|
# There is no --json/machine-readable flag on `apm outdated` (verified against
|
||||||
|
# apm 0.28.0 and 0.39.3), so the phrase match is forced rather than chosen. Note the
|
||||||
|
# singular: apm prints "1 outdated dependency found" when exactly one package is
|
||||||
|
# behind, so matching only "dependencies" would silently miss a one-package
|
||||||
|
# drift. tests/test-apm-current-hook.sh pins both spellings against the real apm.
|
||||||
|
outdated_output="$("$to" 60 "${apm_cmd[@]}" outdated 2>&1)" || exit 0
|
||||||
|
grep -qE 'outdated dependenc(y|ies) found' <<< "$outdated_output" || exit 0
|
||||||
|
|
||||||
|
stale_count="$(grep -oE '[0-9]+ outdated dependenc(y|ies) found' <<< "$outdated_output" | grep -oE '^[0-9]+' || true)"
|
||||||
|
[[ "$stale_count" =~ ^[0-9]+$ ]] || stale_count="some"
|
||||||
|
|
||||||
# What to do with the rewritten lock depends on the branch (ADR-0019): on the
|
# What to do with the rewritten lock depends on the branch (ADR-0019): on the
|
||||||
# default branch it is a real update to commit or discard; on a feature branch it
|
# default branch it is a real update to commit or discard; on a feature branch it
|
||||||
# is churn unrelated to the branch and should be discarded. The branch name only
|
# is churn unrelated to the branch and should be discarded. The branch name only
|
||||||
@@ -72,15 +172,22 @@ default_branch="${default_branch#origin/}"
|
|||||||
if [[ -n "$current_branch" && -n "$default_branch" ]]; then
|
if [[ -n "$current_branch" && -n "$default_branch" ]]; then
|
||||||
if [[ "$current_branch" == "$default_branch" ]]; then
|
if [[ "$current_branch" == "$default_branch" ]]; then
|
||||||
lock_advice="this is the default branch, so commit it or discard it deliberately."
|
lock_advice="this is the default branch, so commit it or discard it deliberately."
|
||||||
|
else
|
||||||
|
if [[ "$apm_label" == "uv" ]]; then
|
||||||
|
lock_advice="this is a feature branch, so discard it: git checkout -- apm.lock.yaml && uv run apm install"
|
||||||
else
|
else
|
||||||
lock_advice="this is a feature branch, so discard it: git checkout -- apm.lock.yaml && apm install"
|
lock_advice="this is a feature branch, so discard it: git checkout -- apm.lock.yaml && apm install"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if timeout 300 apm update --yes > /dev/null 2>&1; then
|
manual_update="apm update --yes"
|
||||||
|
[[ "$apm_label" == "uv" ]] && manual_update="uv run apm update --yes"
|
||||||
|
|
||||||
|
if "$to" 300 "${apm_cmd[@]}" update --yes > /dev/null 2>&1; then
|
||||||
emit true "apm install was ${stale_count} package(s) behind the remote default branch and has been refreshed automatically; skills and agents were redeployed and re-scanned. apm.lock.yaml has been rewritten and is now a modified file in the working tree - ${lock_advice}"
|
emit true "apm install was ${stale_count} package(s) behind the remote default branch and has been refreshed automatically; skills and agents were redeployed and re-scanned. apm.lock.yaml has been rewritten and is now a modified file in the working tree - ${lock_advice}"
|
||||||
else
|
else
|
||||||
emit false "apm install is ${stale_count} package(s) behind the remote default branch and the automatic refresh failed. Deployed skills and agents may be stale. Run: apm update --yes"
|
emit false "apm install is ${stale_count} package(s) behind the remote default branch and the automatic refresh failed. Deployed skills and agents may be stale. Run: ${manual_update}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
"hooks": [
|
"hooks": [
|
||||||
{
|
{
|
||||||
"command": "${CLAUDE_PLUGIN_ROOT}/.apm/hooks/check-apm-current.sh",
|
"command": "${CLAUDE_PLUGIN_ROOT}/.apm/hooks/check-apm-current.sh",
|
||||||
"timeout": 380,
|
"timeout": 400,
|
||||||
"type": "command"
|
"type": "command"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name: kyberforge
|
name: kyberforge
|
||||||
version: 2.2.1
|
version: 2.3.0
|
||||||
description: Skills and agents for creating, maintaining, and managing an apm plugin marketplace for Claude Code and GitHub Copilot.
|
description: Skills and agents for creating, maintaining, and managing an apm plugin marketplace for Claude Code and GitHub Copilot.
|
||||||
author:
|
author:
|
||||||
name: Mortis
|
name: Mortis
|
||||||
|
|||||||
@@ -87,6 +87,39 @@ and if anything is behind, runs `apm update --yes` and returns `reloadSkills: tr
|
|||||||
session picks up the redeployed content. Rationale, measurements, and the failure modes are in
|
session picks up the redeployed content. Rationale, measurements, and the failure modes are in
|
||||||
ADR-0019.
|
ADR-0019.
|
||||||
|
|
||||||
|
**Which apm it runs.** The hook picks one apm and uses it for every call (ADR-0034):
|
||||||
|
|
||||||
|
1. `uv run --project <root> --frozen --no-sync --offline apm`, when the project pins apm and `uv` is
|
||||||
|
on `PATH`. A pin is a `pyproject.toml` carrying a quoted `apm-cli` requirement plus a `uv.lock`
|
||||||
|
beside it. It is matched as text so the hook needs no Python.
|
||||||
|
2. Otherwise the `apm` on `PATH`.
|
||||||
|
3. Otherwise nothing: it exits 0 silently.
|
||||||
|
|
||||||
|
uv is only ever called as `uv run`, with `--no-sync`, so the hook never installs into the environment
|
||||||
|
and never reaches the network through uv. Even `--no-sync` creates an empty `.venv` when none exists,
|
||||||
|
so before taking the uv path the hook checks that the project environment exists. That is
|
||||||
|
`$UV_PROJECT_ENVIRONMENT` when set, else `<root>/.venv`. If it is missing, the hook prints a fixed
|
||||||
|
"not synced, run `uv sync --frozen`" notice and never calls uv. An environment that exists but was
|
||||||
|
never synced has no apm of its own. `uv run` then falls through to the `PATH` apm, and the version
|
||||||
|
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 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` 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
|
||||||
|
digit-checked package count. The commands it names follow the chosen binary: `uv run apm install` or
|
||||||
|
`apm install`, and `uv run apm update --yes` or `apm update --yes`. No command output is ever
|
||||||
|
interpolated.
|
||||||
|
|
||||||
**Where it looks for the lockfile.** The hook resolves a project directory as `${CLAUDE_PROJECT_DIR}`
|
**Where it looks for the lockfile.** The hook resolves a project directory as `${CLAUDE_PROJECT_DIR}`
|
||||||
when the host exports it (Claude Code does, for SessionStart hooks) and the current directory
|
when the host exports it (Claude Code does, for SessionStart hooks) and the current directory
|
||||||
otherwise, then exits silently unless that directory holds an `apm.lock.yaml` — which is what makes
|
otherwise, then exits silently unless that directory holds an `apm.lock.yaml` — which is what makes
|
||||||
@@ -97,14 +130,14 @@ Keep the cwd fallback: a host that sets no `CLAUDE_PROJECT_DIR` must still get i
|
|||||||
behaviour, not an unset-variable error.
|
behaviour, not an unset-variable error.
|
||||||
|
|
||||||
**The `timeout` in `hooks.json` must exceed the script's own budget.** The script spends at most
|
**The `timeout` in `hooks.json` must exceed the script's own budget.** The script spends at most
|
||||||
`timeout 60 apm outdated` plus `timeout 300 apm update`; the hook entry declares `timeout: 380`, the
|
15s on `apm --version`, 60s on `apm outdated` and 300s on `apm update`, 375s in all. The hook entry
|
||||||
sum plus a buffer. Set it lower and a slow remote gets the hook SIGKILLed mid-`apm update`, leaving a
|
declares `timeout: 400`, the sum plus a buffer. Set it lower and a slow remote gets the hook
|
||||||
partially redeployed `.claude/skills/` and emitting no notice — precisely the silent failure the hook
|
SIGKILLed mid-`apm update`, leaving a partially redeployed `.claude/skills/` and emitting no notice —
|
||||||
exists to prevent. `tests/test-apm-current-hook.sh` pins the relationship (host timeout > sum of the
|
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.
|
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`
|
**Staleness is detected by matching apm's summary line, and both spellings count.** `apm outdated`
|
||||||
has no `--json` or otherwise machine-readable output (verified against apm 0.28.0), so the hook
|
has no `--json` or otherwise machine-readable output (verified against apm 0.28.0 and 0.39.3), so the hook
|
||||||
greps its text. apm prints `1 outdated dependency found` in the singular when exactly one package is
|
greps its text. apm prints `1 outdated dependency found` in the singular when exactly one package is
|
||||||
behind and `N outdated dependencies found` otherwise; matching only the plural silently misses a
|
behind and `N outdated dependencies found` otherwise; matching only the plural silently misses a
|
||||||
one-package drift. Because a mocked `apm` would keep a reworded release invisible, the test suite
|
one-package drift. Because a mocked `apm` would keep a reworded release invisible, the test suite
|
||||||
|
|||||||
+425
-10
@@ -2,9 +2,11 @@
|
|||||||
# Tests for plugins/kyberforge/.apm/hooks/check-apm-current.sh — the SessionStart
|
# Tests for plugins/kyberforge/.apm/hooks/check-apm-current.sh — the SessionStart
|
||||||
# hook that keeps an apm-consumed install level with its remote.
|
# hook that keeps an apm-consumed install level with its remote.
|
||||||
#
|
#
|
||||||
# `apm` is mocked throughout: the hook's contract is "read `apm outdated`, decide,
|
# `apm` and `uv` are mocked throughout (seam A: fake binaries first on PATH,
|
||||||
# emit SessionStart JSON", and that is testable without a network or a real
|
# asserting on exit code and stdout, plus the fakes' own call logs): the hook's
|
||||||
# install.
|
# contract is "pick the apm, read `apm outdated`, decide, emit SessionStart
|
||||||
|
# JSON", and that is testable without a network or a real install. The real
|
||||||
|
# apm appears once, at the end, to pin the phrase the hook greps for.
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||||
@@ -31,12 +33,15 @@ GIT_CEILING_DIRECTORIES="$(dirname "$WORK")"
|
|||||||
# `apm update`. Sentinel files record whether update was actually invoked and
|
# `apm update`. Sentinel files record whether update was actually invoked and
|
||||||
# which directory the calls ran in — the hook must run them against the same
|
# which directory the calls ran in — the hook must run them against the same
|
||||||
# directory its lockfile guard checked, not the session's cwd.
|
# directory its lockfile guard checked, not the session's cwd.
|
||||||
|
# `apm --version` answers 0.39.3 unless $3 says otherwise: the hook skips the
|
||||||
|
# outdated check on anything older than 0.39.2 (ADR-0034).
|
||||||
make_apm() {
|
make_apm() {
|
||||||
local outdated_line="$1" update_exit="$2"
|
local outdated_line="$1" update_exit="$2" version="${3:-0.39.3}"
|
||||||
cat > "$FAKE_BIN/apm" << EOF
|
cat > "$FAKE_BIN/apm" << EOF
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
pwd > "$WORK/apm-cwd"
|
pwd > "$WORK/apm-cwd"
|
||||||
case "\$1" in
|
case "\$1" in
|
||||||
|
--version) echo "Agent Package Manager (APM) CLI version $version"; exit 0 ;;
|
||||||
outdated) echo "$outdated_line"; exit 0 ;;
|
outdated) echo "$outdated_line"; exit 0 ;;
|
||||||
update) touch "$WORK/update-was-called"; exit $update_exit ;;
|
update) touch "$WORK/update-was-called"; exit $update_exit ;;
|
||||||
esac
|
esac
|
||||||
@@ -291,6 +296,414 @@ out="$(run_hook_in "$ELSEWHERE" "$ELSEWHERE")"; rc=$?
|
|||||||
&& pass "does not run apm update when there is no lockfile anywhere" \
|
&& pass "does not run apm update when there is no lockfile anywhere" \
|
||||||
|| fail "must not touch a project that does not use apm"
|
|| fail "must not touch a project that does not use apm"
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
echo ""
|
||||||
|
echo "--- which apm: repo-pinned uv, else PATH, else nothing (ADR-0034) ---"
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Seam A: every binary the hook may call is a fake first on a PATH that holds
|
||||||
|
# nothing else of interest. The machine's real uv and apm must not leak into
|
||||||
|
# these cases — a real uv would make "pin but no uv" untestable — so PATH is
|
||||||
|
# built from a whitelist of the system tools the hook and the fakes need.
|
||||||
|
TOOLS="$(mktemp -d)"
|
||||||
|
UV_BIN="$(mktemp -d)"
|
||||||
|
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 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.
|
||||||
|
make_fake_apm() {
|
||||||
|
local bin_dir="$1" tag="$2" outdated_line="$3" update_exit="$4" version="$5"
|
||||||
|
cat > "$bin_dir/apm" << EOF
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
echo "\$*" >> "$WORK/$tag-calls"
|
||||||
|
case "\$1" in
|
||||||
|
--version) printf '%s\n' "$version"; exit 0 ;;
|
||||||
|
outdated) cat "$WORK/$tag-outdated.txt"; exit 0 ;;
|
||||||
|
update) exit $update_exit ;;
|
||||||
|
esac
|
||||||
|
exit 0
|
||||||
|
EOF
|
||||||
|
printf '%s\n' "$outdated_line" > "$WORK/$tag-outdated.txt"
|
||||||
|
chmod +x "$bin_dir/apm"
|
||||||
|
}
|
||||||
|
|
||||||
|
# The fake uv logs every invocation verbatim and only knows `run`: anything
|
||||||
|
# else exits 2. For `run` it skips uv's own options up to the `apm` argument
|
||||||
|
# and execs the pinned fake apm, which is NOT on PATH — so the pinned apm is
|
||||||
|
# reachable only through `uv run`.
|
||||||
|
cat > "$UV_BIN/uv" << EOF
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
printf '%s\n' "\$*" >> "$WORK/uv-calls"
|
||||||
|
[[ "\${1:-}" == run ]] || exit 2
|
||||||
|
[[ -f "$WORK/uv-run-fails" ]] && exit 1
|
||||||
|
shift
|
||||||
|
while [[ \$# -gt 0 && "\$1" != apm ]]; do
|
||||||
|
case "\$1" in --project) shift 2 ;; *) shift ;; esac
|
||||||
|
done
|
||||||
|
[[ "\${1:-}" == apm ]] || exit 2
|
||||||
|
shift
|
||||||
|
exec "$PIN_BIN/apm" "\$@"
|
||||||
|
EOF
|
||||||
|
chmod +x "$UV_BIN/uv"
|
||||||
|
|
||||||
|
# The pin: a pyproject.toml naming apm-cli plus a uv.lock, as ADR-0034 lays out.
|
||||||
|
cat > "$PINNED/pyproject.toml" << 'EOF'
|
||||||
|
[project]
|
||||||
|
name = "consumer"
|
||||||
|
version = "0"
|
||||||
|
requires-python = ">=3.11"
|
||||||
|
|
||||||
|
[tool.uv]
|
||||||
|
package = false
|
||||||
|
|
||||||
|
[dependency-groups]
|
||||||
|
dev = ["apm-cli==0.39.3"]
|
||||||
|
EOF
|
||||||
|
touch "$PINNED/uv.lock" "$PINNED/apm.lock.yaml"
|
||||||
|
# A synced project environment. Without one the hook must not call uv at all.
|
||||||
|
mkdir -p "$PINNED/.venv"
|
||||||
|
|
||||||
|
STALE="[!] 4 outdated dependencies found"
|
||||||
|
CURRENT="[*] All dependencies are up-to-date"
|
||||||
|
V_NEW="Agent Package Manager (APM) CLI version 0.39.3"
|
||||||
|
|
||||||
|
reset_calls() { rm -f "$WORK"/uv-calls "$WORK"/pin-calls "$WORK"/path-calls; }
|
||||||
|
calls_of() { cat "$WORK/$1-calls" 2>/dev/null || true; }
|
||||||
|
|
||||||
|
# $1: space-separated PATH components drawn from uv, apm. Always ends in TOOLS.
|
||||||
|
run_pinned() {
|
||||||
|
local p="" part
|
||||||
|
for part in $1; do
|
||||||
|
case "$part" in
|
||||||
|
uv) p+="$UV_BIN:" ;;
|
||||||
|
apm) p+="$PATH_APM_BIN:" ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
(cd "$PINNED" && env -u CLAUDE_PROJECT_DIR -u UV_PROJECT_ENVIRONMENT PATH="${p}${RUN_TOOLS:-$TOOLS}" bash "$HOOK" 2>/dev/null)
|
||||||
|
}
|
||||||
|
ctx_of() { json_field additionalContext <<< "$1" 2>/dev/null || true; }
|
||||||
|
|
||||||
|
# Every recorded uv call must be `uv run` against the project, frozen, and with
|
||||||
|
# syncing off: a SessionStart hook must never install into the environment.
|
||||||
|
assert_uv_calls_run_only() {
|
||||||
|
local label="$1" n=0 bad=0 line
|
||||||
|
while IFS= read -r line; do
|
||||||
|
[[ -n "$line" ]] || continue
|
||||||
|
n=$((n + 1))
|
||||||
|
[[ "$line" == "run "* ]] || bad=1
|
||||||
|
[[ " $line " == *" sync "* ]] && bad=1
|
||||||
|
[[ " $line " == *" --frozen "* && " $line " == *" --no-sync "* && " $line " == *" --offline "* ]] || bad=1
|
||||||
|
[[ " $line " == *" --project $PINNED "* ]] || bad=1
|
||||||
|
done < <(calls_of uv)
|
||||||
|
if [[ $n -eq 0 ]]; then
|
||||||
|
fail "$label: expected uv to be called at least once, it was not"
|
||||||
|
elif [[ $bad -eq 0 ]]; then
|
||||||
|
pass "$label: all $n uv call(s) are \`uv run --project <root> --frozen --no-sync --offline\`, none is a sync"
|
||||||
|
else
|
||||||
|
fail "$label: uv was called with something other than a frozen no-sync \`run\`: $(tr '\n' '|' <<< "$(calls_of uv)")"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- pin plus uv: uses `uv run`, for both the check and the update ---
|
||||||
|
make_fake_apm "$PIN_BIN" pin "$STALE" 1 "$V_NEW"
|
||||||
|
make_fake_apm "$PATH_APM_BIN" path "$STALE" 1 "$V_NEW"
|
||||||
|
reset_calls
|
||||||
|
out="$(run_pinned "uv apm")"; rc=$?
|
||||||
|
[[ $rc -eq 0 ]] && pass "pin + uv: exits 0" || fail "pin + uv: exit $rc"
|
||||||
|
grep -q "^outdated" <<< "$(calls_of pin)" && grep -q "^update" <<< "$(calls_of pin)" \
|
||||||
|
&& pass "pin + uv: runs the outdated check and the update through \`uv run\`" \
|
||||||
|
|| fail "pin + uv: the pinned apm should see outdated and update, saw: $(calls_of pin | tr '\n' '|')"
|
||||||
|
[[ -z "$(calls_of path)" ]] && pass "pin + uv: never touches the PATH apm" \
|
||||||
|
|| fail "pin + uv: PATH apm was called: $(calls_of path | tr '\n' '|')"
|
||||||
|
grep -qF "Run: uv run apm update --yes" <<< "$(ctx_of "$out")" \
|
||||||
|
&& pass "pin + uv: the failed-refresh advice names \`uv run apm\`" \
|
||||||
|
|| fail "pin + uv: advice should name uv run apm: $(ctx_of "$out")"
|
||||||
|
assert_uv_calls_run_only "pin + uv, stale"
|
||||||
|
|
||||||
|
# --- stale and current on the uv path ---
|
||||||
|
make_fake_apm "$PIN_BIN" pin "$STALE" 0 "$V_NEW"
|
||||||
|
reset_calls
|
||||||
|
out="$(run_pinned "uv")"
|
||||||
|
[[ "$(json_field reloadSkills <<< "$out" 2>/dev/null)" == "True" ]] \
|
||||||
|
&& grep -q "4 package" <<< "$(ctx_of "$out")" \
|
||||||
|
&& pass "uv path, stale: refreshes and reports the count" \
|
||||||
|
|| fail "uv path, stale: expected a successful-refresh notice, got: $out"
|
||||||
|
assert_uv_calls_run_only "uv path, stale"
|
||||||
|
|
||||||
|
make_fake_apm "$PIN_BIN" pin "$CURRENT" 0 "$V_NEW"
|
||||||
|
reset_calls
|
||||||
|
out="$(run_pinned "uv")"; rc=$?
|
||||||
|
[[ $rc -eq 0 && -z "$out" ]] && pass "uv path, current: silent, exit 0" \
|
||||||
|
|| fail "uv path, current: expected silence, got rc=$rc: $out"
|
||||||
|
grep -q "^update" <<< "$(calls_of pin)" && fail "uv path, current: must not update" \
|
||||||
|
|| pass "uv path, current: does not update"
|
||||||
|
assert_uv_calls_run_only "uv path, current"
|
||||||
|
|
||||||
|
# A feature branch's discard advice names the binary that will reinstall.
|
||||||
|
git -C "$PINNED" init -q -b main
|
||||||
|
git -C "$PINNED" -c user.email=[email protected] -c user.name=probe commit -q --allow-empty -m init
|
||||||
|
git -C "$PINNED" update-ref refs/remotes/origin/main HEAD
|
||||||
|
git -C "$PINNED" symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main
|
||||||
|
git -C "$PINNED" checkout -q -b feature/y
|
||||||
|
make_fake_apm "$PIN_BIN" pin "$STALE" 0 "$V_NEW"
|
||||||
|
reset_calls
|
||||||
|
out="$(run_pinned "uv")"
|
||||||
|
grep -qF "git checkout -- apm.lock.yaml && uv run apm install" <<< "$(ctx_of "$out")" \
|
||||||
|
&& pass "uv path, feature branch: the discard advice names \`uv run apm install\`" \
|
||||||
|
|| fail "uv path, feature branch: advice should name uv run apm install: $(ctx_of "$out")"
|
||||||
|
rm -rf "$PINNED/.git"
|
||||||
|
|
||||||
|
# --- pinned apm too old (an unsynced env falls through to an old apm) ---
|
||||||
|
make_fake_apm "$PIN_BIN" pin "$CURRENT" 0 "Agent Package Manager (APM) CLI version 0.28.0"
|
||||||
|
reset_calls
|
||||||
|
out="$(run_pinned "uv")"; rc=$?
|
||||||
|
[[ $rc -eq 0 ]] && pass "uv path, apm 0.28.0: exits 0" || fail "uv path, apm 0.28.0: exit $rc"
|
||||||
|
grep -q "^outdated" <<< "$(calls_of pin)" && fail "uv path, apm 0.28.0: ran the outdated check on a too-old apm" \
|
||||||
|
|| pass "uv path, apm 0.28.0: runs no outdated check"
|
||||||
|
grep -qF "\`uv run apm\` is older than apm 0.39.2" <<< "$(ctx_of "$out")" \
|
||||||
|
&& grep -qF "Run: uv sync --frozen" <<< "$(ctx_of "$out")" \
|
||||||
|
&& pass "uv path, apm 0.28.0: prints the fixed too-old line naming \`uv run apm\`" \
|
||||||
|
|| fail "uv path, apm 0.28.0: expected the uv too-old line, got: $out"
|
||||||
|
assert_uv_calls_run_only "uv path, too old"
|
||||||
|
|
||||||
|
# --- pin but no uv: falls back to the PATH apm ---
|
||||||
|
make_fake_apm "$PIN_BIN" pin "$STALE" 0 "$V_NEW"
|
||||||
|
make_fake_apm "$PATH_APM_BIN" path "$STALE" 1 "$V_NEW"
|
||||||
|
reset_calls
|
||||||
|
out="$(run_pinned "apm")"; rc=$?
|
||||||
|
[[ $rc -eq 0 ]] && pass "pin, no uv: exits 0" || fail "pin, no uv: exit $rc"
|
||||||
|
grep -q "^outdated" <<< "$(calls_of path)" && grep -q "^update" <<< "$(calls_of path)" \
|
||||||
|
&& pass "pin, no uv: falls back to the PATH apm for the check and the update" \
|
||||||
|
|| fail "pin, no uv: PATH apm should run, saw: $(calls_of path | tr '\n' '|')"
|
||||||
|
[[ -z "$(calls_of pin)" ]] && pass "pin, no uv: the pinned apm is not reached" \
|
||||||
|
|| fail "pin, no uv: pinned apm ran without uv"
|
||||||
|
ctx="$(ctx_of "$out")"
|
||||||
|
grep -qF "Run: apm update --yes" <<< "$ctx" && ! grep -qF "uv run" <<< "$ctx" \
|
||||||
|
&& pass "pin, no uv: advice names the bare \`apm\`, not \`uv run apm\`" \
|
||||||
|
|| fail "pin, no uv: advice should name apm only: $ctx"
|
||||||
|
|
||||||
|
# --- pin declared but no uv.lock: `--frozen` has nothing to run from ---
|
||||||
|
rm -f "$PINNED/uv.lock"
|
||||||
|
reset_calls
|
||||||
|
out="$(run_pinned "uv apm")"
|
||||||
|
[[ -z "$(calls_of uv)" ]] && grep -q "^outdated" <<< "$(calls_of path)" \
|
||||||
|
&& pass "pin without uv.lock: does not call uv, uses the PATH apm" \
|
||||||
|
|| fail "pin without uv.lock: expected PATH apm only, uv saw: $(calls_of uv | tr '\n' '|')"
|
||||||
|
touch "$PINNED/uv.lock"
|
||||||
|
|
||||||
|
# --- no pin, with a PATH apm: uv on PATH is ignored ---
|
||||||
|
mv "$PINNED/pyproject.toml" "$PINNED/pyproject.toml.off"
|
||||||
|
make_fake_apm "$PATH_APM_BIN" path "$STALE" 0 "$V_NEW"
|
||||||
|
reset_calls
|
||||||
|
out="$(run_pinned "uv apm")"
|
||||||
|
[[ -z "$(calls_of uv)" ]] && pass "no pin: never calls uv even when it is on PATH" \
|
||||||
|
|| fail "no pin: uv was called: $(calls_of uv | tr '\n' '|')"
|
||||||
|
grep -q "^update" <<< "$(calls_of path)" && [[ "$(json_field reloadSkills <<< "$out" 2>/dev/null)" == "True" ]] \
|
||||||
|
&& pass "no pin, PATH path, stale: refreshes through the PATH apm" \
|
||||||
|
|| fail "no pin, PATH path, stale: expected a refresh via PATH apm, got: $out"
|
||||||
|
|
||||||
|
make_fake_apm "$PATH_APM_BIN" path "$CURRENT" 0 "$V_NEW"
|
||||||
|
reset_calls
|
||||||
|
out="$(run_pinned "uv apm")"; rc=$?
|
||||||
|
[[ $rc -eq 0 && -z "$out" ]] && ! grep -q "^update" <<< "$(calls_of path)" \
|
||||||
|
&& pass "no pin, PATH path, current: silent, no update" \
|
||||||
|
|| fail "no pin, PATH path, current: expected silence, got rc=$rc: $out"
|
||||||
|
|
||||||
|
# A pyproject.toml that does not mention apm-cli is not a pin.
|
||||||
|
printf '[project]\nname = "other"\ndependencies = ["apm-client-lib>=1"]\n' > "$PINNED/pyproject.toml"
|
||||||
|
make_fake_apm "$PATH_APM_BIN" path "$CURRENT" 0 "$V_NEW"
|
||||||
|
reset_calls
|
||||||
|
run_pinned "uv apm" > /dev/null
|
||||||
|
[[ -z "$(calls_of uv)" ]] && pass "a pyproject.toml without apm-cli is not read as a pin" \
|
||||||
|
|| fail "apm-client-lib was mistaken for an apm-cli pin"
|
||||||
|
rm -f "$PINNED/pyproject.toml"
|
||||||
|
mv "$PINNED/pyproject.toml.off" "$PINNED/pyproject.toml"
|
||||||
|
|
||||||
|
# --- 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" \
|
||||||
|
|| fail "no uv, no apm: expected silence, got rc=$rc: $out"
|
||||||
|
|
||||||
|
# --- PATH apm below 0.39.2: fixed too-old line, no outdated check ---
|
||||||
|
for v in 0.28.0 0.39.1 "no version here"; do
|
||||||
|
make_fake_apm "$PATH_APM_BIN" path "$STALE" 0 "Agent Package Manager (APM) CLI version $v"
|
||||||
|
want="\`apm\` on PATH is older than apm 0.39.2"
|
||||||
|
if [[ "$v" == "no version here" ]]; then
|
||||||
|
make_fake_apm "$PATH_APM_BIN" path "$STALE" 0 "$v"
|
||||||
|
want="Could not read the version of \`apm\` on PATH"
|
||||||
|
fi
|
||||||
|
reset_calls
|
||||||
|
out="$(run_pinned "apm")"; rc=$?
|
||||||
|
ctx="$(ctx_of "$out")"
|
||||||
|
if [[ $rc -eq 0 ]] && ! grep -qE "^(outdated|update)" <<< "$(calls_of path)" \
|
||||||
|
&& grep -qF "$want" <<< "$ctx" \
|
||||||
|
&& [[ "$(json_field reloadSkills <<< "$out" 2>/dev/null)" == "False" ]]; then
|
||||||
|
pass "PATH apm reporting '$v': fixed notice ($want), no outdated check, no update"
|
||||||
|
else
|
||||||
|
fail "PATH apm reporting '$v': expected the too-old line and no outdated call; rc=$rc calls=$(calls_of path | tr '\n' '|') out=$out"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
grep -qF "uv run" <<< "$ctx" && fail "PATH too-old line must not name uv run: $ctx" \
|
||||||
|
|| pass "PATH too-old line names the bare apm only"
|
||||||
|
|
||||||
|
# The boundary is inclusive: 0.39.2 is new enough, and so is a later minor.
|
||||||
|
for v in 0.39.2 0.40.0 1.0.0; do
|
||||||
|
make_fake_apm "$PATH_APM_BIN" path "$STALE" 0 "Agent Package Manager (APM) CLI version $v"
|
||||||
|
reset_calls
|
||||||
|
run_pinned "apm" > /dev/null
|
||||||
|
grep -q "^outdated" <<< "$(calls_of path)" \
|
||||||
|
&& pass "PATH apm $v: new enough, runs the outdated check" \
|
||||||
|
|| fail "PATH apm $v: should be accepted as new enough"
|
||||||
|
done
|
||||||
|
|
||||||
|
# --- pin and uv, but no project environment: never call uv ---
|
||||||
|
# `uv run --no-sync` would create an empty .venv in the consumer's repo.
|
||||||
|
rm -rf "$PINNED/.venv"
|
||||||
|
make_fake_apm "$PIN_BIN" pin "$STALE" 0 "$V_NEW"
|
||||||
|
make_fake_apm "$PATH_APM_BIN" path "$STALE" 0 "$V_NEW"
|
||||||
|
reset_calls
|
||||||
|
out="$(run_pinned "uv apm")"; rc=$?
|
||||||
|
[[ $rc -eq 0 ]] && grep -qF "its environment has not been synced" <<< "$(ctx_of "$out")" \
|
||||||
|
&& grep -qF "Run: uv sync --frozen" <<< "$(ctx_of "$out")" \
|
||||||
|
&& pass "pin + uv, no .venv: prints the fixed not-synced notice" \
|
||||||
|
|| fail "pin + uv, no .venv: expected the not-synced notice, got rc=$rc: $out"
|
||||||
|
[[ -z "$(calls_of uv)" && -z "$(calls_of path)" ]] \
|
||||||
|
&& pass "pin + uv, no .venv: calls neither uv nor the PATH apm" \
|
||||||
|
|| fail "pin + uv, no .venv: uv saw '$(calls_of uv | tr '\n' '|')', PATH apm saw '$(calls_of path | tr '\n' '|')'"
|
||||||
|
[[ ! -e "$PINNED/.venv" ]] && pass "pin + uv, no .venv: creates no .venv" \
|
||||||
|
|| fail "pin + uv, no .venv: a .venv appeared in the project"
|
||||||
|
|
||||||
|
# UV_PROJECT_ENVIRONMENT relocates the environment; an existing one there counts.
|
||||||
|
ALT_ENV="$WORK/alt-env"
|
||||||
|
mkdir -p "$ALT_ENV"
|
||||||
|
reset_calls
|
||||||
|
out="$(cd "$PINNED" && env -u CLAUDE_PROJECT_DIR UV_PROJECT_ENVIRONMENT="$ALT_ENV" PATH="$UV_BIN:$TOOLS" bash "$HOOK" 2>/dev/null)"
|
||||||
|
grep -q "^outdated" <<< "$(calls_of pin)" \
|
||||||
|
&& pass "UV_PROJECT_ENVIRONMENT pointing at an existing env: takes the uv path" \
|
||||||
|
|| fail "UV_PROJECT_ENVIRONMENT should satisfy the environment check, got: $out"
|
||||||
|
reset_calls
|
||||||
|
out="$(cd "$PINNED" && env -u CLAUDE_PROJECT_DIR UV_PROJECT_ENVIRONMENT="$WORK/no-such-env" PATH="$UV_BIN:$TOOLS" bash "$HOOK" 2>/dev/null)"
|
||||||
|
[[ -z "$(calls_of uv)" ]] && grep -qF "has not been synced" <<< "$(ctx_of "$out")" \
|
||||||
|
&& pass "UV_PROJECT_ENVIRONMENT pointing at nothing: not-synced notice, no uv call" \
|
||||||
|
|| fail "UV_PROJECT_ENVIRONMENT pointing at nothing should not call uv, got: $out"
|
||||||
|
mkdir -p "$PINNED/.venv"
|
||||||
|
|
||||||
|
# --- pin and uv, but `uv run` itself fails ---
|
||||||
|
for how in "uv run exits non-zero" "no pinned apm to exec"; do
|
||||||
|
make_fake_apm "$PIN_BIN" pin "$STALE" 0 "$V_NEW"
|
||||||
|
if [[ "$how" == "uv run exits non-zero" ]]; then touch "$WORK/uv-run-fails"; else rm -f "$PIN_BIN/apm"; fi
|
||||||
|
reset_calls
|
||||||
|
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"
|
||||||
|
assert_uv_calls_run_only "pin + uv, $how"
|
||||||
|
rm -f "$WORK/uv-run-fails"
|
||||||
|
done
|
||||||
|
|
||||||
|
# --- no timeout binary: nothing can be bounded, so stay silent ---
|
||||||
|
NO_TO="$WORK/tools-no-timeout"
|
||||||
|
G_TO="$WORK/tools-gtimeout"
|
||||||
|
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 "$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,
|
||||||
|
# backticks, separators and quotes must leave no trace in what is emitted.
|
||||||
|
HOSTILE=$'\e[31m[!] 7 outdated dependencies found\e[0m $(touch '"$WORK"'/pwned) `touch '"$WORK"'/pwned2`; rm -rf / ; "}]}\\ \x01'
|
||||||
|
for route in uv apm; do
|
||||||
|
if [[ "$route" == uv ]]; then
|
||||||
|
make_fake_apm "$PIN_BIN" pin "$HOSTILE" 1 "$V_NEW"$'\n\e[0m$(id) `id`;'
|
||||||
|
else
|
||||||
|
mv "$PINNED/pyproject.toml" "$PINNED/pyproject.toml.off"
|
||||||
|
make_fake_apm "$PATH_APM_BIN" path "$HOSTILE" 1 "$V_NEW"$'\n\e[0m$(id) `id`;'
|
||||||
|
fi
|
||||||
|
reset_calls
|
||||||
|
out="$(run_pinned "$route")"; rc=$?
|
||||||
|
ctx="$(ctx_of "$out")"
|
||||||
|
if [[ $rc -eq 0 ]] && echo "$out" | python3 -m json.tool > /dev/null 2>&1 && [[ -n "$ctx" ]]; then
|
||||||
|
pass "hostile output via $route: still exits 0 with valid JSON"
|
||||||
|
else
|
||||||
|
fail "hostile output via $route: rc=$rc, output not valid JSON: $(cat -v <<< "$out")"
|
||||||
|
fi
|
||||||
|
leaked=""
|
||||||
|
for needle in $'\e' '$(' 'pwned' 'rm -rf' '\\' $'\x01' '}]}' 'id`'; do
|
||||||
|
grep -qF -- "$needle" <<< "$out" && leaked+="[$needle]"
|
||||||
|
done
|
||||||
|
[[ -z "$leaked" ]] && pass "hostile output via $route: none of it reaches the emitted text" \
|
||||||
|
|| fail "hostile output via $route: leaked $(cat -v <<< "$leaked") into: $(cat -v <<< "$out")"
|
||||||
|
[[ ! -e "$WORK/pwned" && ! -e "$WORK/pwned2" ]] && pass "hostile output via $route: nothing in it was executed" \
|
||||||
|
|| fail "hostile output via $route: a substitution in apm's output was executed"
|
||||||
|
expected="apm install is 7 package(s) behind the remote default branch and the automatic refresh failed. Deployed skills and agents may be stale. Run: apm update --yes"
|
||||||
|
[[ "$route" == uv ]] && expected="${expected%apm update --yes}uv run apm update --yes"
|
||||||
|
[[ "$ctx" == "$expected" ]] \
|
||||||
|
&& pass "hostile output via $route: the notice is exactly the fixed literal plus the digit-checked count" \
|
||||||
|
|| fail "hostile output via $route: notice differs from the fixed literal: $(cat -v <<< "$ctx")"
|
||||||
|
[[ -f "$PINNED/pyproject.toml.off" ]] && mv "$PINNED/pyproject.toml.off" "$PINNED/pyproject.toml"
|
||||||
|
done
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
echo ""
|
echo ""
|
||||||
echo "--- hooks.json wiring ---"
|
echo "--- hooks.json wiring ---"
|
||||||
@@ -317,7 +730,8 @@ matcher="$(python3 -c 'import json,sys; d=json.load(open(sys.argv[1])); print(d[
|
|||||||
# literal, so raising either internal `timeout` without raising the host budget
|
# literal, so raising either internal `timeout` without raising the host budget
|
||||||
# fails here instead of reintroducing the gap quietly.
|
# fails here instead of reintroducing the gap quietly.
|
||||||
#
|
#
|
||||||
# Every `timeout N` in the script counts, comments included: a stray "timeout
|
# Every `timeout N` or `"$to" N` in the script counts (the hook resolves
|
||||||
|
# `timeout` or `gtimeout` into $to), comments included: a stray "timeout
|
||||||
# 300" in prose only makes this stricter, which is the safe direction.
|
# 300" in prose only makes this stricter, which is the safe direction.
|
||||||
script_budget=0
|
script_budget=0
|
||||||
timeout_count=0
|
timeout_count=0
|
||||||
@@ -325,12 +739,12 @@ while read -r n; do
|
|||||||
[[ -n "$n" ]] || continue
|
[[ -n "$n" ]] || continue
|
||||||
script_budget=$((script_budget + n))
|
script_budget=$((script_budget + n))
|
||||||
timeout_count=$((timeout_count + 1))
|
timeout_count=$((timeout_count + 1))
|
||||||
done < <(grep -oE '\btimeout [0-9]+\b' "$HOOK" | grep -oE '[0-9]+')
|
done < <(grep -oE '(\btimeout|"\$to") [0-9]+\b' "$HOOK" | grep -oE '[0-9]+$')
|
||||||
|
|
||||||
hook_timeout="$(python3 -c 'import json,sys; d=json.load(open(sys.argv[1])); print(d["hooks"]["SessionStart"][0]["hooks"][0]["timeout"])' "$HOOKS_JSON")"
|
hook_timeout="$(python3 -c 'import json,sys; d=json.load(open(sys.argv[1])); print(d["hooks"]["SessionStart"][0]["hooks"][0]["timeout"])' "$HOOKS_JSON")"
|
||||||
|
|
||||||
if [[ $timeout_count -eq 0 ]]; then
|
if [[ $timeout_count -eq 0 ]]; then
|
||||||
fail "found no 'timeout N' in $HOOK — the budget assertion below would be vacuous"
|
fail "found no 'timeout N' or '\"\$to\" N' in $HOOK — the budget assertion below would be vacuous"
|
||||||
else
|
else
|
||||||
pass "parsed $timeout_count internal timeout(s) totalling ${script_budget}s from the hook script"
|
pass "parsed $timeout_count internal timeout(s) totalling ${script_budget}s from the hook script"
|
||||||
[[ $hook_timeout -gt $script_budget ]] \
|
[[ $hook_timeout -gt $script_budget ]] \
|
||||||
@@ -345,8 +759,8 @@ echo "--- the greped phrase, against the real apm ---"
|
|||||||
|
|
||||||
# Everything above mocks `apm`, so an apm release that reworded its summary line
|
# 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.
|
# 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),
|
# `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.
|
# 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
|
# The probe stages a genuinely outdated dependency with no network: a local git
|
||||||
# repo stands in for the upstream, reached through `url.<path>.insteadOf`
|
# repo stands in for the upstream, reached through `url.<path>.insteadOf`
|
||||||
@@ -365,7 +779,7 @@ if ! command -v apm > /dev/null 2>&1 || ! command -v git > /dev/null 2>&1; then
|
|||||||
echo " $SKIP_REASON"
|
echo " $SKIP_REASON"
|
||||||
else
|
else
|
||||||
PROBE="$(mktemp -d)"
|
PROBE="$(mktemp -d)"
|
||||||
trap 'rm -rf "$FAKE_BIN" "$WORK" "$PROBE"' EXIT
|
trap 'rm -rf "$FAKE_BIN" "$WORK" "$TOOLS" "$UV_BIN" "$PIN_BIN" "$PATH_APM_BIN" "$PINNED" "$PROBE"' EXIT
|
||||||
|
|
||||||
UPSTREAM="$PROBE/upstream.git"
|
UPSTREAM="$PROBE/upstream.git"
|
||||||
git init -q "$UPSTREAM"
|
git init -q "$UPSTREAM"
|
||||||
@@ -431,6 +845,7 @@ else
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
pwd > "$WORK/apm-cwd"
|
pwd > "$WORK/apm-cwd"
|
||||||
case "\$1" in
|
case "\$1" in
|
||||||
|
--version) echo "Agent Package Manager (APM) CLI version 0.39.3"; exit 0 ;;
|
||||||
outdated) cat "$PROBE/genuine-$want.txt"; exit 0 ;;
|
outdated) cat "$PROBE/genuine-$want.txt"; exit 0 ;;
|
||||||
update) touch "$WORK/update-was-called"; exit 0 ;;
|
update) touch "$WORK/update-was-called"; exit 0 ;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
Reference in new issue
Block a user