From b0977d407351545cd560cf4544951878b6c3340a Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Wed, 2 Dec 2026 10:12:06 +0000 Subject: [PATCH] feat(scripts): fail the push on a parked executable in apm.lock.yaml apm records each dependency's executables decision as `exec_status:` in the lock. A gated_* value means the trust gate parked that package's hooks, bin or MCP servers. Root `apm audit --ci` still passes in that state, so a wrong key would leave the SessionStart hook or the delivery guard uninstalled with every gate green (spike #269, section 7.3). check-executables-allow-sync now scans the lock's dependencies and fails on any gated_* entry, naming its identity and status, with a Why/Fix block that starts from `apm approve --list`. It runs even when no plugin here ships executables. The test covers deployed, two gated_* values under both readers, the no-plugin case, and that neither the next dependency nor the deployments: section is misreported. gates.md and the hook description note it. Refs: #271 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi --- .pre-commit-config.yaml | 2 +- docs/spec/gates.md | 9 +++ scripts/check-executables-allow-sync.sh | 61 +++++++++++++++++++-- tests/test-check-executables-allow-sync.sh | 64 ++++++++++++++++++++++ 4 files changed, 130 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d0910b6..6140c3e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -71,7 +71,7 @@ repos: - id: check-executables-allow-sync name: Check executables allow keys sync - description: Verify root apm.yml's executables.allow carries a "///plugins/#" key -- the full package identity apm 0.39 matches on, derived from root apm.yml's git+path dependency entry for the plugin, plus the plugin's apm.yml version -- for every plugin that ships executables (plugins//.apm/hooks/ or bin/), reporting every out-of-sync package in one run. A bare "#" key fails, because apm 0.39 parks the hooks under it while root `apm audit --ci` stays green (spike #269). The version half is version-blind to apm, so a stale version still deploys; that half is a record-keeping gate that fails a version bump made without the matching key edit (see ADR-0019's 2026-09-19 correction and docs/spec/gates.md) + description: Verify root apm.yml's executables.allow carries a "///plugins/#" key -- the full package identity apm 0.39 matches on, derived from root apm.yml's git+path dependency entry for the plugin, plus the plugin's apm.yml version -- for every plugin that ships executables (plugins//.apm/hooks/ or bin/), reporting every out-of-sync package in one run. A bare "#" key fails, because apm 0.39 parks the hooks under it while root `apm audit --ci` stays green (spike #269). The version half is version-blind to apm, so a stale version still deploys; that half is a record-keeping gate that fails a version bump made without the matching key edit (see ADR-0019's 2026-09-19 correction and docs/spec/gates.md). It also fails when apm.lock.yaml records any gated_* exec_status, a parked executable that root `apm audit --ci` lets through entry: bash scripts/check-executables-allow-sync.sh language: system stages: [pre-push] diff --git a/docs/spec/gates.md b/docs/spec/gates.md index a950ff6..f75c54c 100644 --- a/docs/spec/gates.md +++ b/docs/spec/gates.md @@ -1282,6 +1282,15 @@ version half stays a repo-level record. The grants are type-level (`hooks: true` content-pinned: `apm approve` would pin content, strip the block's comments, and park the hook on every script edit until someone approves again. +**It also fails on a parked executable in `apm.lock.yaml`** (spike #269, section 7.3). apm records +each dependency's executables decision as `exec_status:` in the lock, `deployed` or a `gated_*` +value such as `gated_pending_approval`. Root `apm audit --ci` passes with executables parked, +because `exec-status-current` only checks that the lock agrees with the gate. So the gate scans the +lock's `dependencies:` and fails on any `gated_*` entry, naming its identity and status, with +`apm approve --list` as the first step of the fix. It runs even when no plugin here ships +executables, since a third-party dependency can be parked too. A missing lock is left to +`apm-audit-ci`'s `lockfile-exists`. It is a line scan of the shape apm writes, not a YAML parse. + The rest of this section describes the 0.28.0 matching that the version-blind behaviour comes from. apm gates a package's `hooks/` and `bin/` on root `apm.yml`'s `executables.allow` diff --git a/scripts/check-executables-allow-sync.sh b/scripts/check-executables-allow-sync.sh index 6300a3a..768b0fb 100755 --- a/scripts/check-executables-allow-sync.sh +++ b/scripts/check-executables-allow-sync.sh @@ -64,13 +64,64 @@ for plugin_dir in "$REPO_ROOT"/plugins/*/; do done shopt -u nullglob -# Only a repo with no executable-shipping plugin at all is a legitimate no-op — -# there is no version to pin and no hook to deploy. -if [[ ${#PLUGINS[@]} -eq 0 ]]; then - exit 0 +FAILED=0 + +# --------------------------------------------------------------------------- +# Parked executables in the lock (spike #269, on #268, section 7.3) +# --------------------------------------------------------------------------- +# apm records each dependency's executables decision as `exec_status:` in +# apm.lock.yaml: `deployed`, or a `gated_*` value (for example +# `gated_pending_approval`) when the trust gate parked its hooks, bin or MCP +# servers. Root `apm audit --ci` passes in that state, because its +# exec-status-current check only asserts the lock agrees with the gate. So a +# wrong key, or a content-pinned hook whose script changed, would leave the +# SessionStart hook or the delivery guard silently uninstalled with every +# other gate green. This fails the push instead. Runs whether or not any +# plugin here ships executables: a third-party dependency can be parked too. +# A missing lock is not this check's concern (apm-audit-ci's lockfile-exists). +# +# A line scan, not a YAML parse: apm writes the lock with libyaml in one fixed +# shape, with `- repo_url:` opening each dependency and its fields at 2 spaces. +LOCKFILE="$REPO_ROOT/apm.lock.yaml" +if [[ -f "$LOCKFILE" ]]; then + GATED="$(awk ' + /^[^ -]/ { in_deps = ($0 ~ /^dependencies:/); next } + !in_deps { next } + /^- / { host = ""; repo = ""; vpath = "" } + { + line = $0 + sub(/^- /, " ", line) + if (line !~ /^ [a-z_]+: /) next + key = line; sub(/^ /, "", key); sub(/: .*/, "", key) + val = line; sub(/^ [a-z_]+: /, "", val); gsub(/["\047]/, "", val) + if (key == "host") host = val + else if (key == "repo_url") repo = val + else if (key == "virtual_path") vpath = val + else if (key == "exec_status" && val ~ /^gated_/) { + id = (host != "" ? host "/" : "") repo (vpath != "" ? "/" vpath : "") + printf "%s: %s\n", id, val + } + } + ' "$LOCKFILE")" + if [[ -n "$GATED" ]]; then + echo "FAIL: apm.lock.yaml records executables apm did not deploy:" >&2 + while IFS= read -r line; do echo " $line" >&2; done <<< "$GATED" + echo " Why: a gated_* exec_status means the trust gate parked that package's hooks, bin or" >&2 + echo " MCP servers: no executables.allow key matches it, or a content pin no longer" >&2 + echo " does. Root 'apm audit --ci' still passes in that state (spike #269), so without" >&2 + echo " this check a parked SessionStart hook or guard goes unnoticed." >&2 + echo " Fix: run 'uv run --frozen apm approve --list' to see why each is parked, correct its" >&2 + echo " executables.allow key in root apm.yml, then 'uv run --frozen apm install' and" >&2 + echo " commit the rewritten apm.lock.yaml." >&2 + FAILED=1 + fi fi -FAILED=0 +# Only a repo with no executable-shipping plugin at all is a legitimate no-op +# for the key checks below — there is no version to pin and no hook to deploy. +if [[ ${#PLUGINS[@]} -eq 0 ]]; then + exit "$FAILED" +fi # "hooks/ and bin/", "hooks/" or "bin/" — what the plugin actually ships, so a # message never claims a package has a bin/ it does not. diff --git a/tests/test-check-executables-allow-sync.sh b/tests/test-check-executables-allow-sync.sh index 6948abf..a29ecf9 100644 --- a/tests/test-check-executables-allow-sync.sh +++ b/tests/test-check-executables-allow-sync.sh @@ -443,6 +443,70 @@ PY2 || fail "fallback must refuse a URL with a port ($port_url)" done +# --------------------------------------------------------------------------- +echo "" +echo "--- a parked executable recorded in apm.lock.yaml fails ---" +# --------------------------------------------------------------------------- + +# write_lock — a lock in the shape apm 0.39.3 +# writes: `- repo_url:` opens each dependency, fields at 2 spaces, host after +# repo_url, exec_status last, then a top-level deployments: section. +write_lock() { + { + echo "lockfile_version: '4'" + echo "apm_version: 0.39.3" + echo "dependencies:" + echo "- repo_url: Owner/Repo" + echo " name: kyberforge" + echo " host: git.example.invalid" + echo " virtual_path: plugins/kyberforge" + echo " deployed_files:" + echo " - .claude/hooks/kyberforge/x.sh" + echo " exec_status: $2" + echo "- repo_url: Owner/Repo" + echo " name: docs" + echo " host: git.example.invalid" + echo " virtual_path: plugins/docs" + echo "deployments:" + echo "- exec_status: gated_pending_approval" + } > "$1/apm.lock.yaml" +} + +F="$(make_fixture "version: 1.5.0" "$MATCHING_BLOCK")" +write_lock "$F" deployed +run_gate "$F" +[[ $GATE_RC -eq 0 ]] && pass "passes a lock whose executables are deployed" \ + || fail "exec_status: deployed must pass, got: $(bash "$SCRIPT" "$F" 2>&1 | head -3 || true)" + +F="$(make_fixture "version: 1.5.0" "$MATCHING_BLOCK")" +write_lock "$F" gated_pending_approval +run_gate "$F" +[[ $GATE_RC -ne 0 ]] && pass "fails a lock that records gated_pending_approval" \ + || fail "a parked executable in the lock must fail the push" +OUT="$(bash "$SCRIPT" "$F" 2>&1 || true)" +grep -qF "git.example.invalid/Owner/Repo/plugins/kyberforge: gated_pending_approval" <<< "$OUT" \ + && pass "names the parked package by identity and its status" \ + || fail "the failure must name the package and status, got: $OUT" +grep -q "Why:" <<< "$OUT" && grep -qF "apm approve --list" <<< "$OUT" \ + && pass "carries Why: and a Fix: naming apm approve --list" || fail "message must carry Why/Fix: $OUT" +grep -qF "plugins/docs" <<< "$OUT" && fail "a dependency with no exec_status must not be reported" \ + || pass "reports only the gated dependency, not the next one or the deployments: section" + +F="$(make_fixture "version: 1.5.0" "$MATCHING_BLOCK")" +write_lock "$F" gated_definition_changed +run_fallback "$F" +[[ $GATE_RC -ne 0 ]] && pass "fails any gated_* status, without PyYAML too" \ + || fail "gated_definition_changed must fail under the fallback reader" + +# A third-party dependency can be parked in a repo whose own plugins ship no +# executables, so the check runs before the no-plugin no-op. +F="$(mktemp -d "$RUN_TMP/fx.XXXXXX")" +echo "name: someone-else" > "$F/apm.yml" +write_lock "$F" gated_pending_approval +run_gate "$F" +[[ $GATE_RC -ne 0 ]] && pass "fails a parked executable even with no executable-shipping plugin" \ + || fail "the lock check must run before the no-plugin no-op" + # --------------------------------------------------------------------------- echo "" echo "--- wired into the pre-push gate ---"