feat(scripts): verify rail + pre-push hook
CI / ci (push) Canceled after 0s
CI / ci (push) Canceled after 0s
Port classis full-test.sh (071966e) as Museion's one-command verify loop: run/start/status/summary over detached xcodebuild, per-run pinned xcresult bundles with atomic run-dir allocation (#33/#179), xcresulttool-authoritative counts (#31/#178), zero-match filters fail (#31/#134), --serialized rerun is the record (#30/#147), per- test timeouts + wedge observability (#134). Default scope: MuseionTests. install-hooks.sh + pre-push: no push while any run is live, lint gate scoped to the push's Swift files (bare swiftlint . exits 2 on main — spike/ + one tests file), autofix-rewrite guard. New-ref pushes lint the merge-base delta vs refs/remotes/origin/main and fail closed on unscopable history; a full-ref spelling defeats refs/tags shadowing. scripts/test-full-test.sh: 23-check acceptance rig with an executed-count guard. Four finish-audit rounds; every guard flip-verified both directions. Suite 692/692 through the rail itself. Closes #190
This commit is contained in:
1 parent
11b196d68a
commit
0ab00eb7b6
9 files changed
+962
-8
No files matched your search
Executable
+164
@@ -0,0 +1,164 @@
|
||||
#!/usr/bin/env bash
|
||||
# test-full-test.sh — pre-push acceptance rig (#190 AC7; finish-audit rounds 1-3).
|
||||
# Builds a DISPOSABLE bare remote + clone, installs the REAL hook, and pushes
|
||||
# every ref shape the gate must handle: clean/autofix/lint-fail/live-run
|
||||
# blocks, docs-only skip, endpoint scoping (in-range block, out-of-range
|
||||
# pass), new-branch delta gating, delete pushes, orphan/shadow-tag refusals,
|
||||
# non-origin and by-URL pushes. Run: ./scripts/test-full-test.sh (no args; a
|
||||
# throwaway mktemp dir under /tmp is kept after the run for post-mortem).
|
||||
# Exits nonzero on any FAIL or on an unexpected executed-check count.
|
||||
set -uo pipefail
|
||||
|
||||
H="$(mktemp -d /tmp/museion-hook-rig.XXXXXX)" # kept after the run for post-mortem
|
||||
REPO="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
fails=0; n_checks=0
|
||||
check() { # $1=label $2=expected $3=actual
|
||||
n_checks=$((n_checks + 1))
|
||||
if [[ "$2" == "$3" ]]; then echo "PASS: $1"; else echo "FAIL: $1 — expected [$2] got [$3]"; fails=$((fails+1)); fi
|
||||
}
|
||||
EXPECTED_CHECKS=23 # executed-count guard: a deleted/dead check fails loudly (#31)
|
||||
cd "$H"
|
||||
git init -q --bare remote.git
|
||||
git clone -q remote.git work
|
||||
cd work
|
||||
git config user.email t@t; git config user.name t
|
||||
mkdir -p scripts/hooks
|
||||
cp "$REPO/scripts/hooks/pre-push" scripts/hooks/
|
||||
cp "$REPO/scripts/install-hooks.sh" scripts/
|
||||
cp "$REPO/.swiftlint.yml" .
|
||||
cp "$REPO/.swiftformat" .
|
||||
# bootstrap: seed the remote's main BEFORE activating hooks (a fresh remote
|
||||
# has no default ref for the gate to scope against — first push is --no-verify
|
||||
# by definition, like any repo bootstrap)
|
||||
printf 'let ok = 1\n' >Good.swift
|
||||
git add -A; git commit -qm bootstrap
|
||||
git push -q --no-verify origin HEAD:refs/heads/main 2>/dev/null
|
||||
bash scripts/install-hooks.sh >/dev/null
|
||||
check "AC7 install-hooks sets core.hooksPath" "scripts/hooks" "$(git config core.hooksPath)"
|
||||
|
||||
push_out() { git push origin HEAD:refs/heads/main 2>&1; }
|
||||
|
||||
# clean tree → push passes
|
||||
printf 'let ok2 = 2\n' >Good2.swift
|
||||
git add -A; git commit -qm clean
|
||||
out="$(push_out)"; rc=$?
|
||||
check "AC7 clean tree pushes" 0 "$rc"
|
||||
|
||||
# committed MISFORMAT → swiftformat rewrites the working tree → BLOCK
|
||||
printf 'let bad=1\n' >Bad.swift
|
||||
git add Bad.swift; git commit -qm misformat
|
||||
out="$(push_out)"; rc=$?
|
||||
[[ "$out" == *"linters MODIFIED the working tree"* ]]; check "AC7 autofix rewrite blocks push" 0 $?
|
||||
check "AC7 autofix block exits nonzero" 1 "$rc"
|
||||
git rm -qf Bad.swift; git commit -qm drop-bad
|
||||
|
||||
# committed LINT VIOLATION (>180-char line) → swiftlint fails → BLOCK
|
||||
{ printf 'let long = "'; printf 'A%.0s' {1..190}; printf '"\n'; } >Long.swift
|
||||
git add Long.swift; git commit -qm violation
|
||||
out="$(push_out)"; rc=$?
|
||||
[[ "$out" == *"linters failed"* ]]; check "AC7 lint violation blocks push" 0 $?
|
||||
check "AC7 lint block exits nonzero" 1 "$rc"
|
||||
git rm -q Long.swift; git commit -qm drop-long
|
||||
|
||||
# LIVE full-test run → BLOCK
|
||||
mkdir -p _build/full-test/run1
|
||||
sleep 30 & livepid=$!
|
||||
echo "$livepid" >_build/full-test/run1/pid
|
||||
printf '%s\n' "$PWD/_build/full-test/run1" >_build/full-test/current
|
||||
out="$(push_out)"; rc=$?
|
||||
[[ "$out" == *"full-test run(s) live"* ]]; check "AC7 live run blocks push" 0 $?
|
||||
check "AC7 live block exits nonzero" 1 "$rc"
|
||||
# regression (#190 review): a live run that `current` does NOT name (concurrent
|
||||
# runs repoint it) must still block — the hook scans all run dirs.
|
||||
mkdir -p _build/full-test/run2; echo 999999 >_build/full-test/run2/pid
|
||||
printf '%s\n' "$PWD/_build/full-test/run2" >_build/full-test/current
|
||||
out="$(push_out)"; rc=$?
|
||||
[[ "$out" == *"run1"* ]]; check "AC7 live run outside current blocks push" 0 $?
|
||||
check "AC7 outside-current block exits nonzero" 1 "$rc"
|
||||
kill "$livepid" 2>/dev/null
|
||||
|
||||
# docs-only commit (no Swift in the push) → passes (lint has nothing to gate;
|
||||
# the skip itself is not directly observable here — every Swift file is clean)
|
||||
printf '# Doc\n' >DOC.md
|
||||
git add DOC.md; git commit -qm docs
|
||||
out="$(push_out)"; rc=$?
|
||||
check "AC7 docs-only push passes" 0 "$rc"
|
||||
|
||||
# pre-existing violation OUTSIDE the push range must NOT block (endpoint diff)
|
||||
{ printf 'let old = "'; printf 'B%.0s' {1..190}; printf '"\n'; } >Old.swift
|
||||
git add Old.swift; git commit -qm add-old
|
||||
out="$(push_out)"; rc=$? # Old.swift IS in range → blocked
|
||||
[[ "$out" == *"linters failed"* ]]; check "AC7 in-range violation still blocks" 0 $?
|
||||
git rm -q Old.swift; git commit -qm drop-old
|
||||
out="$(push_out)"; rc=$? # endpoints no longer contain Old.swift; the range's only
|
||||
# entry is its deletion (ACMR excludes D) — genuine out-of-tree scoping is
|
||||
# pinned by the new-branch case below (Remote.swift outside the delta)
|
||||
check "AC7 deleted-in-range file does not block" 0 "$rc"
|
||||
|
||||
# plant a violating file on the remote default branch (pushed around the gate)
|
||||
{ printf 'let remote = "'; printf 'C%.0s' {1..190}; printf '"\n'; } >Remote.swift
|
||||
git add Remote.swift; git commit -qm remote-violation
|
||||
git push --no-verify -q origin HEAD:refs/heads/main 2>/dev/null
|
||||
|
||||
# NEW branch (zero rsha), clean delta → passes despite the remote's violation
|
||||
git checkout -qb feat
|
||||
printf 'let feat = 1\n' >Feat.swift
|
||||
git add Feat.swift; git commit -qm feat
|
||||
out="$(git push origin HEAD:refs/heads/feat 2>&1)"; rc=$?
|
||||
check "AC7 new-branch push gated on delta only" 0 "$rc"
|
||||
|
||||
# NEW branch carrying a violation → still blocked (gate applies to the delta)
|
||||
git checkout -qb featbad
|
||||
{ printf 'let fb = "'; printf 'D%.0s' {1..190}; printf '"\n'; } >FeatBad.swift
|
||||
git add FeatBad.swift; git commit -qm featbad
|
||||
out="$(git push origin HEAD:refs/heads/featbad 2>&1)"; rc=$?
|
||||
[[ "$out" == *"linters failed"* ]]; check "AC7 new-branch violation blocks" 0 $?
|
||||
git checkout -q main
|
||||
|
||||
# DELETE push (zero lsha) → no fatal noise, passes
|
||||
out="$(git push origin :refs/heads/feat 2>&1)"; rc=$?
|
||||
[[ "$out" != *"fatal:"* ]]; check "AC7 delete push no fatal noise" 0 $?
|
||||
check "AC7 delete push passes" 0 "$rc"
|
||||
|
||||
# push to a NON-origin remote (alt; its alt/main tracking ref deleted):
|
||||
# still scoped against origin/main — the project's delta — and passes
|
||||
git remote add alt "$PWD/../remote.git"; git fetch -q alt
|
||||
git update-ref -d refs/remotes/alt/main
|
||||
git checkout -qb feat2
|
||||
printf 'let f2 = 1\n' >F2.swift
|
||||
git add F2.swift; git commit -qm feat2
|
||||
out="$(git push alt HEAD:refs/heads/feat2 2>&1)"; rc=$?
|
||||
check "AC7 non-origin push scoped via origin/main passes" 0 "$rc"
|
||||
|
||||
# push BY URL ($1 is the URL, not a remote name): still scoped and passes
|
||||
out="$(git push "$PWD/../remote.git" HEAD:refs/heads/byurl 2>&1)"; rc=$?
|
||||
check "AC7 URL push scoped via origin/main passes" 0 "$rc"
|
||||
|
||||
# orphan-history branch → fails closed (silent skip would be a vacuous pass)
|
||||
git checkout -q main
|
||||
git checkout -q --orphan orph
|
||||
git rm -qrf . >/dev/null 2>&1
|
||||
printf 'let orph = 1\n' >Orph.swift
|
||||
git checkout -q main -- scripts .swiftlint.yml .swiftformat # keep the hook in the orphan tree
|
||||
git add -A; git commit -qm orphan
|
||||
out="$(git push origin HEAD:refs/heads/orph 2>&1)"; rc=$?
|
||||
[[ "$out" == *"no common history"* ]]; check "AC7 orphan push fails closed with message" 0 $?
|
||||
check "AC7 orphan push blocked" 1 "$rc"
|
||||
|
||||
# shadow tag: a LOCAL tag named origin/main pointing at the branch tip must
|
||||
# NOT choose the lint base (short-ref resolution consults refs/tags/ first)
|
||||
git checkout -q main
|
||||
git checkout -qb shadow
|
||||
{ printf 'let sh = "'; printf 'E%.0s' {1..190}; printf '"\n'; } >Shadow.swift
|
||||
git add Shadow.swift; git commit -qm shadow
|
||||
git tag -f origin/main shadow >/dev/null
|
||||
out="$(git push origin HEAD:refs/heads/shadow 2>&1)"; rc=$?
|
||||
[[ "$out" == *"linters failed"* ]]; check "AC7 shadow tag cannot void the lint base" 0 $?
|
||||
check "AC7 shadow-tag push blocked" 1 "$rc"
|
||||
git tag -d origin/main >/dev/null; git checkout -q main
|
||||
|
||||
echo "----"
|
||||
if [[ "$fails" -eq 0 && "$n_checks" -eq "$EXPECTED_CHECKS" ]]; then
|
||||
echo "ALL HOOK ACCEPTANCE CHECKS PASSED ($n_checks/$EXPECTED_CHECKS)"
|
||||
else echo "$fails CHECK(S) FAILED, $n_checks/$EXPECTED_CHECKS executed"; exit 1
|
||||
fi
|
||||
Reference in new issue
Block a user