feat(gates): waive ref-consistency for a plugin not yet on origin/main
A first-landing hook- or bin-shipping plugin could not be pushed. check-executables-allow-sync requires its git+path entry in root apm.yml, but root dependencies resolve from the remote's main (ADR-0019), so the lock cannot record the plugin until it lands and root `apm audit --ci` fails ref-consistency with `<identity>/plugins/<name>: not found in lockfile`. No state of the branch satisfied both gates. scripts/apm-audit-ci.sh now waives the root audit only when the sole failure is ref-consistency (`1 of 3 check(s) failed`, as apm 0.39.3 prints it), every detail line is that form for the identity root apm.yml's own git+path entry yields, plugins/<name>/apm.yml exists in the working tree, and the plugin is absent from the local origin/main. No fetch; a missing origin/main or unrecognised output fails closed. The waiver lapses for a plugin once it is on origin/main, when the follow-up lock PR must record it. 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
cc1d396d47
commit
aaa73dddd3
4 files changed
+328
-4
No files matched your search
+126
-2
@@ -47,7 +47,8 @@
|
||||
# discarded precisely where it earns its keep.
|
||||
#
|
||||
# The waiver is therefore narrow on three axes, and fails closed on each:
|
||||
# 1. the root manifest is never waived, whatever it reports
|
||||
# 1. the root manifest is never waived for it (the root's own, separate
|
||||
# waiver is described below)
|
||||
# 2. the failing check must be `lockfile-exists` and no other -- the
|
||||
# "1 of 1 check(s) failed" assertion is what makes that true, since any
|
||||
# second failing check changes the count and the run fails normally
|
||||
@@ -57,6 +58,33 @@
|
||||
# line silently turns the waiver off, which fails the push rather than hiding a
|
||||
# defect. If that happens, re-verify against the new output and update the two
|
||||
# patterns below rather than widening them.
|
||||
#
|
||||
# THE SECOND WAIVER: A PLUGIN NOT YET ON origin/main (ROOT MANIFEST ONLY)
|
||||
#
|
||||
# Root apm.yml's first-party dependencies resolve from the remote's `main`
|
||||
# (ADR-0019), so the lock cannot record a plugin until that plugin has landed.
|
||||
# check-executables-allow-sync.sh meanwhile requires a hook- or bin-shipping
|
||||
# plugin to have its git+path entry in root apm.yml before it can be pushed at
|
||||
# all. Together they make a first-landing executable-shipping plugin
|
||||
# unpushable: the entry is mandatory, and the root `ref-consistency` check then
|
||||
# fails it as `<identity>/plugins/<name>: not found in lockfile`. Verified on
|
||||
# apm 0.39.3 (#179): a failing ref-consistency cuts the root run short at three
|
||||
# checks (lockfile-exists, ref-consistency, drift), so the sole-failure line is
|
||||
# `1 of 3 check(s) failed`.
|
||||
#
|
||||
# So the root manifest's audit is waived when, and only when, ALL of these hold:
|
||||
# 1. the failure count is exactly "1 of 3 check(s) failed" and the one
|
||||
# failing row is ref-consistency -- any second failure changes the count
|
||||
# 2. the ref-consistency details block exists and EVERY line in it reads
|
||||
# `<identity>/plugins/<name>: not found in lockfile`, where <identity> is
|
||||
# the one root apm.yml's own git+path entry for plugins/<name> yields,
|
||||
# derived by check-executables-allow-sync.sh's rule
|
||||
# 3. plugins/<name>/apm.yml exists in the working tree
|
||||
# 4. plugins/<name>/apm.yml is absent from the LOCAL origin/main ref -- no
|
||||
# fetch, the hook stays offline -- and origin/main must resolve
|
||||
# Anything else, including output in a shape not recognised here, fails the
|
||||
# push. The waiver lapses for a plugin by itself: once it is on origin/main,
|
||||
# condition 4 is false and the follow-up lock PR has to record it.
|
||||
|
||||
set -uo pipefail
|
||||
|
||||
@@ -74,6 +102,92 @@ require_apm_version || exit 1
|
||||
|
||||
readonly WAIVED_CHECK='declares dependencies but apm.lock.yaml is absent'
|
||||
readonly SOLE_FAILURE='1 of 1 check(s) failed'
|
||||
readonly REF_SOLE_FAILURE='1 of 3 check(s) failed'
|
||||
readonly REF_FAILED_ROW='^\| \[x\] +\| ref-consistency +\|'
|
||||
readonly REF_DETAILS_HEADER=' ref-consistency details:'
|
||||
readonly REF_DETAIL='^ - (.+)/plugins/([A-Za-z0-9._-]+): not found in lockfile$'
|
||||
|
||||
# dep_identity <plugin dir name> -- the identity root apm.yml's git+path entry
|
||||
# for plugins/<name> yields: <host>/<owner>/<repo>/plugins/<name>. The URL rule
|
||||
# is check-executables-allow-sync.sh's identity(): drop the scheme (or turn an
|
||||
# scp-like host:path into host/path), any user@, a trailing / and .git. Empty
|
||||
# when there is no such entry. A line scan of the one shape root apm.yml uses
|
||||
# (`dependencies:` > `apm:` > `- git:` / `path:` items), not a YAML parse: an
|
||||
# entry in any other shape yields nothing, and so fails closed.
|
||||
dep_identity() {
|
||||
local want="plugins/$1" url
|
||||
url="$(awk -v want="$want" '
|
||||
function unq(v) {
|
||||
sub(/^[ \t]+/, "", v); sub(/[ \t]+$/, "", v)
|
||||
if (v ~ /^".*"$/ || v ~ /^\047.*\047$/) v = substr(v, 2, length(v) - 2)
|
||||
return v
|
||||
}
|
||||
function flush() { if (g != "" && p == want) print g; g = ""; p = "" }
|
||||
/^[ \t]*(#|$)/ { next }
|
||||
/^[^ ]/ { flush(); in_deps = ($0 ~ /^dependencies:/); in_apm = 0; next }
|
||||
!in_deps { next }
|
||||
/^ [^ ]/ { flush(); in_apm = ($0 ~ /^ apm:/); next }
|
||||
!in_apm { next }
|
||||
/^ - / { flush(); sub(/^ - /, " ") }
|
||||
/^ git:/ { v = $0; sub(/^ git:/, "", v); g = unq(v); next }
|
||||
/^ path:/ { v = $0; sub(/^ path:/, "", v); p = unq(v); sub(/^\.\//, "", p); sub(/\/$/, "", p); next }
|
||||
END { flush() }
|
||||
' apm.yml 2>/dev/null | head -n 1)"
|
||||
[ -n "$url" ] || return 0
|
||||
if [[ "$url" == *://* ]]; then
|
||||
url="${url#*://}"
|
||||
elif [[ "$url" == *:* ]]; then
|
||||
url="${url/://}"
|
||||
fi
|
||||
url="${url#*@}"
|
||||
url="${url%/}"
|
||||
url="${url%.git}"
|
||||
printf '%s/%s' "$url" "$want"
|
||||
}
|
||||
|
||||
# ref_waivable <audit output> -- succeeds, printing each waived plugin dir name
|
||||
# on its own line, only when the root output is exactly the unlanded-plugin
|
||||
# ref-consistency failure described in the header. Otherwise prints why on
|
||||
# stderr and fails.
|
||||
ref_waivable() {
|
||||
local output="$1" details line identity name names=""
|
||||
grep -qF "$REF_SOLE_FAILURE" <<<"$output" || return 1
|
||||
grep -qE "$REF_FAILED_ROW" <<<"$output" || return 1
|
||||
[ "$(grep -cxF "$REF_DETAILS_HEADER" <<<"$output")" -eq 1 ] || return 1
|
||||
# The details block: every line after the header up to the first blank one.
|
||||
details="$(awk -v h="$REF_DETAILS_HEADER" '
|
||||
$0 == h { on = 1; next }
|
||||
on && /^[ \t]*$/ { exit }
|
||||
on { print }
|
||||
' <<<"$output")"
|
||||
[ -n "$details" ] || return 1
|
||||
if ! git rev-parse --verify --quiet 'origin/main^{commit}' >/dev/null; then
|
||||
echo 'apm audit --ci: ref-consistency not waived: origin/main does not resolve locally, so whether a plugin has landed is unknown' >&2
|
||||
return 1
|
||||
fi
|
||||
while IFS= read -r line; do
|
||||
if [[ ! "$line" =~ $REF_DETAIL ]]; then
|
||||
echo "apm audit --ci: ref-consistency not waived: unrecognised detail line: $line" >&2
|
||||
return 1
|
||||
fi
|
||||
identity="${BASH_REMATCH[1]}"
|
||||
name="${BASH_REMATCH[2]}"
|
||||
if [ "$identity/plugins/$name" != "$(dep_identity "$name")" ]; then
|
||||
echo "apm audit --ci: ref-consistency not waived: $identity/plugins/$name is not root apm.yml's git+path entry for plugins/$name" >&2
|
||||
return 1
|
||||
fi
|
||||
if [ ! -f "plugins/$name/apm.yml" ]; then
|
||||
echo "apm audit --ci: ref-consistency not waived: plugins/$name/apm.yml is not in the working tree" >&2
|
||||
return 1
|
||||
fi
|
||||
if git cat-file -e "origin/main:plugins/$name/apm.yml" 2>/dev/null; then
|
||||
echo "apm audit --ci: ref-consistency not waived: plugins/$name is already on origin/main, so the lock must record it" >&2
|
||||
return 1
|
||||
fi
|
||||
names+="$name"$'\n'
|
||||
done <<<"$details"
|
||||
printf '%s' "$names"
|
||||
}
|
||||
|
||||
status=0
|
||||
|
||||
@@ -85,7 +199,17 @@ for manifest_dir in . plugins/*/; do
|
||||
continue
|
||||
fi
|
||||
|
||||
# Axis 1: the root is never waived.
|
||||
# The root's one waiver: plugins not yet on origin/main (header, second
|
||||
# waiver).
|
||||
if [ "$manifest_dir" = "." ] && waived="$(ref_waivable "$output")"; then
|
||||
while IFS= read -r name; do
|
||||
printf 'apm audit --ci: waived ref-consistency for plugins/%s (not yet on origin/main; ADR-0019)\n' \
|
||||
"$name"
|
||||
done <<<"$waived"
|
||||
continue
|
||||
fi
|
||||
|
||||
# Axis 1: the root is never waived for lockfile-exists.
|
||||
# Here-strings, not `printf ... | grep -q`: under `set -o pipefail` grep -q
|
||||
# exits on its first match, SIGPIPEs the writer, and the writer's death
|
||||
# becomes the pipeline's status -- a race tests/test-no-pipefail-early-exit-grep.sh
|
||||
|
||||
Reference in new issue
Block a user