fix(scripts): use one whole-history first landing for release tags

Why: the untagged-run branch looked for an earlier run of a version only
from the start of the wanted range, while tag validation used the first
landing across all history. After a backfill, a revert to a pre-backfill
version was tagged on the revert commit, and the next dry run reported
that tag as a later landing: exit 2, blocking --apply for every plugin.

Implementation Notes:
- first_run() returns the first valid run of a version over the whole
  first-parent history; tag validation, the tagged-elsewhere check, the
  backfill start and the untagged-run check all use it.
- An untagged version whose first landing lies before the wanted range
  reports RELEASED with a "before the tagged range; not tagged" note; no
  tag is created and the exit code is unaffected.
- Preflight rejects a plugin name whose tag git check-ref-format refuses
  (e.g. a..b, a*) before any history is read, so a glob character never
  reaches a pathspec or ref pattern; tags are listed once and filtered by
  exact prefix instead of a for-each-ref glob.
- git rev-list failure and an empty run list now exit 2 with a FAIL
  message instead of being read as no history or crashing.
- The error footer addresses agents (stop and report, AGENTS.md) and the
  maintainer (fix by hand, ADR-0033) separately.

Impact: ADR-0033 defines first landing precisely, documents the preflight,
and documents the maintainer escape from an INVALID run (hand-cut tag on
the next valid version; --apply stays all-or-nothing). New tests cover the
revert repro, a backfill range holding a pre-range version, the INVALID
escape, rev-list failure/empty history, a glob plugin name, and the footer.

Refs: #223
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-11-27 19:25:16 +00:00
1 parent 0a52c8597d
commit 62650543ec
3 files changed
+219 -52

No files matched your search

