Merge pull request 'fix(rtk): follow up the #284 review notes' (#287) from fix/rtk-review-polish into main
Reviewed-on: #287
This commit was merged in pull request #287.
This commit is contained in:
commit
00c93ba03d
5 files changed
+108
-14
No files matched your search
+15
-6
@@ -1247,22 +1247,31 @@ that `not found in lockfile` form for an identity equal to root `apm.yml`'s own
|
|||||||
must also exist in the working tree and be absent from the **local** `origin/main`, which must
|
must also exist in the working tree and be absent from the **local** `origin/main`, which must
|
||||||
resolve; nothing is fetched. A plugin name must start with a letter or digit and may not contain
|
resolve; nothing is fetched. A plugin name must start with a letter or digit and may not contain
|
||||||
`..`. Any other output fails closed. The waiver lapses for a plugin by itself: once it is on
|
`..`. Any other output fails closed. The waiver lapses for a plugin by itself: once it is on
|
||||||
`origin/main`, the follow-up PR that records it in the lock is required.
|
`origin/main`, the follow-up PR that records it in the lock is required. Because the hook reads
|
||||||
|
only the local `origin/main` ref, a stale or unfetched one keeps the waiver alive after the plugin
|
||||||
|
has landed. That fails safe: the waiver still requires the full 15-check re-run below to pass, so
|
||||||
|
it waives only the `not found in lockfile` rows. `git fetch` refreshes the ref and ends the waiver.
|
||||||
|
|
||||||
**The waiver re-runs the full root check set before it passes.** The cut-short run never reaches the
|
**The waiver re-runs the full root check set before it passes.** The cut-short run never reaches the
|
||||||
other twelve root checks (`content-integrity`, `hook-approval-pins`, `local-bundle-hooks`,
|
other twelve root checks (`content-integrity`, `hook-approval-pins`, `local-bundle-hooks`,
|
||||||
`exec-status-current`, `deployed-files-present` and the rest), so the three-check result alone
|
`exec-status-current`, `deployed-files-present` and the rest), so the three-check result alone
|
||||||
would let a defect in any of them through. Once the conditions above hold, the hook copies the working
|
would let a defect in any of them through. Once the conditions above hold, the hook copies the working
|
||||||
tree (minus `.git` and `.venv`) into a `mktemp -d` directory with `tar`. In the copy it drops only the
|
tree (minus `.git`, `.venv` and `.claude/worktrees`) into a `mktemp -d` directory with `tar`. In the
|
||||||
`dependencies:` > `apm:` items whose `path:` names a waived plugin, checks that the reduced
|
copy it drops only the `dependencies:` > `apm:` items whose `path:` names a waived plugin, checks
|
||||||
`apm.yml` differs from the original by those deletions alone, and runs `git init` with the same
|
that the reduced `apm.yml` differs from the original by those deletions alone and that no entry for
|
||||||
`origin` URL, the only git state apm reads. It then runs `apm audit --ci` there. The push passes only
|
a waived plugin survived, and runs `git init`. It gives that repo the git state apm reads: the
|
||||||
|
same `origin` URL, for org-policy discovery, and a copy of the real repo's `info/exclude` (from
|
||||||
|
`git rev-parse --git-path info/exclude`, so a linked worktree's shared one), which
|
||||||
|
`deployed-files-present` consults through `git check-ignore`. It then runs `apm audit --ci` there. The push passes only
|
||||||
if that run exits 0 and prints `All 15 check(s) passed`. On this branch (holocron#179, apm 0.39.3) it
|
if that run exits 0 and prints `All 15 check(s) passed`. On this branch (holocron#179, apm 0.39.3) it
|
||||||
does, and the hook prints `root re-run without the unlanded plugins: All 15 check(s) passed`. A copy
|
does, and the hook prints `root re-run without the unlanded plugins: All 15 check(s) passed`. A copy
|
||||||
was chosen over swapping `apm.yml` in place under a `trap`: the copy never writes the working tree, so
|
was chosen over swapping `apm.yml` in place under a `trap`: the copy never writes the working tree, so
|
||||||
the tree stays byte-identical even after `SIGKILL`, and a concurrent apm never sees a reduced
|
the tree stays byte-identical even after `SIGKILL`, and a concurrent apm never sees a reduced
|
||||||
manifest. `.git` is not copied because in a linked worktree it points into the shared gitdir. `.venv`
|
manifest. `.git` is not copied because in a linked worktree it points into the shared gitdir. `.venv`
|
||||||
is not copied because apm runs from the real one via `uv run --project`. The scratch directory is
|
is not copied because apm runs from the real one via `uv run --project`. `.claude/worktrees` is not
|
||||||
|
copied because each worktree there is a full checkout that can carry its own `.venv`. Leaving it out
|
||||||
|
hides nothing: it is ignored through `info/exclude`, and the root checks look only at lock-recorded
|
||||||
|
deployed paths, none of which is under it. The scratch directory is
|
||||||
removed on exit, including on `INT`, `TERM` and `HUP`. The script header records the full reasoning.
|
removed on exit, including on `INT`, `TERM` and `HUP`. The script header records the full reasoning.
|
||||||
`tests/test-apm-audit-ci-waiver.sh` covers the waiver, the re-run, and each of its guards.
|
`tests/test-apm-audit-ci-waiver.sh` covers the waiver, the re-run, and each of its guards.
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ This repo hand-writes its grant in the root `apm.yml` and does not run `apm appr
|
|||||||
|
|
||||||
### "ambiguous duplicate APM-owned hook entry"
|
### "ambiguous duplicate APM-owned hook entry"
|
||||||
|
|
||||||
apm raises this error when `.claude/settings.json` holds more byte-identical copies of an APM-owned hook entry than `.claude/apm-hooks.json` records. It happens when the same hook entry is pasted in by hand or merged in twice. To fix it, remove the duplicate entries from `.claude/settings.json`, keeping none of the hand-added copies, then run `apm install` again.
|
`apm audit` raises this error, with or without `--ci`, unless drift checking is off with `--no-drift`. It reports it as a drift finding on `.claude/settings.json`. `apm export-patch` runs the same check. `apm install --frozen` runs it too, but reports only that an APM-managed hook entry was edited or removed. The cause is `.claude/settings.json` holding more byte-identical copies of an APM-owned hook entry than `.claude/apm-hooks.json` records. It happens when the same hook entry is pasted in by hand or merged in twice. To fix it, remove the duplicate entries from `.claude/settings.json`, keeping none of the hand-added copies, then run `apm install` again.
|
||||||
|
|
||||||
## Author
|
## Author
|
||||||
|
|
||||||
|
|||||||
+29
-5
@@ -116,11 +116,25 @@
|
|||||||
# reading another path cannot silently see an empty one.
|
# reading another path cannot silently see an empty one.
|
||||||
# * NOT .git: from a linked worktree it is a pointer file into the shared
|
# * NOT .git: from a linked worktree it is a pointer file into the shared
|
||||||
# gitdir, and a git command run in the copy could then refresh that
|
# gitdir, and a git command run in the copy could then refresh that
|
||||||
# worktree's real index. A fresh `git init` with the same origin URL
|
# worktree's real index. A fresh `git init` stands in for it, carrying the
|
||||||
# stands in for it -- apm reads only the origin remote, for org-policy
|
# two pieces of git state apm reads: the origin remote's URL (org-policy
|
||||||
# discovery, and the copy prints the same policy line the real root does.
|
# discovery; the copy prints the same policy line the real root does) and
|
||||||
|
# the repo's info/exclude, copied from `git rev-parse --git-path
|
||||||
|
# info/exclude` (which resolves to the shared gitdir in a linked worktree)
|
||||||
|
# when it exists. deployed-files-present runs `git check-ignore` on each
|
||||||
|
# lock-recorded path that is absent, and an absent path ignored only
|
||||||
|
# through info/exclude must not count as missing in the copy either.
|
||||||
|
# .gitignore files travel with the tree, and core.excludesFile is the same
|
||||||
|
# user-level config for both runs.
|
||||||
# * NOT .venv: apm runs through `uv run --project <repo root>`, so the
|
# * NOT .venv: apm runs through `uv run --project <repo root>`, so the
|
||||||
# environment is the real one; .venv is no apm input and most of the size.
|
# environment is the real one; .venv is no apm input and most of the size.
|
||||||
|
# * NOT .claude/worktrees: Claude Code's linked worktrees, each a full
|
||||||
|
# checkout that can carry its own .venv. They are ignored through
|
||||||
|
# info/exclude, and no root check reads them: deployed-files-present and
|
||||||
|
# content-integrity look up lock-recorded paths, none of which is under
|
||||||
|
# .claude/worktrees, and drift compares the replay's deployed files
|
||||||
|
# against the same paths in the tree. Leaving them out hides nothing the
|
||||||
|
# real audit would see.
|
||||||
# Only list items under `dependencies:` > `apm:` whose `path:` names a waived
|
# Only list items under `dependencies:` > `apm:` whose `path:` names a waived
|
||||||
# plugin are removed (comments and every other line kept), and the result is
|
# plugin are removed (comments and every other line kept), and the result is
|
||||||
# checked to differ from the original by deletions only, each waived entry gone.
|
# checked to differ from the original by deletions only, each waived entry gone.
|
||||||
@@ -276,9 +290,10 @@ trap 'exit 143' TERM HUP
|
|||||||
# 0 and reports the full root check set passing; otherwise prints why, and
|
# 0 and reports the full root check set passing; otherwise prints why, and
|
||||||
# apm's output, on stderr and fails.
|
# apm's output, on stderr and fails.
|
||||||
reduced_root_audit() {
|
reduced_root_audit() {
|
||||||
local names="$1" origin name rerun rc delta
|
local names="$1" origin exclude name rerun rc delta
|
||||||
SCRATCH="$(mktemp -d "${TMPDIR:-/tmp}/apm-audit-ci.XXXXXX")" || return 1
|
SCRATCH="$(mktemp -d "${TMPDIR:-/tmp}/apm-audit-ci.XXXXXX")" || return 1
|
||||||
if ! tar -C . --exclude=./.git --exclude=./.venv -cf - . | tar -C "$SCRATCH" -xf -; then
|
if ! tar -C . --exclude=./.git --exclude=./.venv --exclude=./.claude/worktrees -cf - . |
|
||||||
|
tar -C "$SCRATCH" -xf -; then
|
||||||
echo 'apm audit --ci: ref-consistency not waived: could not copy the tree for the re-run' >&2
|
echo 'apm audit --ci: ref-consistency not waived: could not copy the tree for the re-run' >&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@@ -309,6 +324,15 @@ reduced_root_audit() {
|
|||||||
if origin="$(git remote get-url origin 2>/dev/null)"; then
|
if origin="$(git remote get-url origin 2>/dev/null)"; then
|
||||||
git -C "$SCRATCH" remote add origin "$origin" || return 1
|
git -C "$SCRATCH" remote add origin "$origin" || return 1
|
||||||
fi
|
fi
|
||||||
|
# The real repo's ignore rules for deployed-files-present (header, "NOT
|
||||||
|
# .git"). --git-path resolves to the shared gitdir from a linked worktree.
|
||||||
|
exclude="$(git rev-parse --path-format=absolute --git-path info/exclude 2>/dev/null)" || exclude=""
|
||||||
|
if [ -n "$exclude" ] && [ -f "$exclude" ]; then
|
||||||
|
if ! mkdir -p "$SCRATCH/.git/info" || ! cp "$exclude" "$SCRATCH/.git/info/exclude"; then
|
||||||
|
echo 'apm audit --ci: ref-consistency not waived: could not copy info/exclude into the re-run copy' >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
rc=0
|
rc=0
|
||||||
rerun="$(cd "$SCRATCH" && run_apm audit --ci 2>&1)" || rc=$?
|
rerun="$(cd "$SCRATCH" && run_apm audit --ci 2>&1)" || rc=$?
|
||||||
if [ "$rc" -ne 0 ] || ! grep -qF "$ROOT_FULL_PASS" <<<"$rerun"; then
|
if [ "$rc" -ne 0 ] || ! grep -qF "$ROOT_FULL_PASS" <<<"$rerun"; then
|
||||||
|
|||||||
@@ -9,7 +9,9 @@
|
|||||||
# every plugin directory. The waiver's re-run is told apart by where it runs:
|
# every plugin directory. The waiver's re-run is told apart by where it runs:
|
||||||
# under $TMPDIR, the script's mktemp scratch copy, where the stub saves the manifest it was given ($STUB_RERUN_LOG) and prints
|
# under $TMPDIR, the script's mktemp scratch copy, where the stub saves the manifest it was given ($STUB_RERUN_LOG) and prints
|
||||||
# $STUB_RERUN_OUTPUT (default: the full root pass) with exit $STUB_RERUN_RC
|
# $STUB_RERUN_OUTPUT (default: the full root pass) with exit $STUB_RERUN_RC
|
||||||
# (default 0). The fixture is a throwaway git repo whose
|
# (default 0). With $STUB_GIT_LOG set it also saves the copy's
|
||||||
|
# .git/info/exclude and notes whether .claude/worktrees was copied. The fixture
|
||||||
|
# is a throwaway git repo whose
|
||||||
# refs/remotes/origin/main is set with update-ref -- nothing is fetched.
|
# refs/remotes/origin/main is set with update-ref -- nothing is fetched.
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
@@ -40,6 +42,10 @@ if [[ -f apm.lock.yaml.root-marker ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
[[ -z "${STUB_RERUN_LOG:-}" ]] || cp apm.yml "$STUB_RERUN_LOG"
|
[[ -z "${STUB_RERUN_LOG:-}" ]] || cp apm.yml "$STUB_RERUN_LOG"
|
||||||
|
if [[ -n "${STUB_GIT_LOG:-}" ]]; then
|
||||||
|
cp .git/info/exclude "$STUB_GIT_LOG.exclude" 2> /dev/null || true
|
||||||
|
[[ ! -e .claude/worktrees ]] || touch "$STUB_GIT_LOG.worktrees"
|
||||||
|
fi
|
||||||
printf '%s\n' "${STUB_RERUN_OUTPUT-[*] All 15 check(s) passed}"
|
printf '%s\n' "${STUB_RERUN_OUTPUT-[*] All 15 check(s) passed}"
|
||||||
exit "${STUB_RERUN_RC:-0}"
|
exit "${STUB_RERUN_RC:-0}"
|
||||||
fi
|
fi
|
||||||
@@ -141,8 +147,58 @@ cmp -s "$TMP/apm.yml.orig" "$F/apm.yml" && [[ -z "$(git -C "$F" status --porcela
|
|||||||
&& pass "leaves the working tree's apm.yml byte-identical" || fail "apm.yml changed"
|
&& pass "leaves the working tree's apm.yml byte-identical" || fail "apm.yml changed"
|
||||||
tmp_clean && pass "removes the scratch copy" || fail "scratch left behind: $(ls -A "$TMPD")"
|
tmp_clean && pass "removes the scratch copy" || fail "scratch left behind: $(ls -A "$TMPD")"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "--- the re-run copy: carries info/exclude, leaves out .claude/worktrees ---"
|
||||||
|
F="$TMP/excl"
|
||||||
|
make_fixture "$F"
|
||||||
|
printf '%s\n' '# fixture marker' '**/.claude/worktrees/' >> "$F/.git/info/exclude"
|
||||||
|
mkdir -p "$F/.claude/worktrees/wt/.venv"
|
||||||
|
touch "$F/.claude/worktrees/wt/.venv/big"
|
||||||
|
run_audit "$F" "$(root_output "$SOLE" "" "$RTK_DETAIL")" STUB_GIT_LOG="$TMP/gitlog"
|
||||||
|
[[ $RC -eq 0 ]] && pass "still waived" || fail "exited $RC: $OUT"
|
||||||
|
cmp -s "$F/.git/info/exclude" "$TMP/gitlog.exclude" \
|
||||||
|
&& pass "the copy's .git/info/exclude is the repo's" || fail "info/exclude not carried into the copy"
|
||||||
|
[[ ! -e "$TMP/gitlog.worktrees" ]] && pass ".claude/worktrees is not copied" || fail ".claude/worktrees was copied"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "--- not waived: the reduction changes a line, not only deletes (deletions-only guard) ---"
|
||||||
|
F="$TMP/nonl"
|
||||||
|
make_fixture "$F"
|
||||||
|
# No trailing newline: awk prints one back, so the reduced manifest's last
|
||||||
|
# line differs from the original's, a change rather than a deletion.
|
||||||
|
printf '%s' "$(cat "$F/apm.yml")" > "$F/apm.yml.new" && mv "$F/apm.yml.new" "$F/apm.yml"
|
||||||
|
run_audit "$F" "$(root_output "$SOLE" "" "$RTK_DETAIL")"
|
||||||
|
[[ $RC -ne 0 ]] && ! grep -qF "waived ref-consistency" <<< "$OUT" \
|
||||||
|
&& grep -qF "changed more than the waived entries" <<< "$OUT" \
|
||||||
|
&& pass "fails when the reduced apm.yml differs by more than deletions" || fail "must fail (rc=$RC): $OUT"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "--- not waived: the reduction leaves an rtk entry in place ---"
|
||||||
|
F="$TMP/blank"
|
||||||
|
make_fixture "$F"
|
||||||
|
# A blank line inside the rtk item: dep_identity skips it and still finds the
|
||||||
|
# entry, but reduce_manifest ends the item there and keeps it whole.
|
||||||
|
sed -i '/# Routes Bash/{n;s|$|\n|}' "$F/apm.yml"
|
||||||
|
grep -qx '' "$F/apm.yml" || fail "fixture: no blank line in the rtk item"
|
||||||
|
run_audit "$F" "$(root_output "$SOLE" "" "$RTK_DETAIL")"
|
||||||
|
[[ $RC -ne 0 ]] && ! grep -qF "waived ref-consistency" <<< "$OUT" \
|
||||||
|
&& pass "fails when nothing was removed" || fail "must fail (rc=$RC): $OUT"
|
||||||
|
# A second, blank-split rtk item after a normal one: the normal one is
|
||||||
|
# removed, a pure deletion, so only the post-reduce dep_identity guard sees the
|
||||||
|
# entry that survived.
|
||||||
|
F="$TMP/dup"
|
||||||
|
make_fixture "$F"
|
||||||
|
awk -v e=" - git: https://$IDENTITY.git"$'\n\n'" path: plugins/rtk" \
|
||||||
|
'/^ mcp:/ { print e } { print }' "$F/apm.yml" > "$F/apm.yml.new"
|
||||||
|
mv "$F/apm.yml.new" "$F/apm.yml"
|
||||||
|
run_audit "$F" "$(root_output "$SOLE" "" "$RTK_DETAIL")"
|
||||||
|
[[ $RC -ne 0 ]] && ! grep -qF "waived ref-consistency" <<< "$OUT" \
|
||||||
|
&& grep -qF "could not remove plugins/rtk's entry" <<< "$OUT" \
|
||||||
|
&& pass "fails when an rtk entry survives a deletions-only reduction" || fail "must fail (rc=$RC): $OUT"
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "--- not waived: the full-set re-run fails ---"
|
echo "--- not waived: the full-set re-run fails ---"
|
||||||
|
F="$TMP/waived"
|
||||||
run_audit "$F" "$(root_output "$SOLE" "" "$RTK_DETAIL")" STUB_RERUN_RC=1 \
|
run_audit "$F" "$(root_output "$SOLE" "" "$RTK_DETAIL")" STUB_RERUN_RC=1 \
|
||||||
STUB_RERUN_OUTPUT="$(printf '%s\n' '| [x] | content-integrity | hidden Unicode |' '[x] 1 of 15 check(s) failed')"
|
STUB_RERUN_OUTPUT="$(printf '%s\n' '| [x] | content-integrity | hidden Unicode |' '[x] 1 of 15 check(s) failed')"
|
||||||
[[ $RC -ne 0 ]] && ! grep -qF "waived ref-consistency" <<< "$OUT" \
|
[[ $RC -ne 0 ]] && ! grep -qF "waived ref-consistency" <<< "$OUT" \
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ fail() { echo " FAIL: $1"; FAIL=$((FAIL + 1)); }
|
|||||||
|
|
||||||
[[ -f "$SRC" ]] || { echo "FAIL: $SRC does not exist"; exit 1; }
|
[[ -f "$SRC" ]] || { echo "FAIL: $SRC does not exist"; exit 1; }
|
||||||
REAL_RTK="$(command -v rtk || true)"
|
REAL_RTK="$(command -v rtk || true)"
|
||||||
TIMEOUT="$(command -v timeout)"
|
TIMEOUT="$(command -v timeout || true)"
|
||||||
|
[[ -n "$TIMEOUT" ]] || { echo "FAIL: timeout(1) is not on PATH; install coreutils to run these tests"; exit 1; }
|
||||||
|
|
||||||
WORK="$(mktemp -d)"
|
WORK="$(mktemp -d)"
|
||||||
trap 'rm -rf "$WORK"' EXIT
|
trap 'rm -rf "$WORK"' EXIT
|
||||||
@@ -105,6 +106,10 @@ else
|
|||||||
# so rtk passes it through with no output. A later rtk may add one.
|
# so rtk passes it through with no output. A later rtk may add one.
|
||||||
run "$HOOK" "$REAL_PATH" "echo hello"
|
run "$HOOK" "$REAL_PATH" "echo hello"
|
||||||
if [[ $RC -eq 0 && -z "$OUT" ]]; then pass; else fail "echo hello: want no output, got $RC: $OUT"; fi
|
if [[ $RC -eq 0 && -z "$OUT" ]]; then pass; else fail "echo hello: want no output, got $RC: $OUT"; fi
|
||||||
|
# Backs the README's "running both hooks is harmless": rtk leaves a command
|
||||||
|
# that already starts with rtk alone, so a second hook adds nothing.
|
||||||
|
run "$HOOK" "$REAL_PATH" "rtk git status"
|
||||||
|
if [[ $RC -eq 0 && -z "$OUT" ]]; then pass; else fail "rtk git status: want no output, got $RC: $OUT"; fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "== hooks.json"
|
echo "== hooks.json"
|
||||||
|
|||||||
Reference in new issue
Block a user