A mis-cut tag could serve as the start point and silently drop the runs before it: x-v9.9.9 or a lightweight x-v1.0.1 on a later landing hid an untagged 1.1.0 and --apply succeeded. Every reachable <p>-v<semver> tag is now validated (annotated, peels to a landing of its own version); an invalid one is an ERROR row naming it, blocks --apply, and is never the start point. Also from review: - --apply needs origin/main and a ref on it; no local-main fallback. - A version with literal quotes is invalid, not stripped. - Plugin dirs are listed NUL-separated; a leading-dash name exits 2. - With no tags, the backfill starts at the current version's first landing, so a recurring version is released once, there (Case 2, 12d). - expect_row ERE-escapes plugin and version. ADR-0033 updated to match. Refs: #223 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
453 lines
22 KiB
Bash
Executable File
453 lines
22 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# Tests for scripts/tag-plugin-releases.sh (ADR-0033). Every case builds its
|
|
# own throwaway repo; none touches this repo's tags.
|
|
|
|
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
SCRIPT="$REPO_ROOT/scripts/tag-plugin-releases.sh"
|
|
PASS=0
|
|
FAIL=0
|
|
|
|
pass() { echo " PASS: $1"; PASS=$((PASS + 1)); }
|
|
fail() { echo " FAIL: $1"; FAIL=$((FAIL + 1)); }
|
|
|
|
if ! python3 -c 'import yaml' 2>/dev/null; then
|
|
echo "SKIP: python3 with PyYAML is required" >&2
|
|
exit 77
|
|
fi
|
|
|
|
# Fixtures must not inherit the caller's repo (see tests/run-tests.sh, #204).
|
|
unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE GIT_OBJECT_DIRECTORY GIT_COMMON_DIR
|
|
|
|
# Output assertions use here-strings, never `echo | grep -q` (pipefail race;
|
|
# see docs/spec/gates.md, Tests).
|
|
|
|
CLEANUP_DIRS=()
|
|
trap 'rm -rf ${CLEANUP_DIRS[@]+"${CLEANUP_DIRS[@]}"}' EXIT
|
|
|
|
new_repo() {
|
|
local dir
|
|
dir="$(mktemp -d)"
|
|
CLEANUP_DIRS+=("$dir")
|
|
(cd "$dir" && git init -q -b main && git config user.email [email protected] && git config user.name t \
|
|
&& git config tag.gpgSign false && git config commit.gpgSign false)
|
|
echo "$dir"
|
|
}
|
|
|
|
# write_apm <repo> <dir> <version> [name] [description]
|
|
write_apm() {
|
|
local repo="$1" dir="$2" ver="$3" name="${4:-$2}" desc="${5:-A plugin.}"
|
|
mkdir -p "$repo/plugins/$dir"
|
|
printf 'name: %s\nversion: %s\ndescription: %s\n' "$name" "$ver" "$desc" > "$repo/plugins/$dir/apm.yml"
|
|
}
|
|
|
|
commit() { (cd "$1" && git add -A && git commit -q -m "${2:-change}"); }
|
|
head_sha() { git -C "$1" rev-parse HEAD; }
|
|
# --apply needs origin/main; point it at local main (no remote needed).
|
|
sync_origin() { git -C "$1" update-ref refs/remotes/origin/main refs/heads/main; }
|
|
|
|
# run <repo> [args...]: stdout+stderr, exit code in RC.
|
|
run() {
|
|
local dir="$1"; shift
|
|
RC=0
|
|
OUT="$(cd "$dir" && bash "$SCRIPT" "$@" 2>&1)" || RC=$?
|
|
}
|
|
|
|
expect_rc() {
|
|
local desc="$1" want="$2"
|
|
if [[ "$RC" -eq "$want" ]]; then pass "$desc (exit $want)"; else fail "$desc: exit $RC, want $want"; echo "$OUT" | sed 's/^/ /'; fi
|
|
}
|
|
|
|
# ERE-escape $1 so a version's dots match only dots.
|
|
ere_quote() { sed 's/[][\\.*^$+?(){}|/]/\\&/g' <<< "$1"; }
|
|
|
|
# expect_row <desc> <plugin> <version> <sha> <status>
|
|
expect_row() {
|
|
local desc="$1" re
|
|
re="^$(ere_quote "$2") +$(ere_quote "$3") +${4:0:7} +$5\$"
|
|
if grep -Eq "$re" <<< "$OUT"; then pass "$desc"; else fail "$desc: no row '$2 $3 ${4:0:7} $5'"; echo "$OUT" | sed 's/^/ /'; fi
|
|
}
|
|
|
|
# expect_rows <desc> <plugin> <count>
|
|
expect_rows() {
|
|
local n
|
|
n="$(grep -Ec "^$2 " <<< "$OUT" || true)"
|
|
if [[ "$n" -eq "$3" ]]; then pass "$1"; else fail "$1: $n rows for $2, want $3"; echo "$OUT" | sed 's/^/ /'; fi
|
|
}
|
|
|
|
echo "Case 1: merge commit vs squash -- target is the commit on main's first-parent line"
|
|
R="$(new_repo)"
|
|
write_apm "$R" alpha 1.0.0; write_apm "$R" beta 1.0.0; commit "$R" init
|
|
(cd "$R" && git checkout -q -b feat-a)
|
|
write_apm "$R" alpha 1.1.0; commit "$R" "bump alpha"
|
|
BRANCH_A="$(head_sha "$R")"
|
|
(cd "$R" && git checkout -q main && git merge -q --no-ff -m "merge a" feat-a)
|
|
MERGE_A="$(head_sha "$R")"
|
|
(cd "$R" && git checkout -q -b feat-b)
|
|
write_apm "$R" beta 1.1.0; commit "$R" "bump beta"
|
|
(cd "$R" && git checkout -q main && git merge -q --squash feat-b > /dev/null && git commit -q -m "squash b")
|
|
SQUASH_B="$(head_sha "$R")"
|
|
run "$R"
|
|
expect_rc "dry run with missing tags" 1
|
|
expect_row "merge: alpha 1.1.0 targets the merge commit" alpha 1.1.0 "$MERGE_A" MISSING
|
|
expect_row "squash: beta 1.1.0 targets the squash commit" beta 1.1.0 "$SQUASH_B" MISSING
|
|
if ! grep -q "${BRANCH_A:0:7}" <<< "$OUT"; then pass "feature-branch commit is never a target"; else fail "feature-branch commit named"; fi
|
|
if grep -q "reading local main" <<< "$OUT"; then pass "falls back to local main with a staleness note"; else fail "no staleness note"; fi
|
|
(cd "$R" && git checkout -q -b elsewhere && git checkout -q main)
|
|
write_apm "$R" alpha 9.9.9 > /dev/null; # working-tree edit must not count
|
|
run "$R" --ref main
|
|
expect_row "reads the ref, not the working tree" alpha 1.1.0 "$MERGE_A" MISSING
|
|
(cd "$R" && git checkout -q -- .)
|
|
|
|
echo "Case 2: version goes X -> Y -> X with no tags -- backfill starts at X's first landing"
|
|
R="$(new_repo)"
|
|
write_apm "$R" gamma 0.9.0; commit "$R" z; ZERO="$(head_sha "$R")"
|
|
write_apm "$R" gamma 1.0.0; commit "$R" a; FIRST="$(head_sha "$R")"
|
|
write_apm "$R" gamma 1.1.0; commit "$R" b; SECOND="$(head_sha "$R")"
|
|
write_apm "$R" gamma 1.0.0; commit "$R" c; THIRD="$(head_sha "$R")"
|
|
run "$R" --ref main
|
|
expect_rc "X->Y->X dry run" 1
|
|
expect_row "X is MISSING at its first landing" gamma 1.0.0 "$FIRST" MISSING
|
|
expect_row "Y after it is MISSING" gamma 1.1.0 "$SECOND" MISSING
|
|
expect_row "X's later run is RELEASED" gamma 1.0.0 "$THIRD" RELEASED
|
|
expect_rows "three wanted rows" gamma 3
|
|
if ! grep -q "${ZERO:0:7}" <<< "$OUT"; then pass "history before X's first landing not named"; else fail "older run named"; fi
|
|
sync_origin "$R"
|
|
run "$R" --ref main --apply
|
|
expect_rc "backfill --apply" 0
|
|
if [[ "$(git -C "$R" rev-parse "gamma-v1.0.0^{commit}" 2>/dev/null)" == "$FIRST" ]]; then pass "gamma-v1.0.0 on the first landing"; else fail "gamma-v1.0.0 misplaced"; fi
|
|
run "$R" --ref main
|
|
expect_rc "dry run after backfill is clean (idempotent)" 0
|
|
|
|
echo "Case 3: non-bump edit to apm.yml does not start a new run"
|
|
R="$(new_repo)"
|
|
write_apm "$R" delta 2.0.0; commit "$R" a; BUMP="$(head_sha "$R")"
|
|
write_apm "$R" delta 2.0.0 delta "Reworded."; commit "$R" b; EDIT="$(head_sha "$R")"
|
|
run "$R" --ref main
|
|
expect_row "target stays on the bump commit" delta 2.0.0 "$BUMP" MISSING
|
|
expect_rows "one row only" delta 1
|
|
if ! grep -q "${EDIT:0:7}" <<< "$OUT"; then pass "edit commit not a target"; else fail "edit commit named"; fi
|
|
|
|
echo "Case 4: existing lightweight tag is an ERROR"
|
|
(cd "$R" && git tag delta-v2.0.0 "$BUMP")
|
|
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
|
|
|
|
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")
|
|
run "$R" --ref main
|
|
expect_rc "tag on a later commit" 2
|
|
expect_row "row is ERROR" delta 2.0.0 "$BUMP" ERROR
|
|
if grep -q "peels to ${EDIT:0:7}" <<< "$OUT"; then pass "message names where it peels"; else fail "no peel message"; fi
|
|
(cd "$R" && git tag -d delta-v2.0.0 > /dev/null && git tag -a delta-v2.0.0 -m x "$BUMP")
|
|
run "$R" --ref main
|
|
expect_rc "same tag on the right commit" 0
|
|
expect_row "row is OK" delta 2.0.0 "$BUMP" OK
|
|
|
|
echo "Case 6: shallow clone exits 2"
|
|
S="$(mktemp -d)"; CLEANUP_DIRS+=("$S")
|
|
git clone -q --depth 1 "file://$R" "$S/c" 2>/dev/null
|
|
run "$S/c"
|
|
expect_rc "shallow clone" 2
|
|
if grep -q "shallow" <<< "$OUT"; then pass "message names shallow"; else fail "no shallow message"; fi
|
|
|
|
echo "Case 7: apm.yml name differs from directory exits 2"
|
|
R="$(new_repo)"
|
|
write_apm "$R" eps 1.0.0 epsilon; commit "$R" a
|
|
run "$R" --ref main
|
|
expect_rc "name != dir" 2
|
|
if grep -q "must equal the directory" <<< "$OUT"; then pass "message names the mismatch"; else fail "no mismatch message"; fi
|
|
|
|
echo "Case 7b: non-semver current version exits 2"
|
|
R="$(new_repo)"
|
|
write_apm "$R" zeta 1.0; commit "$R" a
|
|
run "$R" --ref main
|
|
expect_rc "version 1.0" 2
|
|
|
|
echo "Case 8: prefix-sharing names (git, gitea) never claim each other's tags"
|
|
R="$(new_repo)"
|
|
write_apm "$R" git 0.1.0; write_apm "$R" gitea 1.0.0; commit "$R" a; C1="$(head_sha "$R")"
|
|
write_apm "$R" git 0.2.0; write_apm "$R" gitea 1.1.0; commit "$R" b; C2="$(head_sha "$R")"
|
|
(cd "$R" && git tag -a gitea-v1.0.0 -m x "$C1")
|
|
run "$R" --ref main
|
|
expect_rows "git: gitea's tag is not its anchor -- current run only" git 1
|
|
expect_row "git 0.2.0 MISSING" git 0.2.0 "$C2" MISSING
|
|
expect_rows "gitea: anchored at its own tag" gitea 2
|
|
expect_row "gitea 1.0.0 OK" gitea 1.0.0 "$C1" OK
|
|
expect_row "gitea 1.1.0 MISSING" gitea 1.1.0 "$C2" MISSING
|
|
run "$R" --ref main --plugin git
|
|
expect_rows "--plugin git lists no gitea row" gitea 0
|
|
expect_rows "--plugin git lists git" git 1
|
|
|
|
echo "Case 9: every run after the newest tag is wanted"
|
|
R="$(new_repo)"
|
|
write_apm "$R" eta 1.0.0; commit "$R" a; V10="$(head_sha "$R")"
|
|
write_apm "$R" eta 1.1.0; commit "$R" b; V11="$(head_sha "$R")"
|
|
write_apm "$R" eta 1.2.0; commit "$R" c; V12="$(head_sha "$R")"
|
|
write_apm "$R" eta 1.3.0; commit "$R" d; V13="$(head_sha "$R")"
|
|
(cd "$R" && git tag -a eta-v1.1.0 -m x "$V11")
|
|
run "$R" --ref main
|
|
expect_rc "later runs missing" 1
|
|
expect_row "anchor 1.1.0 OK" eta 1.1.0 "$V11" OK
|
|
expect_row "1.2.0 MISSING" eta 1.2.0 "$V12" MISSING
|
|
expect_row "1.3.0 MISSING" eta 1.3.0 "$V13" MISSING
|
|
expect_rows "older 1.0.0 not wanted" eta 3
|
|
if ! grep -q "${V10:0:7}" <<< "$OUT"; then pass "1.0.0 commit not named"; else fail "1.0.0 named"; fi
|
|
|
|
echo "Case 10: --apply creates annotated tags, prints explicit push line, is idempotent"
|
|
sync_origin "$R"
|
|
run "$R" --ref main --apply
|
|
expect_rc "--apply" 0
|
|
for pair in "1.2.0:$V12" "1.3.0:$V13"; do
|
|
v="${pair%%:*}"; sha="${pair#*:}"
|
|
if [[ "$(git -C "$R" cat-file -t "refs/tags/eta-v$v" 2>/dev/null)" == tag ]]; then pass "eta-v$v is annotated"; else fail "eta-v$v not annotated"; fi
|
|
if [[ "$(git -C "$R" rev-parse "eta-v$v^{commit}" 2>/dev/null)" == "$sha" ]]; then pass "eta-v$v peels to its target"; else fail "eta-v$v wrong target"; fi
|
|
done
|
|
if [[ "$(git -C "$R" tag -l --format='%(contents:subject)' eta-v1.3.0)" == "eta 1.3.0" ]]; then pass "tag message is '<p> <v>'"; else fail "tag message wrong"; fi
|
|
if grep -qx "git push origin eta-v1.2.0 eta-v1.3.0" <<< "$OUT"; then pass "push line names each tag"; else fail "push line wrong"; echo "$OUT" | sed 's/^/ /'; fi
|
|
if ! grep -q -- "--tags" <<< "$OUT"; then pass "push line never uses --tags"; else fail "--tags printed"; fi
|
|
run "$R" --ref main --apply
|
|
expect_rc "second --apply" 0
|
|
if ! grep -q "git push" <<< "$OUT"; then pass "second --apply creates nothing"; else fail "second --apply printed a push line"; fi
|
|
run "$R" --ref main
|
|
expect_rc "dry run after --apply" 0
|
|
|
|
echo "Case 11: --apply is all-or-nothing"
|
|
R="$(new_repo)"
|
|
write_apm "$R" theta 1.0.0; write_apm "$R" iota 1.0.0; commit "$R" a; A="$(head_sha "$R")"
|
|
write_apm "$R" iota 1.0.0 iota "Reworded."; commit "$R" b
|
|
(cd "$R" && git tag iota-v1.0.0 "$A")
|
|
sync_origin "$R"
|
|
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: 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; 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 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
|
|
sync_origin "$R"
|
|
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
|
|
sync_origin "$R"
|
|
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: two wanted rows" nu 2
|
|
expect_row "untagged: first landing is MISSING" nu 1.0.0 "$N1" MISSING
|
|
expect_row "untagged: re-add is RELEASED" nu 1.0.0 "$N3" RELEASED
|
|
(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
|
|
printf "name: mu\nversion: \"'1.0.0'\"\n" > "$R/plugins/mu/apm.yml"; commit "$R" c
|
|
run "$R" --ref main
|
|
expect_rc "literal quotes in version are invalid, not stripped" 2
|
|
if grep -q "no strict MAJOR.MINOR.PATCH" <<< "$OUT"; then pass "message names the invalid version"; else fail "no invalid-version message"; fi
|
|
|
|
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
|
|
sync_origin "$R"
|
|
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"
|
|
sync_origin "$R"
|
|
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
|
|
sync_origin "$R"
|
|
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")"
|
|
sync_origin "$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 12m: an invalid tag is never the start point and is reported"
|
|
R="$(new_repo)"
|
|
write_apm "$R" x 1.0.0; commit "$R" a; X10="$(head_sha "$R")"
|
|
write_apm "$R" x 1.1.0; commit "$R" b; X11="$(head_sha "$R")"
|
|
write_apm "$R" x 1.2.0; commit "$R" c; X12="$(head_sha "$R")"
|
|
write_apm "$R" x 1.3.0; commit "$R" d
|
|
(cd "$R" && git tag -a x-v1.0.0 -m x "$X10" && git tag -a x-v9.9.9 -m x "$X12")
|
|
sync_origin "$R"
|
|
run "$R" --ref main
|
|
expect_rc "wrong-version tag on a later landing" 2
|
|
expect_row "row names the wrong-version tag" x 9.9.9 "$X12" ERROR
|
|
if grep -q "x-v9.9.9 peels to ${X12:0:7}" <<< "$OUT"; then pass "message names x-v9.9.9"; else fail "x-v9.9.9 not named"; fi
|
|
expect_row "1.1.0 is still wanted (start point is x-v1.0.0)" x 1.1.0 "$X11" MISSING
|
|
run "$R" --ref main --apply
|
|
expect_rc "--apply blocked by the wrong-version tag" 2
|
|
if [[ "$(git -C "$R" tag -l | tr '\n' ' ')" == "x-v1.0.0 x-v9.9.9 " ]]; then pass "nothing created"; else fail "tags created: $(git -C "$R" tag -l | tr '\n' ' ')"; fi
|
|
(cd "$R" && git tag -d x-v9.9.9 > /dev/null && git tag x-v1.0.1 "$X12")
|
|
run "$R" --ref main
|
|
expect_rc "lightweight tag as start point" 2
|
|
expect_row "row names the lightweight tag" x 1.0.1 "$X12" ERROR
|
|
if grep -q "x-v1.0.1 is a lightweight tag" <<< "$OUT"; then pass "message names x-v1.0.1"; else fail "x-v1.0.1 not named"; fi
|
|
expect_row "1.1.0 is still wanted" x 1.1.0 "$X11" MISSING
|
|
run "$R" --ref main --apply
|
|
expect_rc "--apply blocked by the lightweight tag" 2
|
|
|
|
echo "Case 12n: --apply only tags history on origin/main"
|
|
R="$(new_repo)"
|
|
write_apm "$R" wa 1.0.0; commit "$R" a
|
|
(cd "$R" && git checkout -q -b feat)
|
|
write_apm "$R" wa 1.1.0; commit "$R" b; FEAT="$(head_sha "$R")"
|
|
(cd "$R" && git checkout -q main)
|
|
run "$R" --ref "$FEAT" --apply
|
|
expect_rc "--apply with no origin/main" 2
|
|
if [[ -z "$(git -C "$R" tag -l)" ]]; then pass "no tag without origin/main"; else fail "tag created without origin/main"; fi
|
|
run "$R" --apply
|
|
expect_rc "--apply refuses the local-main fallback" 2
|
|
sync_origin "$R"
|
|
run "$R" --ref "$FEAT" --apply
|
|
expect_rc "--apply --ref <feature-branch commit>" 2
|
|
if grep -q "not on origin/main" <<< "$OUT"; then pass "message names origin/main"; else fail "no origin/main message"; fi
|
|
if [[ -z "$(git -C "$R" tag -l)" ]]; then pass "no tag on a feature-branch commit"; else fail "tag created off main"; fi
|
|
run "$R" --ref "$FEAT"
|
|
expect_rc "dry run may still read a feature-branch ref" 1
|
|
|
|
echo "Case 12o: a plugin name starting with '-' exits 2"
|
|
R="$(new_repo)"
|
|
write_apm "$R" ok 1.0.0; write_apm "$R" "-x" 1.0.0; commit "$R" a
|
|
sync_origin "$R"
|
|
run "$R" --ref main --apply
|
|
expect_rc "leading-dash plugin" 2
|
|
if grep -q "must not start with '-'" <<< "$OUT"; then pass "message names the leading dash"; else fail "no leading-dash message"; fi
|
|
if [[ -z "$(git -C "$R" tag -l)" ]]; then pass "nothing created"; else fail "tags created"; fi
|
|
|
|
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
|
|
|
|
echo "Case 13: bad input exits 2"
|
|
run "$R" --ref no-such-ref
|
|
expect_rc "unresolvable --ref" 2
|
|
run "$R" --ref main --plugin nope
|
|
expect_rc "unknown --plugin" 2
|
|
run "$R" --bogus
|
|
expect_rc "unknown flag" 2
|
|
R="$(new_repo)"
|
|
write_apm "$R" lam 1.0.0; commit "$R" a
|
|
(cd "$R" && git branch -q -m trunk)
|
|
run "$R"
|
|
expect_rc "no origin/main or main" 2
|
|
|
|
echo
|
|
echo "Results: $PASS passed, $FAIL failed"
|
|
[[ $FAIL -eq 0 ]]
|