fix(gates): re-run the full root audit after the unlanded-plugin waiver
Why: on apm 0.39.3 a failing ref-consistency stops the root run after three checks, so while the unlanded-plugin waiver applied, the other twelve root checks (content-integrity, hook-approval-pins, local-bundle-hooks, exec-status-current, deployed-files-present, ...) never ran. Implementation notes: once the waiver's conditions hold, the hook copies the working tree (minus .git and .venv) into a mktemp dir. There it drops only the waived plugins' dependencies.apm items, checks the diff is deletions only, and runs git init with the same origin. It then runs apm audit --ci in the copy, and passes only on exit 0 with "All 15 check(s) passed". A copy was chosen over a trap-guarded in-place swap of apm.yml: it never writes the working tree, so the tree stays byte-identical even after SIGKILL. The plugin name must now start alphanumeric and contain no "..". Impact: tests cover a failing, short, or non-zero re-run; a one-of-three failure on another row; a duplicated details header; and dotted names. Each guard was mutation-checked. On this branch the re-run reports all 15 checks passing. Refs: #179 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
This commit is contained in:
1 parent
aaa73dddd3
commit
e14fca123d
3 files changed
+253
-11
No files matched your search
@@ -6,7 +6,10 @@
|
||||
# Same seam as tests/test-apm-gate-invocation.sh: a stub `apm`, reached through
|
||||
# the APM override so no uv or real apm runs. The stub prints canned `audit
|
||||
# --ci` output for the root manifest ($STUB_ROOT_OUTPUT, exit 1) and passes in
|
||||
# every plugin directory. The fixture is a throwaway git repo whose
|
||||
# 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
|
||||
# $STUB_RERUN_OUTPUT (default: the full root pass) with exit $STUB_RERUN_RC
|
||||
# (default 0). The fixture is a throwaway git repo whose
|
||||
# refs/remotes/origin/main is set with update-ref -- nothing is fetched.
|
||||
set -euo pipefail
|
||||
|
||||
@@ -32,8 +35,13 @@ if [[ "${1:-}" == --version ]]; then
|
||||
exit 0
|
||||
fi
|
||||
if [[ -f apm.lock.yaml.root-marker ]]; then
|
||||
printf '%s\n' "$STUB_ROOT_OUTPUT"
|
||||
exit 1
|
||||
if [[ "$PWD" != "$TMPDIR"/* ]]; then
|
||||
printf '%s\n' "$STUB_ROOT_OUTPUT"
|
||||
exit 1
|
||||
fi
|
||||
[[ -z "${STUB_RERUN_LOG:-}" ]] || cp apm.yml "$STUB_RERUN_LOG"
|
||||
printf '%s\n' "${STUB_RERUN_OUTPUT-[*] All 15 check(s) passed}"
|
||||
exit "${STUB_RERUN_RC:-0}"
|
||||
fi
|
||||
exit 0
|
||||
EOF
|
||||
@@ -93,10 +101,19 @@ EOF
|
||||
|
||||
RC=0
|
||||
OUT=""
|
||||
run_audit() { # <dir> <root output>
|
||||
# TMPDIR is a fresh per-run dir, so the re-run's scratch copy can be checked
|
||||
# for cleanup.
|
||||
TMPD="$TMP/tmpdir"
|
||||
run_audit() { # <dir> <root output> [VAR=value ...]
|
||||
local dir="$1" root="$2"
|
||||
shift 2
|
||||
RC=0
|
||||
OUT="$(cd "$1" && env APM="$BIN/apm" STUB_ROOT_OUTPUT="$2" bash "$AUDIT" 2>&1)" || RC=$?
|
||||
rm -rf "$TMPD"
|
||||
mkdir -p "$TMPD"
|
||||
OUT="$(cd "$dir" && env APM="$BIN/apm" STUB_ROOT_OUTPUT="$root" TMPDIR="$TMPD" "$@" \
|
||||
bash "$AUDIT" 2>&1)" || RC=$?
|
||||
}
|
||||
tmp_clean() { [[ -z "$(ls -A "$TMPD")" ]]; }
|
||||
|
||||
WAIVER_LINE='apm audit --ci: waived ref-consistency for plugins/rtk (not yet on origin/main; ADR-0019)'
|
||||
SOLE='[x] 1 of 3 check(s) failed'
|
||||
@@ -105,9 +122,43 @@ RTK_DETAIL="$IDENTITY/plugins/rtk: not found in lockfile"
|
||||
echo "--- waived: one plugin not yet on origin/main ---"
|
||||
F="$TMP/waived"
|
||||
make_fixture "$F"
|
||||
run_audit "$F" "$(root_output "$SOLE" "" "$RTK_DETAIL")"
|
||||
cp "$F/apm.yml" "$TMP/apm.yml.orig"
|
||||
run_audit "$F" "$(root_output "$SOLE" "" "$RTK_DETAIL")" STUB_RERUN_LOG="$TMP/rerun.yml"
|
||||
[[ $RC -eq 0 ]] && pass "exits 0" || fail "exited $RC: $OUT"
|
||||
grep -qxF "$WAIVER_LINE" <<< "$OUT" && pass "prints the waiver line" || fail "no waiver line: $OUT"
|
||||
grep -qxF 'apm audit --ci: root re-run without the unlanded plugins: All 15 check(s) passed' <<< "$OUT" \
|
||||
&& pass "reports the full-set re-run" || fail "no re-run line: $OUT"
|
||||
# The re-run's manifest is the original minus exactly the rtk item.
|
||||
if [[ -f "$TMP/rerun.yml" ]] && diff "$TMP/apm.yml.orig" "$TMP/rerun.yml" > "$TMP/rerun.diff"; then
|
||||
fail "the re-run saw an unreduced apm.yml"
|
||||
elif [[ "$(cat "$TMP/rerun.diff" 2>/dev/null)" == "$(printf '%s\n' '7,8d6' \
|
||||
"< - git: https://$IDENTITY.git" '< path: plugins/rtk')" ]]; then
|
||||
pass "the re-run's apm.yml drops only the plugins/rtk entry"
|
||||
else
|
||||
fail "unexpected re-run manifest: $(cat "$TMP/rerun.diff" 2>/dev/null)"
|
||||
fi
|
||||
cmp -s "$TMP/apm.yml.orig" "$F/apm.yml" && [[ -z "$(git -C "$F" status --porcelain -- apm.yml)" ]] \
|
||||
&& 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")"
|
||||
|
||||
echo ""
|
||||
echo "--- not waived: the full-set re-run fails ---"
|
||||
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')"
|
||||
[[ $RC -ne 0 ]] && ! grep -qF "waived ref-consistency" <<< "$OUT" \
|
||||
&& grep -qF "content-integrity" <<< "$OUT" \
|
||||
&& pass "fails, showing the re-run's failing check" || fail "must fail (rc=$RC): $OUT"
|
||||
cmp -s "$TMP/apm.yml.orig" "$F/apm.yml" && pass "apm.yml still byte-identical" || fail "apm.yml changed"
|
||||
tmp_clean && pass "removes the scratch copy on failure too" || fail "scratch left behind: $(ls -A "$TMPD")"
|
||||
run_audit "$F" "$(root_output "$SOLE" "" "$RTK_DETAIL")" STUB_RERUN_RC=1
|
||||
[[ $RC -ne 0 ]] && ! grep -qF "waived ref-consistency" <<< "$OUT" \
|
||||
&& pass "fails when the re-run exits non-zero despite a passing summary" || fail "must fail (rc=$RC): $OUT"
|
||||
run_audit "$F" "$(root_output "$SOLE" "" "$RTK_DETAIL")" STUB_RERUN_OUTPUT='[*] All 14 check(s) passed'
|
||||
[[ $RC -ne 0 ]] && ! grep -qF "waived ref-consistency" <<< "$OUT" \
|
||||
&& pass "fails when the re-run runs fewer than the full set" || fail "must fail (rc=$RC): $OUT"
|
||||
run_audit "$F" "$(root_output "$SOLE" "" "$RTK_DETAIL")" STUB_RERUN_OUTPUT=''
|
||||
[[ $RC -ne 0 ]] && ! grep -qF "waived ref-consistency" <<< "$OUT" \
|
||||
&& pass "fails when the re-run prints no summary" || fail "must fail (rc=$RC): $OUT"
|
||||
|
||||
echo ""
|
||||
echo "--- not waived: the plugin is already on origin/main ---"
|
||||
@@ -129,6 +180,47 @@ run_audit "$F" "$(root_output '[x] 2 of 3 check(s) failed' \
|
||||
[[ $RC -ne 0 ]] && ! grep -qF "waived ref-consistency" <<< "$OUT" \
|
||||
&& pass "fails when drift fails too" || fail "must fail (rc=$RC): $OUT"
|
||||
|
||||
echo ""
|
||||
echo "--- not waived: one of three fails, but it is not ref-consistency ---"
|
||||
F="$TMP/otherrow"
|
||||
make_fixture "$F"
|
||||
run_audit "$F" "$(root_output "$SOLE" \
|
||||
'| [x] | drift | 1 file(s) differ |' "$RTK_DETAIL" |
|
||||
sed 's/^| \[x\] | ref-consistency/| [+] | ref-consistency/')"
|
||||
[[ $RC -ne 0 ]] && ! grep -qF "waived ref-consistency" <<< "$OUT" \
|
||||
&& pass "fails when the sole failing row is drift" || fail "must fail (rc=$RC): $OUT"
|
||||
|
||||
echo ""
|
||||
echo "--- not waived: a duplicated details header ---"
|
||||
F="$TMP/duphdr"
|
||||
make_fixture "$F"
|
||||
run_audit "$F" "$(root_output "$SOLE" "" "$RTK_DETAIL"
|
||||
printf '%s\n' '' ' ref-consistency details:' ' - github.com/acme/skills: not found in lockfile')"
|
||||
[[ $RC -ne 0 ]] && ! grep -qF "waived ref-consistency" <<< "$OUT" \
|
||||
&& pass "fails when a second details block could hide a detail" || fail "must fail (rc=$RC): $OUT"
|
||||
|
||||
echo ""
|
||||
echo "--- not waived: a plugin name that is . or .., or holds .. ---"
|
||||
F="$TMP/dotnames"
|
||||
make_fixture "$F"
|
||||
# Each entry goes inside the apm: list, above ` mcp: []`, so dep_identity
|
||||
# finds it and only the name guards stand between it and a waiver.
|
||||
for n in .. . .hidden a..b; do
|
||||
awk -v e=" - git: https://$IDENTITY.git"$'\n'" path: plugins/$n" \
|
||||
'/^ mcp:/ { print e } { print }' "$F/apm.yml" > "$F/apm.yml.new"
|
||||
mv "$F/apm.yml.new" "$F/apm.yml"
|
||||
mkdir -p "$F/plugins/$n"
|
||||
[[ -f "$F/plugins/$n/apm.yml" ]] || printf 'name: x\n' > "$F/plugins/$n/apm.yml"
|
||||
done
|
||||
for n in .. . .hidden; do
|
||||
run_audit "$F" "$(root_output "$SOLE" "" "$IDENTITY/plugins/$n: not found in lockfile")"
|
||||
[[ $RC -ne 0 ]] && grep -qF "unrecognised detail line" <<< "$OUT" \
|
||||
&& pass "fails on plugins/$n" || fail "must fail on plugins/$n (rc=$RC): $OUT"
|
||||
done
|
||||
run_audit "$F" "$(root_output "$SOLE" "" "$IDENTITY/plugins/a..b: not found in lockfile")"
|
||||
[[ $RC -ne 0 ]] && grep -qF "contains '..'" <<< "$OUT" \
|
||||
&& pass "fails on plugins/a..b" || fail "must fail on plugins/a..b (rc=$RC): $OUT"
|
||||
|
||||
echo ""
|
||||
echo "--- not waived: a mismatch outside plugins/ ---"
|
||||
F="$TMP/nonplugin"
|
||||
|
||||
Reference in new issue
Block a user