fix(apm): key executables.allow on the full 0.39 package identity

apm 0.39.3 matches executable grants on the package identity
<host>/<owner>/<repo>/<path>. The bare kyberforge#<version> and
delivery#<version> keys that 0.28.0 matched no longer match, so the first
0.39 install parks both hooks and rewrites .claude/settings.json without
them, while root apm audit --ci stays green (spike #269, on #268).

Rename both keys to git.rkdr.net/Mortis/Holocron/plugins/<name>#<version>
with type-level grants, as `apm approve --list` names them on 0.39.3. Keep
the version suffix convention; apm strips it before matching. Do not use
`apm approve`, which would content-pin, strip the block's comments and
park the hook on every script edit.

check-executables-allow-sync now derives each expected key from root
apm.yml's git + path dependency entry for the plugin, fails a bare key with
a message saying why, and fails a shipping plugin with no such entry. Both
readers carry the change, and the test covers URL and path spellings.

Refs: #271

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
This commit is contained in:
Defame1297andClaude Opus 5.5 committed 2026-12-02 08:46:38 +00:00
1 parent feef6d8307
commit e1a99a7291
4 files changed
+249 -50

No files matched your search

+142 -27
View File
@@ -1,22 +1,37 @@
#!/usr/bin/env bash
set -euo pipefail
# Fails the push when root apm.yml's executables.allow stops naming the actual
# version of every plugin that ships executables. A plugin ships executables
# when plugins/<name>/.apm/hooks/ or plugins/<name>/bin/ exists; each one needs
# a '<name>#<version>' key, where <name> and <version> come from its own
# apm.yml (and <name> must equal the directory name, since keys use the
# package name). Every failing package is reported in one run.
# Fails the push when root apm.yml's executables.allow stops naming the full
# identity and actual version of every plugin that ships executables. A plugin
# ships executables when plugins/<name>/.apm/hooks/ or plugins/<name>/bin/
# exists; each one needs a '<identity>#<version>' key:
#
# The grant itself is version-blind — apm matches the version-less name
# alongside '<package>#<version>' (exec_gate.py builds the candidate list,
# _map_grants matches it) — so a stale key keeps granting the package's hooks/
# and bin/ and deployment does not break. What this gate buys is repo-level,
# not apm-level: a version bump without the matching key edit fails this
# repo's own pre-push, so each key stays an accurate record of what was
# approved. See ADR-0019's 2026-09-19 correction and docs/spec/gates.md,
# "check-executables-allow-sync"; nothing else in the pre-push gate compares
# these files.
# * <identity> is the package identity apm 0.39 matches grants on,
# <host>/<owner>/<repo>/<path>, e.g. git.rkdr.net/Mortis/Holocron/plugins/kyberforge.
# It is derived from root apm.yml's own `git:` + `path:` dependency entry
# for plugins/<name>, the same fields apm builds it from: the URL loses its
# scheme, any user@ and a trailing .git, and the path is appended. Verified
# against `apm approve --list` on apm 0.39.3 for a git+path entry on a
# self-hosted host. A plugin with no such entry fails, because no key can be
# derived for it.
# * <version> comes from plugins/<name>/apm.yml (whose name: must equal the
# directory name).
#
# Every failing package is reported in one run.
#
# Under apm 0.28 a bare '<name>#<version>' key matched. Under 0.39.3 it does
# not: the hooks are parked, .claude/settings.json is rewritten without them,
# and root `apm audit --ci` still passes (spike #269, on #268). So a bare key is
# now a real deployment failure that nothing else catches, and this gate names
# it as one.
#
# The '#<version>' suffix is stripped before apm matches, so the grant is
# version-blind and a stale version keeps granting the package's hooks/ and
# bin/. What the version half buys is repo-level, not apm-level: a version bump
# without the matching key edit fails this repo's own pre-push, so each key
# stays an accurate record of what was approved. See ADR-0019's 2026-09-19
# correction and docs/spec/gates.md, "check-executables-allow-sync"; nothing
# else in the pre-push gate compares these files.
#
# Run from repo root or pass REPO_ROOT as arg.
@@ -110,6 +125,8 @@ fi
# e<TAB><plugin dir><TAB><message> zero or more — the plugin's facts are unusable
# a<TAB>present|absent exactly once — is executables.allow a mapping?
# k<TAB><allow key> zero or more
# d<TAB><path><TAB><git url> zero or more — a root dependencies.apm entry
# carrying both git: and path:
#
# python3 + PyYAML is preferred where importable; the fallback below is not a
# YAML parser, it recognises only the shapes these manifests use. PyYAML stays
@@ -167,6 +184,14 @@ if isinstance(allow, dict):
print("k\t%s" % key)
else:
print("a\tabsent")
dependencies = root.get("dependencies")
apm_deps = dependencies.get("apm") if isinstance(dependencies, dict) else None
for entry in apm_deps if isinstance(apm_deps, list) else []:
if isinstance(entry, dict):
git, path = entry.get("git"), entry.get("path")
if isinstance(git, str) and isinstance(path, str):
print("d\t%s\t%s" % (path, git))
PY
}
@@ -193,6 +218,16 @@ top_level_scalar() {
read_facts_bash() {
local line allow_state="absent" in_executables=0 in_allow=0 key plugin manifest
local in_deps=0 in_apm_deps=0 dep_git="" dep_path=""
# Emits the dependency entry collected so far, if it carried both fields.
flush_dep() {
if [[ -n "$dep_git" && -n "$dep_path" ]]; then
printf 'd\t%s\t%s\n' "$dep_path" "$dep_git"
fi
dep_git=""
dep_path=""
}
for plugin in ${READABLE[@]+"${READABLE[@]}"}; do
manifest="$REPO_ROOT/plugins/$plugin/apm.yml"
@@ -208,12 +243,38 @@ read_facts_bash() {
# A top-level key (column 0) closes whatever block was open. Checked before
# anything else so `marketplace:` after `executables:` cannot leak keys in.
if [[ "$line" != [[:space:]]* ]]; then
if [[ "$line" == executables:* ]]; then
in_executables=1
else
in_executables=0
fi
flush_dep
in_executables=0
in_deps=0
case "$line" in
executables:*) in_executables=1 ;;
dependencies:*) in_deps=1 ;;
esac
in_allow=0
in_apm_deps=0
continue
fi
# dependencies: -> apm: -> a list of `- git: ...` / ` path: ...` items at
# 4-space indent, fields at 6 (or on the dash line itself).
if [[ $in_deps -eq 1 ]]; then
if [[ "$line" =~ ^\ \ [^[:space:]#] ]]; then
flush_dep
in_apm_deps=0
[[ "$line" =~ ^\ \ apm: ]] && in_apm_deps=1
continue
fi
[[ $in_apm_deps -eq 1 ]] || continue
if [[ "$line" =~ ^\ \ \ \ -\ * ]]; then
flush_dep
line=" ${line#*- }"
fi
if [[ "$line" =~ ^\ \ \ \ \ \ (git|path):(.*)$ ]]; then
if [[ "${BASH_REMATCH[1]}" == git ]]; then
dep_git="$(unquote "${BASH_REMATCH[2]}")"
else
dep_path="$(unquote "${BASH_REMATCH[2]}")"
fi
fi
continue
fi
[[ $in_executables -eq 1 ]] || continue
@@ -236,6 +297,7 @@ read_facts_bash() {
printf 'k\t%s\n' "$key"
fi
done < "$ROOT_MANIFEST"
flush_dep
printf 'a\t%s\n' "$allow_state"
}
@@ -263,6 +325,36 @@ fact() {
ALLOW_STATE="$(printf '%s\n' "$FACTS" | sed -n 's/^a\t//p')"
ALLOW_KEYS="$(printf '%s\n' "$FACTS" | sed -n 's/^k\t//p')"
# Strips one leading ./ and any trailing / from a dependency path.
norm_path() {
local path="${1#./}"
printf '%s' "${path%/}"
}
# identity <plugin dir> — <host>/<owner>/<repo>/<path> from root apm.yml's
# git+path dependency entry for plugins/<plugin dir>; empty when it has none.
identity() {
local want="plugins/$1" tag path url
while IFS=$'\t' read -r tag path url; do
[[ "$tag" == d && "$(norm_path "$path")" == "$want" ]] || continue
if [[ "$url" == *://* ]]; then
url="${url#*://}"
elif [[ "$url" == *:* ]]; then
url="${url/://}" # scp-like user@host:owner/repo
fi
url="${url#*@}"
url="${url%/}"
url="${url%.git}"
printf '%s/%s' "$url" "$want"
return
done <<< "$FACTS"
}
# expected_key <plugin dir> — '<identity>#<version>'.
expected_key() {
printf '%s#%s' "$(identity "$1")" "$(fact v "$1")"
}
# ---------------------------------------------------------------------------
# Per-package checks
# ---------------------------------------------------------------------------
@@ -294,20 +386,31 @@ for plugin in ${READABLE[@]+"${READABLE[@]}"}; do
if [[ -z "$version" ]]; then
echo "FAIL: plugins/$plugin/apm.yml declares no version:, so no allow key can be checked against it." >&2
echo " Why: the executables.allow key is '<package>#<version>'; with no version there is" >&2
echo " Why: the executables.allow key is '<identity>#<version>'; with no version there is" >&2
echo " nothing for root apm.yml's key to stay in sync with." >&2
echo " Fix: give plugins/$plugin/apm.yml a top-level version: (read by $READER)." >&2
FAILED=1
continue
fi
if [[ -z "$(identity "$plugin")" ]]; then
echo "FAIL: root apm.yml has no dependencies.apm entry with git: and path: plugins/$plugin, so the" >&2
echo " identity apm approves $plugin's $(ships "$plugin") under cannot be derived." >&2
echo " Why: apm 0.39 matches executables.allow on the full identity <host>/<owner>/<repo>/<path>," >&2
echo " built from that entry; this gate builds the expected key from the same fields." >&2
echo " Fix: declare plugins/$plugin in root apm.yml as a '- git: <url>' / 'path: plugins/$plugin'" >&2
echo " dependency (read by $READER)." >&2
FAILED=1
continue
fi
EXPECTED+=("$plugin")
done
if [[ ${#EXPECTED[@]} -gt 0 && "$ALLOW_STATE" != "present" ]]; then
summary=""
for plugin in ${EXPECTED[@]+"${EXPECTED[@]}"}; do
summary+="${summary:+, }$plugin#$(fact v "$plugin")"
summary+="${summary:+, }$(expected_key "$plugin")"
done
echo "FAIL: root apm.yml has no executables.allow mapping, but these packages ship executables: $summary." >&2
echo " Why: without an allow entry apm refuses to deploy a package's hooks/ and bin/ — for" >&2
@@ -317,7 +420,7 @@ if [[ ${#EXPECTED[@]} -gt 0 && "$ALLOW_STATE" != "present" ]]; then
echo " executables:" >&2
echo " allow:" >&2
for plugin in ${EXPECTED[@]+"${EXPECTED[@]}"}; do
echo " $plugin#$(fact v "$plugin"):" >&2
echo " $(expected_key "$plugin"):" >&2
if [[ -d "$REPO_ROOT/plugins/$plugin/.apm/hooks" ]]; then echo " hooks: true" >&2; fi
if [[ -d "$REPO_ROOT/plugins/$plugin/bin" ]]; then echo " bin: true" >&2; fi
done
@@ -325,18 +428,30 @@ if [[ ${#EXPECTED[@]} -gt 0 && "$ALLOW_STATE" != "present" ]]; then
fi
for plugin in ${EXPECTED[@]+"${EXPECTED[@]}"}; do
expected_key="$plugin#$(fact v "$plugin")"
expected_key="$(expected_key "$plugin")"
if grep -qxF -- "$expected_key" <<< "$ALLOW_KEYS"; then
continue
fi
# Keys for the right identity at another version, and bare '<name>#...' keys,
# which apm 0.28 matched and 0.39 does not.
stale_keys=()
bare_keys=()
while IFS= read -r key; do
if [[ -n "$key" && "$key" == "$plugin#"* ]]; then stale_keys+=("$key"); fi
[[ -n "$key" ]] || continue
if [[ "$key" == "$(identity "$plugin")#"* ]]; then stale_keys+=("$key"); fi
if [[ "$key" == "$plugin" || "$key" == "$plugin#"* ]]; then bare_keys+=("$key"); fi
done <<< "$ALLOW_KEYS"
echo "FAIL: root apm.yml's executables.allow has no '$expected_key' key, but that is $plugin's version." >&2
if [[ ${#stale_keys[@]} -gt 0 ]]; then
echo "FAIL: root apm.yml's executables.allow has no '$expected_key' key, but that is $plugin's identity and version." >&2
if [[ ${#bare_keys[@]} -gt 0 ]]; then
echo " Found instead:" >&2
printf ' %s\n' ${bare_keys[@]+"${bare_keys[@]}"} ${stale_keys[@]+"${stale_keys[@]}"} >&2
echo " Why: apm 0.39 matches grants on the full package identity. A bare '$plugin#...' key" >&2
echo " matches nothing, so $plugin's $(ships "$plugin") are parked, .claude/settings.json" >&2
echo " loses its entries, and root 'apm audit --ci' still passes (spike #269, on #268)." >&2
echo " Fix: rename the key in root apm.yml to '$expected_key:'." >&2
elif [[ ${#stale_keys[@]} -gt 0 ]]; then
echo " Found instead:" >&2
printf ' %s\n' ${stale_keys[@]+"${stale_keys[@]}"} >&2
echo " Why: nothing is broken right now — apm's grant is version-blind, so a key naming another" >&2