+105
View File
@@ -135,6 +135,8 @@ run "$R" --ref main
expect_rc "lightweight tag" 2
expect_row "row is ERROR" delta 2.0.0 "$BUMP" ERROR
if grep -q "lightweight" <<< "$OUT"; then pass "message names lightweight"; else fail "no lightweight message"; fi
if grep -q "^Agents: stop and report this to the maintainer" <<< "$OUT"; then pass "footer tells agents to stop and report"; else fail "no agent footer"; fi
if grep -q "^Maintainer: tags are immutable" <<< "$OUT"; then pass "footer addresses the maintainer"; else fail "no maintainer footer"; fi
echo "Case 5: annotated tag on the wrong commit is an ERROR"
(cd "$R" && git tag -d delta-v2.0.0 > /dev/null && git tag -a delta-v2.0.0 -m x "$EDIT")
@@ -478,6 +480,109 @@ expect_rc "--plugin git --plugin git --apply" 0
if [[ "$(git -C "$R" tag -l)" == "git-v1.0.0" ]]; then pass "one tag created"; else fail "wrong tags: $(git -C "$R" tag -l | tr '\n' ' ')"; fi
if grep -qx "git push origin git-v1.0.0" <<< "$OUT"; then pass "push line names the tag once"; else fail "push line wrong"; echo "$OUT" | sed 's/^/ /'; fi
echo "Case 12t: a revert to a version from before the tagged range is RELEASED, never tagged"
R="$(new_repo)"
write_apm "$R" rv 1.0.0; commit "$R" a; RV1="$(head_sha "$R")"
write_apm "$R" rv 1.1.0; commit "$R" b; RV2="$(head_sha "$R")"
sync_origin "$R"
run "$R" --ref main --apply
expect_rc "backfill --apply tags the current version only" 0
if [[ "$(git -C "$R" tag -l)" == "rv-v1.1.0" ]]; then pass "only rv-v1.1.0 backfilled"; else fail "wrong tags: $(git -C "$R" tag -l | tr '\n' ' ')"; fi
write_apm "$R" rv 1.0.0; commit "$R" revert; RV3="$(head_sha "$R")"
write_apm "$R" rv 1.2.0; commit "$R" c; RV4="$(head_sha "$R")"
sync_origin "$R"
run "$R" --ref main
expect_rc "dry run: only the new bump is missing" 1
expect_row "backfilled 1.1.0 OK" rv 1.1.0 "$RV2" OK
expect_row "revert to pre-backfill 1.0.0 is RELEASED" rv 1.0.0 "$RV3" RELEASED
expect_row "new bump 1.2.0 MISSING" rv 1.2.0 "$RV4" MISSING
if grep -q "first landed at ${RV1:0:7}, before the tagged range; not tagged" <<< "$OUT"; then pass "note names the pre-range first landing"; else fail "no pre-range note"; echo "$OUT" | sed 's/^/ /'; fi
run "$R" --ref main --apply
expect_rc "--apply after the revert" 0
if [[ "$(git -C "$R" tag -l | tr '\n' ' ')" == "rv-v1.1.0 rv-v1.2.0 " ]]; then pass "rv-v1.2.0 created, no rv-v1.0.0"; else fail "wrong tags: $(git -C "$R" tag -l | tr '\n' ' ')"; fi
run "$R" --ref main
expect_rc "dry run after --apply is clean, never 2" 0
echo "Case 12t2: backfill whose range holds a version that first landed before it"
R="$(new_repo)"
write_apm "$R" rw 1.0.0; commit "$R" a; RW1="$(head_sha "$R")"
write_apm "$R" rw 1.1.0; commit "$R" b; RW2="$(head_sha "$R")"
write_apm "$R" rw 1.0.0; commit "$R" c; RW3="$(head_sha "$R")"
write_apm "$R" rw 1.1.0; commit "$R" d; RW4="$(head_sha "$R")"
sync_origin "$R"
run "$R" --ref main
expect_rc "backfill dry run" 1
expect_row "current version MISSING at its first landing" rw 1.1.0 "$RW2" MISSING
expect_row "1.0.0 inside the range is RELEASED" rw 1.0.0 "$RW3" RELEASED
expect_row "current version's later run RELEASED" rw 1.1.0 "$RW4" RELEASED
if ! grep -q "${RW1:0:7} " <<< "$(grep '^rw ' <<< "$OUT")"; then pass "pre-range landing is not a row"; else fail "pre-range landing listed"; fi
run "$R" --ref main --apply
expect_rc "backfill --apply" 0
if [[ "$(git -C "$R" tag -l)" == "rw-v1.1.0" ]]; then pass "only rw-v1.1.0 created"; else fail "wrong tags: $(git -C "$R" tag -l | tr '\n' ' ')"; fi
run "$R" --ref main
expect_rc "dry run after backfill" 0
echo "Case 12e2: the escape from an INVALID run is a hand-cut tag on the next valid version"
R="$(new_repo)"
write_apm "$R" om 1.0.0; commit "$R" a; OM1="$(head_sha "$R")"
write_apm "$R" om 1.1; commit "$R" b
write_apm "$R" om 1.2.0; commit "$R" c; OM3="$(head_sha "$R")"
write_apm "$R" om 1.3.0; commit "$R" d; OM4="$(head_sha "$R")"
write_apm "$R" op 1.0.0; commit "$R" e
(cd "$R" && git tag -a om-v1.0.0 -m x "$OM1")
sync_origin "$R"
run "$R" --ref main --apply
expect_rc "INVALID run blocks --apply for every plugin" 2
if [[ "$(git -C "$R" tag -l)" == "om-v1.0.0" ]]; then pass "nothing created, not even the other plugin's tag"; else fail "tags created: $(git -C "$R" tag -l | tr '\n' ' ')"; fi
(cd "$R" && git tag -a om-v1.2.0 -m "om 1.2.0" "$OM3")
run "$R" --ref main
expect_rc "after the hand-cut tag, only missing tags remain" 1
expect_rows "invalid run no longer wanted" om 2
expect_row "hand-cut start point OK" om 1.2.0 "$OM3" OK
expect_row "next version MISSING" om 1.3.0 "$OM4" MISSING
echo "Case 12u: a git rev-list failure or an empty history exits 2, not a crash"
R="$(new_repo)"
write_apm "$R" rl 1.0.0; commit "$R" a
W="$(mktemp -d)"; CLEANUP_DIRS+=("$W")
REAL_GIT="$(command -v git)"
cat > "$W/git" <<EOF
#!/usr/bin/env bash
if [[ "\$1" == rev-list && " \$* " == *" --reverse "* ]]; then
case "\${FAKE_REVLIST:-}" in
fail) echo "fatal: simulated rev-list failure" >&2; exit 128 ;;
empty) exit 0 ;;
esac
fi
exec "$REAL_GIT" "\$@"
EOF
chmod +x "$W/git"
RC=0; OUT="$(cd "$R" && PATH="$W:$PATH" FAKE_REVLIST=fail bash "$SCRIPT" --ref main 2>&1)" || RC=$?
expect_rc "rev-list failure" 2
if grep -q "git rev-list could not read plugins/rl/apm.yml" <<< "$OUT"; then pass "message names the rev-list failure"; else fail "no rev-list message"; echo "$OUT" | sed 's/^/ /'; fi
RC=0; OUT="$(cd "$R" && PATH="$W:$PATH" FAKE_REVLIST=empty bash "$SCRIPT" --ref main 2>&1)" || RC=$?
expect_rc "no commit carries apm.yml" 2
if grep -q "no commit on its first-parent history carries it" <<< "$OUT"; then pass "message names the empty history"; else fail "no empty-history message"; echo "$OUT" | sed 's/^/ /'; fi
if ! grep -q "unbound\|bad array subscript" <<< "$OUT"; then pass "no shell crash"; else fail "shell crashed"; fi
echo "Case 12v: a glob character in a plugin name is rejected before any pathspec or ref pattern"
R="$(new_repo)"
write_apm "$R" ab 1.0.0; commit "$R" a; AB1="$(head_sha "$R")"
write_apm "$R" "a*" 1.0.0; commit "$R" b
write_apm "$R" ab 1.1.0; commit "$R" c; AB3="$(head_sha "$R")"
(cd "$R" && git tag -a ab-v1.0.0 -m x "$AB1")
sync_origin "$R"
run "$R" --ref main --apply
expect_rc "plugin 'a*' is rejected" 2
if grep -q "plugins/a\*: 'a\*-v<version>' is not a valid tag name (git check-ref-format)" <<< "$OUT"; then pass "message names a* and check-ref-format"; else fail "no preflight message"; echo "$OUT" | sed 's/^/ /'; fi
if ! grep -q "^PLUGIN " <<< "$OUT"; then pass "rejected before any history is read (no table)"; else fail "table printed"; fi
if [[ "$(git -C "$R" tag -l)" == "ab-v1.0.0" ]]; then pass "nothing created"; else fail "tags created: $(git -C "$R" tag -l | tr '\n' ' ')"; fi
run "$R" --ref main --plugin ab
expect_rc "ab alone is unaffected by its glob-named neighbour" 1
expect_rows "ab rows only" ab 2
expect_row "ab 1.0.0 OK" ab 1.0.0 "$AB1" OK
expect_row "ab 1.1.0 MISSING" ab 1.1.0 "$AB3" MISSING
echo "Case 12p: expect_row matches a version's dots literally"
OUT="zz 1x0x0 abcdef0 OK"
if ! grep -Eq "^zz +$(ere_quote 1.0.0) +abcdef0 +OK\$" <<< "$OUT"; then pass "1.0.0 does not match 1x0x0"; else fail "unescaped dots"; fi