fix(scripts): release a recurring version once, at its first landing

A reverted bump left a run whose tag peeled to an earlier landing, which the
script reported as ERROR. Because --apply is all-or-nothing, that ERROR stayed
in the wanted set forever and blocked every other plugin's tag.

A version is now released once, at its first landing. A run whose tag peels to
an earlier run of the same version, or whose untagged version already appears
earlier in the wanted set, reports RELEASED with a note and never blocks other
rows. A tag on no landing of its version remains ERROR.

Also: preflight every new tag name with git check-ref-format; report the tags
already created, with their push line, and exit 2 if git tag fails mid-run;
reject whitespace in apm.yml name and version. New tests cover the revert,
in-set repeats, delete and re-add, an off-history tag, an invalid version in the
wanted set, origin/main default resolution, and --apply with --plugin and --ref.

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 17:55:47 +00:00
1 parent 8b54a60fc8
commit f677698887
2 files changed
+215 -33

No files matched your search

+136 -6
View File
@@ -209,16 +209,146 @@ run "$R" --ref main --apply
expect_rc "ERROR blocks --apply" 2
if [[ -z "$(git -C "$R" tag -l 'theta-v*')" ]]; then pass "nothing created for the clean plugin"; else fail "theta tag created despite ERROR"; fi
echo "Case 12: version recurring inside the wanted set is an ERROR"
echo "Case 12: untagged version recurring inside the wanted set is tagged at its first landing"
R="$(new_repo)"
write_apm "$R" kappa 0.9.0; commit "$R" a; K0="$(head_sha "$R")"
write_apm "$R" kappa 1.0.0; commit "$R" b
write_apm "$R" kappa 1.1.0; commit "$R" c
write_apm "$R" kappa 1.0.0; commit "$R" d
write_apm "$R" kappa 1.0.0; commit "$R" b; KB="$(head_sha "$R")"
write_apm "$R" kappa 1.1.0; commit "$R" c; KC="$(head_sha "$R")"
write_apm "$R" kappa 1.0.0; commit "$R" d; KD="$(head_sha "$R")"
(cd "$R" && git tag -a kappa-v0.9.0 -m x "$K0")
run "$R" --ref main
expect_rc "recurring version" 2
if grep -q "recurs" <<< "$OUT"; then pass "message names the recurrence"; else fail "no recurrence message"; fi
expect_rc "recurring version is not an error" 1
expect_row "first landing of 1.0.0 is MISSING" kappa 1.0.0 "$KB" MISSING
expect_row "later landing of 1.0.0 is RELEASED" kappa 1.0.0 "$KD" RELEASED
expect_row "1.1.0 MISSING" kappa 1.1.0 "$KC" MISSING
if grep -q "first landing ${KB:0:7}" <<< "$OUT"; then pass "note names the first landing"; else fail "no first-landing note"; fi
run "$R" --ref main --apply
expect_rc "--apply with a recurring version" 0
if [[ "$(git -C "$R" rev-parse "kappa-v1.0.0^{commit}" 2>/dev/null)" == "$KB" ]]; then pass "kappa-v1.0.0 cut at the first landing"; else fail "kappa-v1.0.0 not on the first landing"; fi
run "$R" --ref main
expect_rc "dry run after --apply" 0
expect_row "later landing RELEASED via the tag" kappa 1.0.0 "$KD" RELEASED
if grep -q "already released at ${KB:0:7}" <<< "$OUT"; then pass "note names where it was released"; else fail "no already-released note"; fi
echo "Case 12b: a revert after tagging does not wedge other plugins"
R="$(new_repo)"
write_apm "$R" aa 1.0.0; write_apm "$R" bb 1.0.0; commit "$R" a; A1="$(head_sha "$R")"
write_apm "$R" aa 1.1.0; commit "$R" b; A2="$(head_sha "$R")"
(cd "$R" && git tag -a aa-v1.0.0 -m x "$A1" && git tag -a aa-v1.1.0 -m x "$A2" && git tag -a bb-v1.0.0 -m x "$A1")
write_apm "$R" aa 1.0.0; commit "$R" revert; A3="$(head_sha "$R")"
write_apm "$R" bb 1.2.0; commit "$R" c; B2="$(head_sha "$R")"
run "$R" --ref main
expect_rc "dry run: only bb is missing" 1
expect_row "aa 1.1.0 OK" aa 1.1.0 "$A2" OK
expect_row "reverted aa 1.0.0 is RELEASED" aa 1.0.0 "$A3" RELEASED
expect_row "bb 1.2.0 MISSING" bb 1.2.0 "$B2" MISSING
run "$R" --ref main --apply
expect_rc "--apply after a revert" 0
if [[ "$(git -C "$R" rev-parse "bb-v1.2.0^{commit}" 2>/dev/null)" == "$B2" ]]; then pass "bb-v1.2.0 created"; else fail "bb-v1.2.0 not created"; fi
if [[ "$(git -C "$R" rev-parse "aa-v1.0.0^{commit}")" == "$A1" ]]; then pass "aa-v1.0.0 left where it was"; else fail "aa-v1.0.0 moved"; fi
if grep -qx "git push origin bb-v1.2.0" <<< "$OUT"; then pass "push line names only bb-v1.2.0"; else fail "push line wrong"; echo "$OUT" | sed 's/^/ /'; fi
echo "Case 12c: a tag on no landing of its version stays an ERROR"
(cd "$R" && git tag -d aa-v1.0.0 > /dev/null && git tag -a aa-v1.0.0 -m x "$A2")
run "$R" --ref main
expect_rc "tag on another version's landing" 2
expect_row "row is ERROR" aa 1.0.0 "$A3" ERROR
echo "Case 12d: apm.yml deleted and re-added starts a new run"
R="$(new_repo)"
write_apm "$R" nu 1.0.0; write_apm "$R" xi 1.0.0; commit "$R" a; N1="$(head_sha "$R")"
rm -r "$R/plugins/nu"; commit "$R" delete
write_apm "$R" nu 1.0.0; commit "$R" readd; N3="$(head_sha "$R")"
run "$R" --ref main --plugin nu
expect_rows "untagged: one wanted row" nu 1
expect_row "untagged: target is the re-add" nu 1.0.0 "$N3" MISSING
(cd "$R" && git tag -a nu-v1.0.0 -m x "$N1")
run "$R" --ref main --plugin nu
expect_rc "tagged before the delete" 0
expect_row "original landing OK" nu 1.0.0 "$N1" OK
expect_row "re-added landing RELEASED" nu 1.0.0 "$N3" RELEASED
echo "Case 12e: invalid version inside the wanted set is an ERROR"
R="$(new_repo)"
write_apm "$R" omi 1.0.0; commit "$R" a; O1="$(head_sha "$R")"
write_apm "$R" omi 1.1; commit "$R" b; O2="$(head_sha "$R")"
write_apm "$R" omi 1.2.0; commit "$R" c
(cd "$R" && git tag -a omi-v1.0.0 -m x "$O1")
run "$R" --ref main
expect_rc "invalid version in history" 2
expect_row "row is ERROR" omi INVALID "$O2" ERROR
echo "Case 12f: a tag outside the ref's history is not an anchor"
R="$(new_repo)"
write_apm "$R" pi 1.0.0; commit "$R" a; P1="$(head_sha "$R")"
write_apm "$R" pi 1.1.0; commit "$R" b; P2="$(head_sha "$R")"
(cd "$R" && git checkout -q -b side "$P1" && git commit -q --allow-empty -m side && git tag -a pi-v1.0.0 -m x HEAD && git checkout -q main)
run "$R" --ref main
expect_rc "off-history tag ignored" 1
expect_rows "only the current run is wanted" pi 1
expect_row "pi 1.1.0 MISSING" pi 1.1.0 "$P2" MISSING
(cd "$R" && git tag -a pi-v1.1.0 -m x side)
run "$R" --ref main
expect_rc "current version tagged off-history" 2
expect_row "row is ERROR" pi 1.1.0 "$P2" ERROR
echo "Case 12g: whitespace in name or version exits 2"
R="$(new_repo)"
mkdir -p "$R/plugins/mu"; printf 'name: "mu\\t"\nversion: 1.0.0\n' > "$R/plugins/mu/apm.yml"; commit "$R" a
run "$R" --ref main
expect_rc "tab in name" 2
if grep -q "whitespace" <<< "$OUT"; then pass "message names whitespace"; else fail "no whitespace message"; fi
printf 'name: mu\nversion: "1.0.0 "\n' > "$R/plugins/mu/apm.yml"; commit "$R" b
run "$R" --ref main
expect_rc "trailing space in version" 2
echo "Case 12h: a tag name git rejects is an ERROR and nothing is created"
R="$(new_repo)"
write_apm "$R" rho 1.0.0; write_apm "$R" "a..b" 1.0.0; commit "$R" a
run "$R" --ref main --apply
expect_rc "invalid ref name blocks --apply" 2
if grep -q "check-ref-format" <<< "$OUT"; then pass "message names check-ref-format"; else fail "no check-ref-format message"; fi
if [[ -z "$(git -C "$R" tag -l)" ]]; then pass "nothing created"; else fail "tags created despite invalid name"; fi
echo "Case 12i: a git tag failure mid --apply reports what was created"
R="$(new_repo)"
write_apm "$R" sa 1.0.0; write_apm "$R" sb 1.0.0; commit "$R" a
mkdir -p "$R/.git/refs/tags" && : > "$R/.git/refs/tags/sb-v1.0.0.lock"
run "$R" --ref main --apply
expect_rc "mid-run git tag failure" 2
if [[ -n "$(git -C "$R" tag -l sa-v1.0.0)" ]]; then pass "sa-v1.0.0 was created first"; else fail "sa-v1.0.0 missing"; fi
if grep -qx "git push origin sa-v1.0.0" <<< "$OUT"; then pass "push line names what was created"; else fail "no push line for created tags"; echo "$OUT" | sed 's/^/ /'; fi
echo "Case 12j: --apply with --plugin creates only that plugin's tag"
R="$(new_repo)"
write_apm "$R" ta 1.0.0; write_apm "$R" tb 1.0.0; commit "$R" a
run "$R" --ref main --plugin ta --apply
expect_rc "--apply --plugin ta" 0
if [[ -n "$(git -C "$R" tag -l ta-v1.0.0)" && -z "$(git -C "$R" tag -l 'tb-v*')" ]]; then pass "only ta tagged"; else fail "wrong tags: $(git -C "$R" tag -l | tr '\n' ' ')"; fi
echo "Case 12k: --ref <older> --plugin <p> --apply tags that plugin's older version only"
R="$(new_repo)"
write_apm "$R" ua 1.0.0; write_apm "$R" ub 1.0.0; commit "$R" a; U1="$(head_sha "$R")"
write_apm "$R" ua 1.1.0; write_apm "$R" ub 1.1.0; commit "$R" b; U2="$(head_sha "$R")"
run "$R" --ref "$U1" --plugin ua --apply
expect_rc "one-off older tag" 0
if [[ "$(git -C "$R" tag -l)" == "ua-v1.0.0" ]]; then pass "only ua-v1.0.0 created"; else fail "wrong tags: $(git -C "$R" tag -l | tr '\n' ' ')"; fi
if [[ "$(git -C "$R" rev-parse "ua-v1.0.0^{commit}")" == "$U1" ]]; then pass "ua-v1.0.0 on the older commit"; else fail "ua-v1.0.0 misplaced"; fi
run "$R" --ref main
expect_rows "ua anchored at the one-off tag" ua 2
expect_row "ua 1.1.0 MISSING after the one-off" ua 1.1.0 "$U2" MISSING
echo "Case 12l: default ref is origin/main, not local main"
R="$(new_repo)"
write_apm "$R" va 1.0.0; commit "$R" a; V1="$(head_sha "$R")"
B="$(mktemp -d)"; CLEANUP_DIRS+=("$B")
git init -q --bare "$B/r.git"
(cd "$R" && git remote add origin "$B/r.git" && git push -q origin main 2>/dev/null)
write_apm "$R" va 2.0.0; commit "$R" local-only
run "$R"
expect_rc "default ref" 1
expect_row "reads origin/main's version" va 1.0.0 "$V1" MISSING
if ! grep -q "reading local main" <<< "$OUT"; then pass "no staleness note when origin/main resolves"; else fail "staleness note printed"; fi
echo "Case 13: bad input exits 2"
run "$R" --ref no-such-ref