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
+594
@@ -0,0 +1,594 @@
|
||||
#!/usr/bin/env bash
|
||||
# full-test.sh — detached, xcresult-authoritative full-suite runner.
|
||||
#
|
||||
# Ported from classis scripts/full-test.sh (matured through classis
|
||||
# #649–#729, source commit 071966e) and adapted to Museion (#190). Encodes
|
||||
# the session learnings so sessions stop re-deriving them — the 2026-11-16
|
||||
# retro measured this loop at 29% of all terminal calls (77 xcodebuild +
|
||||
# 76 hand-rolled xcresult reads in ≥8 incantation variants):
|
||||
# #177 — run xcodebuild DETACHED and poll; the full suite can exceed a
|
||||
# tool call's timeout budget (the #177 build-for-testing /
|
||||
# test-without-building split existed only to dodge that cap —
|
||||
# and detached runs make it unnecessary).
|
||||
# #31/#178 — pass/fail counts are authoritative ONLY in the completed
|
||||
# .xcresult (`xcresulttool get test-results summary`), never in
|
||||
# grepped output; #178: totalTestCount counts a parameterized
|
||||
# @Test as ONE test — reconcile executed counts from the summary,
|
||||
# never from log lines.
|
||||
# #31/#134 — an -only-testing filter that matches ZERO executed tests
|
||||
# FAILS the run: single-name filters and suite names with
|
||||
# spaces/backticks match zero Swift Testing tests and "pass"
|
||||
# vacuously. A zero-executed summary exits nonzero, always.
|
||||
# #30/#147 — a parallel-load flake settles via a serialized rerun
|
||||
# (-parallel-testing-enabled NO); that green is the record (each
|
||||
# rerun allocates its own run dir and becomes `current`).
|
||||
# #134 — per-test execution-time allowances are enforced by the runner
|
||||
# (-test-timeouts-enabled YES): a wedged test FAILS at its
|
||||
# allowance — host killed, restarted, named in the xcresult —
|
||||
# instead of holding the run silent (the machine-wedge family:
|
||||
# testmanagerd / IDE-session hangs). The runner rounds the
|
||||
# DEFAULT allowance UP to whole minutes (60s stays 60s).
|
||||
# EngineSmokeTests' real child processes (one wire smoke per LLM
|
||||
# surface) sit well inside the 60s default — raise via
|
||||
# --test-timeout if that ever changes.
|
||||
# #33/#179 — every launch pins its own result bundle (-resultBundlePath)
|
||||
# into an ATOMICALLY allocated run dir, and `run` polls ITS OWN
|
||||
# dir: never "newest .xcresult" (the #33 bundle race), never
|
||||
# `current` (a same-second twin launch repoints it — the #179
|
||||
# pin). Concurrent sessions can never race for a bundle.
|
||||
# Wedge observability (classis #716 machinery, ported): live `status`
|
||||
# names the last test event + its exact age, what is IN FLIGHT,
|
||||
# flags STOPPED (state T) descendants immediately, and separates
|
||||
# advisory "no test progress" from the hard STALLED warning.
|
||||
#
|
||||
# Usage:
|
||||
# scripts/full-test.sh run [--serialized] [--workers N] [--scheme S] [--stall-min N] [--test-timeout N] [--no-test-timeouts] [-- xcodebuild-args...]
|
||||
# scripts/full-test.sh start [same flags] # spawn detached, print run dir, exit
|
||||
# Detached via nohup + setsid-when-available (escapes the caller's process
|
||||
# group, so a tool-call timeout cannot take the run down). Without setsid,
|
||||
# agent callers should prefer `setsid nohup ./scripts/full-test.sh run … > log 2>&1 < /dev/null &`.
|
||||
# scripts/full-test.sh status # live: last test event + age, wedge/stall warnings; exits 3
|
||||
# # finished: final summary
|
||||
# scripts/full-test.sh summary [run-dir] # print a finished run's summary
|
||||
#
|
||||
# run blocks until done — only from a caller with enough timeout budget;
|
||||
# otherwise use start + status (the #177-safe pattern).
|
||||
# status exits 3 while the run is live, so callers can poll in a loop.
|
||||
#
|
||||
# Default test selection is the hosted unit bundle (-only-testing:MuseionTests);
|
||||
# forward your own -only-testing to take over selection (multiple -only-testing
|
||||
# flags UNION, so the default is dropped the moment you bring one). The UI
|
||||
# smoke target stays out of the rail. No parallel flags are passed by default
|
||||
# (single hosted bundle — worker pinning buys nothing); --workers N opts in.
|
||||
#
|
||||
# Do NOT lint concurrently with a live run (#30 — real-process fake-ACP tests
|
||||
# flake under concurrent load).
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
# Acceptance harnesses point FT_BASE_DIR at an isolated directory. Run-dir
|
||||
# allocation is unique per launch, but the bases must stay disjoint: a stub
|
||||
# launch must never repoint the real base's `current` file under a live
|
||||
# agent's polling loop. Absolute-path requirement enforced below die().
|
||||
BASE="${FT_BASE_DIR:-$ROOT/_build/full-test}"
|
||||
CURRENT="$BASE/current"
|
||||
# Per-test timeouts bound a wedged test at --test-timeout; the stall warning
|
||||
# is the BACKSTOP (non-test silence: build, host launch, post-phases). 10 min
|
||||
# comfortably exceeds the 5-min maximum allowance plus kill/restart overhead.
|
||||
# Keep it above --test-timeout if you raise that.
|
||||
STALL_MIN_DEFAULT=10
|
||||
# Per-test allowance seconds. The runner rounds the DEFAULT allowance UP to
|
||||
# whole minutes; the maximum caps any per-test raise (XCTest
|
||||
# executionTimeAllowance / Swift Testing .timeLimit). EngineSmokeTests spawns
|
||||
# real child processes per LLM surface — seconds, well inside 60s.
|
||||
TEST_TIMEOUT_DEFAULT=60
|
||||
TEST_TIMEOUT_MAX=300
|
||||
POLL_SECS=15
|
||||
|
||||
die() { echo "full-test.sh: $*" >&2; exit 2; }
|
||||
[[ -z ${FT_BASE_DIR:-} || $FT_BASE_DIR == /* ]] \
|
||||
|| die "FT_BASE_DIR must be an absolute path, got: ${FT_BASE_DIR:-}"
|
||||
|
||||
# Numeric flag values feed bash arithmetic downstream — a crafted value like
|
||||
# `x[$(cmd)]` or a leading-zero octal literal would be EVALUATED there, not
|
||||
# compared. Accept only plain decimal integers (≤9 digits, so arithmetic
|
||||
# can't overflow either); zero is legal only where the caller allows it.
|
||||
valid_int() { [[ $1 =~ ^(0|[1-9][0-9]{0,8})$ ]]; }
|
||||
require_int() { # $1=flag-name $2=value — positive only
|
||||
valid_int "$2" && [[ $2 != 0 ]] || die "$1 must be a positive integer (no leading zeros), got: $2"
|
||||
}
|
||||
require_nonneg_int() { # $1=flag-name $2=value — zero allowed (--stall-min)
|
||||
valid_int "$2" || die "$1 must be a non-negative integer (no leading zeros), got: $2"
|
||||
}
|
||||
|
||||
usage() { local last; last=$(awk '/^set -euo pipefail/{print NR - 2; exit}' "$0"); sed -n "2,${last}p" "$0" | sed 's/^# \{0,1\}//'; exit 2; }
|
||||
|
||||
MODE="${1:-run}"
|
||||
case "$MODE" in
|
||||
run | start | status | summary) if [[ $# -gt 0 ]]; then shift; fi ;;
|
||||
*) usage ;;
|
||||
esac
|
||||
|
||||
SCHEME=Museion
|
||||
SERIALIZED=0
|
||||
STALL_MIN=$STALL_MIN_DEFAULT
|
||||
TIMEOUT_ENABLED=1
|
||||
TEST_TIMEOUT=$TEST_TIMEOUT_DEFAULT
|
||||
# 0 = pass NO explicit parallel flags (the historical Museion invocation;
|
||||
# single hosted bundle — bundle-worker parallelism buys nothing). --workers N
|
||||
# opts in; --serialized is the #30/#147 flake rerun hatch.
|
||||
WORKERS=0
|
||||
FORWARD=()
|
||||
POSITIONAL=()
|
||||
# The run dir allocated by THIS invocation's start_run. `run` mode polls its
|
||||
# own directory — a same-second twin launch repoints `current` at its own
|
||||
# run, which must not steal this poll loop (#179).
|
||||
THIS_RUN=""
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--serialized) SERIALIZED=1 ;;
|
||||
--workers) [[ $# -ge 2 ]] || die "--workers needs a value"; require_int --workers "$2"; WORKERS="$2"; shift ;;
|
||||
--scheme) [[ $# -ge 2 ]] || die "--scheme needs a value"; [[ $2 == */* ]] && die "--scheme must be a bare scheme name (no path separators), got: $2"; SCHEME="$2"; shift ;;
|
||||
--stall-min) [[ $# -ge 2 ]] || die "--stall-min needs a value"; require_nonneg_int --stall-min "$2"; STALL_MIN="$2"; shift ;;
|
||||
--test-timeout) [[ $# -ge 2 ]] || die "--test-timeout needs a value (seconds)"; require_int --test-timeout "$2"; TEST_TIMEOUT="$2"; shift ;;
|
||||
--no-test-timeouts) TIMEOUT_ENABLED=0 ;;
|
||||
--) shift; FORWARD=("$@"); break ;;
|
||||
-*) die "unknown flag: $1" ;;
|
||||
*) POSITIONAL+=("$1") ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
[[ ${#POSITIONAL[@]} -le 1 ]] || die "unexpected arguments: ${POSITIONAL[*]:1}"
|
||||
|
||||
SUFFIX=""
|
||||
if [[ $SERIALIZED == 1 ]]; then SUFFIX="-serialized"; fi
|
||||
|
||||
start_run() {
|
||||
local run_id run_dir timeout_max n cand merr have_only=0 a
|
||||
# The enforced maximum never sits below the default, so a large
|
||||
# --test-timeout stays coherent (computed once; used by args + banner).
|
||||
timeout_max=$(( TEST_TIMEOUT > TEST_TIMEOUT_MAX ? TEST_TIMEOUT : TEST_TIMEOUT_MAX ))
|
||||
# Allocate the run dir by ATOMIC test-and-create. The bare second-granular
|
||||
# id is tried first (ids unchanged in the common case); a same-second
|
||||
# launch of the same scheme+mode finds it taken and walks a serial tail
|
||||
# (-2, -3, … — unbounded: every taken name was allocated by a real
|
||||
# launch, so the walk always terminates). Each attempt is itself atomic —
|
||||
# bare mkdir fails EEXIST under POSIX, so concurrent starts can never
|
||||
# both win one candidate; there is no check-then-create window. A mkdir
|
||||
# failure whose path does NOT then exist is a real error (e.g.
|
||||
# permissions), not a collision, and dies loudly. The tail only ever
|
||||
# follows the timestamp+scheme base, so ids stay sorted by start time.
|
||||
run_id="$(date -u +%Y%m%dT%H%M%SZ)-$SCHEME$SUFFIX"
|
||||
run_dir=""
|
||||
mkdir -p "$BASE"
|
||||
n=1
|
||||
while :; do
|
||||
if (( n == 1 )); then
|
||||
cand="$BASE/$run_id"
|
||||
else
|
||||
cand="$BASE/$run_id-$n"
|
||||
fi
|
||||
if mkdir "$cand" 2>/dev/null; then
|
||||
run_dir="$cand"
|
||||
break
|
||||
fi
|
||||
if [[ ! -e $cand && ! -L $cand ]]; then
|
||||
merr="$(mkdir "$cand" 2>&1)" || true
|
||||
die "could not create run dir $cand${merr:+ — $merr}"
|
||||
fi
|
||||
n=$((n + 1))
|
||||
done
|
||||
THIS_RUN="$run_dir"
|
||||
|
||||
local args=(
|
||||
-allowProvisioningUpdates
|
||||
-project "$ROOT/Museion.xcodeproj"
|
||||
-scheme "$SCHEME"
|
||||
-destination 'platform=macOS'
|
||||
test
|
||||
-resultBundlePath "$run_dir/result.xcresult"
|
||||
)
|
||||
if [[ $SERIALIZED == 1 ]]; then args+=(-parallel-testing-enabled NO)
|
||||
elif (( WORKERS > 0 )); then args+=(-parallel-testing-enabled YES -parallel-testing-worker-count "$WORKERS"); fi
|
||||
# Runner-enforced per-test allowances — a wedged test fails at its
|
||||
# allowance (host killed + restarted, named in the xcresult). The maximum
|
||||
# never sits below the default, so a large --test-timeout stays coherent.
|
||||
if [[ $TIMEOUT_ENABLED == 1 ]]; then
|
||||
args+=(
|
||||
-test-timeouts-enabled YES
|
||||
-default-test-execution-time-allowance "$TEST_TIMEOUT"
|
||||
-maximum-test-execution-time-allowance "$timeout_max"
|
||||
)
|
||||
fi
|
||||
# Default test selection: the hosted unit bundle (#190). Multiple
|
||||
# -only-testing flags UNION — a bundle-level default beside a finer
|
||||
# forwarded filter would make the filter a no-op — so the default is
|
||||
# dropped the moment the caller forwards any -only-testing of their own.
|
||||
if [[ ${#FORWARD[@]} -gt 0 ]]; then
|
||||
for a in "${FORWARD[@]}"; do [[ $a == -only-testing* ]] && have_only=1; done
|
||||
fi
|
||||
if (( have_only == 0 )); then args+=(-only-testing:MuseionTests); fi
|
||||
if [[ ${#FORWARD[@]} -gt 0 ]]; then args+=("${FORWARD[@]}"); fi
|
||||
|
||||
# nohup + stdin </dev/null: survives this script's (and its caller's) exit.
|
||||
# setsid (when present) also escapes the process group, so a tool-timeout
|
||||
# group-kill of the launching call cannot take the run down with it.
|
||||
# The pidfile holds the WRAPPER's pid: it dies only after exit-code is
|
||||
# written, so "pid gone" always means "run fully finished".
|
||||
# Output is piped through stamp_stream (exported below — wall-clock prefix
|
||||
# per line, so `status` can age the last test-progress event exactly);
|
||||
# pipefail keeps $? xcodebuild's own exit code, not the stamp function's.
|
||||
DETACHER=()
|
||||
command -v setsid >/dev/null 2>&1 && DETACHER=(setsid)
|
||||
( cd "$ROOT" && nohup ${DETACHER[@]+"${DETACHER[@]}"} bash -c '
|
||||
log="$1"; exitf="$2"; shift 2
|
||||
set -o pipefail
|
||||
xcodebuild "$@" 2>&1 < /dev/null | stamp_stream >"$log"
|
||||
echo $? >"$exitf"
|
||||
' _ "$run_dir/xcodebuild.log" "$run_dir/exit-code" "${args[@]}" >/dev/null 2>&1 &
|
||||
echo $! >"$run_dir/pid"
|
||||
)
|
||||
|
||||
# Publish `current` ATOMICALLY. A truncating `>` from two same-second
|
||||
# launches can interleave — the shorter write lands over a longer earlier
|
||||
# one and leaves trailing bytes, corrupting current for every reader.
|
||||
# Write a per-launch temp and rename(2) it into place (same directory ⇒
|
||||
# one filesystem ⇒ atomic).
|
||||
printf '%s\n' "$run_dir" >"$BASE/.current.tmp.$$"
|
||||
mv "$BASE/.current.tmp.$$" "$CURRENT"
|
||||
echo "run dir : $run_dir"
|
||||
echo "pid : $(cat "$run_dir/pid")"
|
||||
echo "scheme : $SCHEME$SUFFIX"
|
||||
if [[ $SERIALIZED == 1 ]]; then echo "parallel: NO (--serialized)"
|
||||
elif (( WORKERS > 0 )); then echo "parallel: YES ($WORKERS workers)"
|
||||
else echo "parallel: default (no flags)"; fi
|
||||
if (( have_only == 0 )); then echo "tests : MuseionTests (default)"
|
||||
else echo "tests : caller -only-testing filter"; fi
|
||||
if [[ $TIMEOUT_ENABLED == 1 ]]; then echo "timeout : ${TEST_TIMEOUT}s per test (max ${timeout_max}s)"; else echo "timeout : DISABLED (--no-test-timeouts)"; fi
|
||||
if [[ ${#FORWARD[@]} -gt 0 ]]; then echo "forwarded: ${FORWARD[*]}"; fi
|
||||
}
|
||||
|
||||
current_run_dir() {
|
||||
[[ -f $CURRENT ]] || die "no run recorded — call 'start' first"
|
||||
local d
|
||||
d="$(cat "$CURRENT")"
|
||||
[[ -d $d ]] || die "recorded run dir missing: $d"
|
||||
printf '%s' "$d"
|
||||
}
|
||||
|
||||
pid_alive() { kill -0 "$1" 2>/dev/null; }
|
||||
|
||||
# --- wedge observability -----------------------------------------------------
|
||||
# Test-progress lines are the test phase's heartbeat. The wrapper stamps every
|
||||
# log line "YYYY-MM-DD HH:MM:SS ", so the last progress line carries an exact
|
||||
# event time; unstamped (legacy) logs fall back to the log mtime for its age.
|
||||
|
||||
# Stamp every stdin line with a local wall-clock prefix "YYYY-MM-DD HH:MM:SS ".
|
||||
# Runs inside the detached wrapper's shell via `export -f` — exported bash
|
||||
# functions travel through nohup to the `bash -c` child, keeping the runner
|
||||
# self-contained (no stamper file whose absence would silently empty the log).
|
||||
# `date` is cached per second: stamps are second-granular anyway, so the fork
|
||||
# cost is one date per wall-clock second of output. The `|| [[ -n $line ]]`
|
||||
# arm keeps a final unterminated line. Verified: bash's printf builtin writes
|
||||
# through per invocation — no stdio buffering — so the log's mtime tracks
|
||||
# real output for stall detection.
|
||||
stamp_stream() {
|
||||
local line stamp='' last_sec=-1
|
||||
while IFS= read -r line || [[ -n $line ]]; do
|
||||
if (( SECONDS != last_sec )); then
|
||||
last_sec=$SECONDS
|
||||
stamp="$(date '+%Y-%m-%d %H:%M:%S')"
|
||||
fi
|
||||
printf '%s %s\n' "$stamp" "$line"
|
||||
done
|
||||
}
|
||||
export -f stamp_stream
|
||||
|
||||
fmt_age() { # seconds → "45s" / "12m 03s"
|
||||
local s="$1"
|
||||
if (( s >= 60 )); then printf '%dm %02ds' $(( s / 60 )) $(( s % 60 ))
|
||||
else printf '%ds' "$s"; fi
|
||||
}
|
||||
|
||||
age_since() { # $1=epoch seconds → age in seconds, clamped at 0 (clock-skew guard)
|
||||
local a=$(( $(date +%s) - $1 ))
|
||||
(( a < 0 )) && a=0
|
||||
printf '%s' "$a"
|
||||
}
|
||||
|
||||
describe_progress_line() { # $1=line → TP_DESC, TP_EPOCH (stamp epoch; empty when unstamped)
|
||||
local rest="$1"
|
||||
TP_DESC=""; TP_EPOCH=""
|
||||
if [[ $rest =~ ^([0-9]{4}-[0-9]{2}-[0-9]{2}\ [0-9]{2}:[0-9]{2}:[0-9]{2})\ (.*)$ ]]; then
|
||||
TP_EPOCH="$(date -j -f '%Y-%m-%d %H:%M:%S' "${BASH_REMATCH[1]}" +%s 2>/dev/null || true)"
|
||||
rest="${BASH_REMATCH[2]}"
|
||||
fi
|
||||
if [[ $rest =~ [Tt]est\ [Ss]uite\ \'([^\']+)\'\ (started|passed|failed) ]]; then
|
||||
TP_DESC="suite '${BASH_REMATCH[1]}' ${BASH_REMATCH[2]}"
|
||||
elif [[ $rest =~ [Tt]est\ [Cc]ase\ \'([^\']+)\'\ (passed|failed) ]]; then
|
||||
TP_DESC="test '${BASH_REMATCH[1]}' ${BASH_REMATCH[2]}"
|
||||
elif [[ $rest =~ [Tt]est\ [Cc]ase\ (.+)\ started\.$ ]]; then
|
||||
TP_DESC="test ${BASH_REMATCH[1]} started"
|
||||
elif [[ $rest =~ [Ss]uite\ ([A-Za-z0-9_.]+)\ (started|passed|failed) ]]; then
|
||||
# Swift Testing verbose (serialized logs, glyph-prefixed): "Suite NAME passed after …"
|
||||
TP_DESC="suite '${BASH_REMATCH[1]}' ${BASH_REMATCH[2]}"
|
||||
elif [[ $rest =~ [Tt]est\ ([A-Za-z0-9_.]+\(\))\ (started|passed|failed) ]]; then
|
||||
# Swift Testing verbose: "Test fnName() started."
|
||||
TP_DESC="test '${BASH_REMATCH[1]}' ${BASH_REMATCH[2]}"
|
||||
elif [[ $rest =~ [Tt]est\ run\ with\ ([0-9]+)\ tests?\ in\ ([0-9]+)\ suites?\ (passed|failed) ]]; then
|
||||
TP_DESC="run (${BASH_REMATCH[1]} tests) ${BASH_REMATCH[3]}"
|
||||
elif [[ $rest == "Testing started" ]]; then
|
||||
TP_DESC="testing started"
|
||||
else
|
||||
TP_DESC="progress: ${rest:0:80}"
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
last_progress_event() { # $1=log → TP_DESC, TP_EPOCH; rc 1 = no progress line yet
|
||||
local line
|
||||
TP_DESC=""; TP_EPOCH=""
|
||||
line="$(grep -iE "test suite|test case|test run with|testing started|suite .* (started|passed|failed)|test .*\(.*\) (started|passed|failed)" "$1" 2>/dev/null | tail -n 1)" || true
|
||||
[[ -n $line ]] || return 1
|
||||
describe_progress_line "$line"
|
||||
}
|
||||
|
||||
# What is IN FLIGHT right now: the suite each host is currently in, plus the
|
||||
# last started per-test line when the log shape provides one (classic/
|
||||
# serialized modes, where a started line has no matching completion). This is
|
||||
# the "last-started test" the wedge report names. Closing rules match the
|
||||
# real log shapes: parallel hosts run suites SEQUENTIALLY and never emit
|
||||
# suite-finished lines — a new suite-start on a host closes its previous one —
|
||||
# while classic/serialized logs close suites explicitly. Ages come from the
|
||||
# wrapper stamps; unstamped legacy logs report "?".
|
||||
open_flights() { # $1=log → lines "kind<TAB>name<TAB>host<TAB>stamp"
|
||||
awk '
|
||||
function stampof(s) {
|
||||
split(s, w, " ")
|
||||
if (w[1] ~ /^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$/ && w[2] ~ /^[0-9][0-9]:[0-9][0-9]:[0-9][0-9]$/) return w[1] " " w[2]
|
||||
return ""
|
||||
}
|
||||
function close_suite(h, n) { if (h in openName && openName[h] == n) { delete openName[h]; delete openStamp[h] } }
|
||||
{
|
||||
st = stampof($0)
|
||||
body = st == "" ? $0 : substr($0, 21)
|
||||
sub(/^[^A-Za-z]*/, "", body) # strip Swift Testing glyph prefixes
|
||||
if (body ~ /^(Test|Suite) /) {
|
||||
split(body, a, "\047") # single-quote split: a[2] = quoted name
|
||||
if (body ~ /^Test [Ss]uite/ && body ~ / started/) {
|
||||
host = (a[3] ~ / on $/) ? a[4] : "-"
|
||||
openName[host] = a[2]; openStamp[host] = st # sequential host: supersedes
|
||||
} else if (body ~ /^Test [Ss]uite/ && body ~ /passed|failed/) {
|
||||
host = (a[3] ~ / on $/) ? a[4] : "-"
|
||||
close_suite(host, a[2])
|
||||
inflDone = 1 # suite finished ⇒ its last started test did too
|
||||
} else if (body ~ /^Suite/ && body ~ / started/) {
|
||||
# Swift Testing verbose (serialized logs): "Suite NAME started."
|
||||
split(body, sw, " "); openName["-"] = sw[2]; openStamp["-"] = st
|
||||
} else if (body ~ /^Suite/ && body ~ /passed|failed/) {
|
||||
split(body, sw, " "); close_suite("-", sw[2]); inflDone = 1
|
||||
} else if (body ~ /^Test/ && body ~ /started\.$/) {
|
||||
# classic quoted cases, Swift "Test case passing …" and "Test fn() started."
|
||||
if (body ~ /^Test [Cc]ase /)
|
||||
inflN = (a[2] != "") ? a[2] : substr(body, 11, length(body) - 19)
|
||||
else {
|
||||
inflN = substr(body, 6); sub(/ started\.$/, "", inflN)
|
||||
}
|
||||
inflS = st; inflDone = 0
|
||||
} else if (body ~ /^Test run with/ && body ~ /passed|failed/) {
|
||||
inflDone = 1 # Swift Testing bundle finished
|
||||
} else if (body ~ /^Test/ && body ~ /passed|failed/) {
|
||||
if (inflN != "" && index(body, inflN)) inflDone = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
END {
|
||||
for (h in openName) if (openName[h] != "") print "suite\t" openName[h] "\t" h "\t" openStamp[h]
|
||||
if (inflN != "" && !inflDone) print "test\t" inflN "\t-\t" inflS
|
||||
}
|
||||
' "$1"
|
||||
}
|
||||
|
||||
# Every live descendant of $1 whose ps state is T (stopped). A SIGSTOPed test
|
||||
# host is the recorded wedge simulation; real machine wedges (#134
|
||||
# testmanagerd/IDE-session family) go silent instead and surface through the
|
||||
# progress-age tiers.
|
||||
stopped_descendants() { # $1=root pid → "pid<TAB>command" lines
|
||||
local root="$1" seen=" " pid st kids k n=0
|
||||
local front=("$root")
|
||||
while (( ${#front[@]} > 0 )); do
|
||||
pid="${front[0]}"
|
||||
front=(${front[@]+"${front[@]:1}"})
|
||||
[[ $seen == *" $pid "* ]] && continue
|
||||
seen+="$pid "
|
||||
(( n += 1 )); (( n > 500 )) && return 0
|
||||
st="$(ps -o stat= -p "$pid" 2>/dev/null | tr -d ' ')"
|
||||
if [[ $st == T* ]]; then
|
||||
printf '%s\t%s\n' "$pid" "$(ps -o command= -p "$pid" 2>/dev/null | cut -c 1-100)"
|
||||
fi
|
||||
kids="$(pgrep -P "$pid" 2>/dev/null || true)"
|
||||
for k in $kids; do front+=("$k"); done
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
summarize_run() {
|
||||
local run_dir="$1"
|
||||
local result="$run_dir/result.xcresult"
|
||||
local exit_code_file="$run_dir/exit-code"
|
||||
[[ -f $exit_code_file ]] || die "run not finished (no exit-code in $run_dir) — use 'status'"
|
||||
local xc_exit
|
||||
xc_exit="$(cat "$exit_code_file")"
|
||||
if [[ ! -d $result ]]; then
|
||||
{
|
||||
echo "full-test.sh: result bundle missing in $run_dir (xcodebuild exit $xc_exit)"
|
||||
echo " A run killed mid-write corrupts the bundle (#177). Rerun; if the first"
|
||||
echo " run wedged, add --serialized (#30/#147)."
|
||||
} >&2
|
||||
exit 2
|
||||
fi
|
||||
xcrun xcresulttool get test-results summary --path "$result" >"$run_dir/summary.json" ||
|
||||
die "xcresulttool could not read $result"
|
||||
python3 - "$run_dir" "$xc_exit" <<'PY'
|
||||
import json, sys
|
||||
|
||||
run_dir, xc_exit = sys.argv[1], int(sys.argv[2])
|
||||
s = json.load(open(f"{run_dir}/summary.json"))
|
||||
def count(key):
|
||||
return int(s.get(key) or 0)
|
||||
passed, failed, skipped = count("passedTests"), count("failedTests"), count("skippedTests")
|
||||
executed = passed + failed # skipped tests were selected, not executed
|
||||
# #31/#134: a filter matching zero executed tests must FAIL, never pass
|
||||
# vacuously (single-name / spaces / backticks match zero Swift Testing tests).
|
||||
if executed == 0:
|
||||
print(f"result : VACUOUS — 0 tests executed, {skipped} skipped (xcodebuild exit {xc_exit}) — summary.json beside the log")
|
||||
print(" Nothing executable matched (#31/#134); fix the -only-testing value.")
|
||||
sys.exit(1)
|
||||
print(f"result : {executed} executed / {passed} passed / {failed} failed / {skipped} skipped "
|
||||
f"(xcodebuild exit {xc_exit}) — summary.json beside the log")
|
||||
sys.exit(0 if xc_exit == 0 and failed == 0 else 1)
|
||||
PY
|
||||
}
|
||||
|
||||
case "$MODE" in
|
||||
start)
|
||||
start_run
|
||||
;;
|
||||
run)
|
||||
start_run
|
||||
# Poll THIS launch's dir, not `current` — a same-second twin launch
|
||||
# repoints `current` at its own run mid-loop (#179).
|
||||
run_dir="$THIS_RUN"
|
||||
pid="$(cat "$run_dir/pid")"
|
||||
echo "polling every ${POLL_SECS}s…"
|
||||
while pid_alive "$pid"; do sleep "$POLL_SECS"; done
|
||||
summarize_run "$run_dir"
|
||||
;;
|
||||
status)
|
||||
run_dir="$(current_run_dir)"
|
||||
pid="$(cat "$run_dir/pid")"
|
||||
if pid_alive "$pid"; then
|
||||
log="$run_dir/xcodebuild.log"
|
||||
elapsed="$(ps -p "$pid" -o etime= | tr -d ' ')"
|
||||
if [[ ! -f $log ]]; then
|
||||
# launch window: wrapper wrote pid but not the first log line yet
|
||||
echo "live : pid $pid, elapsed $elapsed, log not yet written"
|
||||
exit 3
|
||||
fi
|
||||
last_write="$(stat -f '%Sm' -t '%H:%M:%S' "$log")"
|
||||
stall_age=$(( $(date +%s) - $(stat -f '%m' "$log") ))
|
||||
echo "live : pid $pid, elapsed $elapsed, log last written $last_write ($(wc -l < "$log" | tr -d ' ') lines)"
|
||||
tp_desc=""; tp_age=0; have_progress=0
|
||||
if last_progress_event "$log"; then
|
||||
have_progress=1
|
||||
tp_desc="$TP_DESC"
|
||||
tp_when="${TP_EPOCH:-$(stat -f '%m' "$log")}"
|
||||
tp_age="$(age_since "$tp_when")"
|
||||
echo "last : $tp_desc $(fmt_age "$tp_age") ago"
|
||||
fi
|
||||
|
||||
# In-flight work — open suites (parallel logs) and the last started
|
||||
# test without a completion (classic/serialized logs). This is what a
|
||||
# wedge report names; the heartbeat only says when progress last
|
||||
# HAPPENED. Collected once, reused by the display and the warnings.
|
||||
FL_KIND=(); FL_NAME=(); FL_HOST=(); FL_AGE=()
|
||||
fk= fn= fh= fs= fep= fage=
|
||||
while IFS=$'\t' read -r fk fn fh fs; do
|
||||
[[ -n $fk ]] || continue
|
||||
fage="?"
|
||||
if [[ -n $fs ]]; then
|
||||
fep="$(date -j -f '%Y-%m-%d %H:%M:%S' "$fs" +%s 2>/dev/null || true)"
|
||||
[[ -n $fep ]] && fage="$(fmt_age "$(age_since "$fep")")"
|
||||
fi
|
||||
FL_KIND+=("$fk"); FL_NAME+=("$fn"); FL_HOST+=("$fh"); FL_AGE+=("$fage")
|
||||
done < <(open_flights "$log")
|
||||
# Drop in-flight entries whose HOST has exited: parallel logs never emit
|
||||
# suite-finished lines, and a dead test host's suite is finished — only
|
||||
# a live host can be genuinely stuck. Host-less entries ("-", classic
|
||||
# logs) and entries whose host text carries no "(pid)" are kept.
|
||||
fl_keep=()
|
||||
for i in "${!FL_KIND[@]}"; do
|
||||
if [[ ${FL_HOST[$i]} =~ \(([0-9]+)\) ]] && ! pid_alive "${BASH_REMATCH[1]}"; then
|
||||
continue
|
||||
fi
|
||||
fl_keep+=("$i")
|
||||
done
|
||||
if (( ${#fl_keep[@]} != ${#FL_KIND[@]} )); then
|
||||
FL_K=(); FL_N=(); FL_H=(); FL_A=()
|
||||
for i in ${fl_keep[@]+"${fl_keep[@]}"}; do
|
||||
FL_K+=("${FL_KIND[$i]}"); FL_N+=("${FL_NAME[$i]}"); FL_H+=("${FL_HOST[$i]}"); FL_A+=("${FL_AGE[$i]}")
|
||||
done
|
||||
# bash 3.2: unguarded "${FL_K[@]}" on an empty array aborts under set -u
|
||||
# (all hosts exited while the wrapper lives → fl_keep empty → status dies
|
||||
# instead of reporting the live run). Same guard idiom as fl_keep above.
|
||||
FL_KIND=(${FL_K[@]+"${FL_K[@]}"}); FL_NAME=(${FL_N[@]+"${FL_N[@]}"}); FL_HOST=(${FL_H[@]+"${FL_H[@]}"}); FL_AGE=(${FL_A[@]+"${FL_A[@]}"})
|
||||
fi
|
||||
open_desc=""
|
||||
for i in "${!FL_KIND[@]}"; do
|
||||
fdisp="${FL_HOST[$i]}"; fdisp="${fdisp#My Mac - }"
|
||||
[[ $fdisp == "-" ]] && fdisp="" || fdisp=" (host: $fdisp)"
|
||||
open_desc+="${open_desc:+; }${FL_KIND[$i]} '${FL_NAME[$i]}' ${FL_AGE[$i]}$fdisp"
|
||||
done
|
||||
[[ -n $open_desc ]] && echo "open : $open_desc"
|
||||
|
||||
# A STOPPED (state T) descendant is a wedge signature that is
|
||||
# detectable immediately — no stall-min wait. Name the in-flight work
|
||||
# on that host (hosts appear in the log as "(pid)") plus its last
|
||||
# event (#134 machine-wedge family).
|
||||
while IFS=$'\t' read -r wpid wcmd; do
|
||||
[[ -n $wpid ]] || continue
|
||||
wopen=""
|
||||
for i in "${!FL_KIND[@]}"; do
|
||||
if [[ ${FL_HOST[$i]} == *"($wpid)"* ]]; then
|
||||
wopen+="${wopen:+ and }${FL_KIND[$i]} '${FL_NAME[$i]}' ${FL_AGE[$i]}"
|
||||
fi
|
||||
done
|
||||
wlast=""
|
||||
wline="$(grep -F "($wpid)" "$log" 2>/dev/null | tail -n 1)" || true
|
||||
if [[ -n $wline ]]; then
|
||||
describe_progress_line "$wline"
|
||||
wlast="$TP_DESC"
|
||||
if [[ -n $TP_EPOCH ]]; then
|
||||
wage="$(age_since "$TP_EPOCH")"
|
||||
wlast="$wlast $(fmt_age "$wage") ago"
|
||||
fi
|
||||
fi
|
||||
{
|
||||
echo "CANDIDATE WEDGE : descendant pid $wpid is STOPPED (state T) — #134 machine-wedge family.${wopen:+ Stuck in: $wopen.}"
|
||||
[[ -n $wlast ]] && echo " last event on that host: $wlast"
|
||||
[[ -n $wcmd ]] && echo " process: $wcmd"
|
||||
} >&2
|
||||
done < <(stopped_descendants "$pid")
|
||||
|
||||
# No test progress past stall-min while the log is still being written
|
||||
# is NOT silence — advisory only, never the STALLED warning (from
|
||||
# outside, a healthy slow test looks exactly like a wedged worker).
|
||||
if (( have_progress )) && (( tp_age > STALL_MIN * 60 )) && (( stall_age <= STALL_MIN * 60 )); then
|
||||
{
|
||||
echo "CANDIDATE WEDGE : no test progress for $(fmt_age "$tp_age") (last: $tp_desc), but the"
|
||||
echo " log is still being written $(fmt_age "$stall_age") ago — one worker may be"
|
||||
echo " wedged (#134 family); a healthy slow test looks the same."
|
||||
} >&2
|
||||
fi
|
||||
|
||||
# True silence (no writes at all) keeps the stall-min semantics, now
|
||||
# naming the last test event whenever the test phase was reached.
|
||||
if (( stall_age > STALL_MIN * 60 )); then
|
||||
{
|
||||
echo "STALLED : no log output for $(( stall_age / 60 )) min — #134 machine-wedge family."
|
||||
echo " Wait, or kill $pid and rerun with --serialized (#30/#147)."
|
||||
if (( have_progress )); then
|
||||
echo " last test progress: $tp_desc $(fmt_age "$tp_age") ago"
|
||||
fi
|
||||
} >&2
|
||||
fi
|
||||
exit 3
|
||||
fi
|
||||
summarize_run "$run_dir"
|
||||
;;
|
||||
summary)
|
||||
if [[ ${#POSITIONAL[@]} -ge 1 ]]; then run_dir="${POSITIONAL[0]}"; else run_dir="$(current_run_dir)"; fi
|
||||
summarize_run "$run_dir"
|
||||
;;
|
||||
esac
|
||||
Executable
+102
@@ -0,0 +1,102 @@
|
||||
#!/usr/bin/env bash
|
||||
# pre-push — lint gate + no-push-while-testing guard + autofix-tree guard (#190).
|
||||
#
|
||||
# Ports the classis pre-push (classis #679/#684 classes) to Museion:
|
||||
# 1. no push while a full-test run is live — concurrent load flakes the
|
||||
# real-process suites (#30), and pushing mid-verification defeats the run;
|
||||
# 2. lint gate scoped to the push's own Swift files — failing closed on
|
||||
# violations there (the repo tree carries pre-existing findings a bare
|
||||
# repo-wide gate could never clear);
|
||||
# 3. autofix guard — a lint autofix pass that rewrites files AFTER
|
||||
# verification must not ride the push untested: the push fails, the
|
||||
# rewrite gets reviewed and re-verified via scripts/full-test.sh.
|
||||
# Pre-existing unrelated dirt only warns.
|
||||
#
|
||||
# Installed via scripts/install-hooks.sh (git config core.hooksPath scripts/hooks).
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(git rev-parse --show-toplevel)"
|
||||
cd "$ROOT"
|
||||
|
||||
# GUI git clients (Xcode, …) inherit launchd's sparse PATH, which lacks
|
||||
# Homebrew — resolve the lint tools from the standard tool dirs.
|
||||
# Append-only: the caller's PATH keeps priority.
|
||||
for dir in /opt/homebrew/bin /usr/local/bin; do
|
||||
if [[ -d "$dir" && ":$PATH:" != *":$dir:"* ]]; then
|
||||
PATH="$PATH:$dir"
|
||||
fi
|
||||
done
|
||||
export PATH
|
||||
|
||||
# 1. Never push while ANY full-test run is live: concurrent load flakes the
|
||||
# real-process suites (#30), and pushing mid-verification defeats the run.
|
||||
# Concurrent runs each pin their own dir (#190) — `current` only names the
|
||||
# newest, so scan every run dir for a live pid.
|
||||
live=""
|
||||
for d in _build/full-test/*/; do
|
||||
[[ -f "${d}pid" ]] || continue
|
||||
p="$(cat "${d}pid")"
|
||||
kill -0 "$p" 2>/dev/null && live="$live $d(pid $p)"
|
||||
done
|
||||
if [[ -n $live ]]; then
|
||||
echo "pre-push: full-test run(s) live:$live — wait for them, then push." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 2. Lint gate, scoped to THIS PUSH's Swift files (#190): the repo tree
|
||||
# carries pre-existing swiftlint findings (warning noise repo-wide,
|
||||
# error-severity in spike/ experiments and one tests file) — a bare
|
||||
# `swiftlint .` gate can never pass here and would block every push.
|
||||
# The gate is the push's own files; no Swift in the push → nothing to gate.
|
||||
before="$(git status --porcelain)"
|
||||
zero=0000000000000000000000000000000000000000
|
||||
# Default-branch base for NEW-ref scoping: the project's default branch at
|
||||
# origin, as a FULL ref — short names resolve refs/tags/ first, so a fetched
|
||||
# tag "origin/main" would shadow the remote ref. Hardcoded, not $1-derived:
|
||||
# pushes to other remotes or by URL are still scoped against origin/main,
|
||||
# which is correct for this project's delta. A remote with a divergent
|
||||
# default would need its own scoping — add per-remote resolution then.
|
||||
default_ref="refs/remotes/origin/main"
|
||||
swift_files=()
|
||||
while read -r lref lsha rref rsha; do
|
||||
[[ "$lsha" == "$zero" ]] && continue # ref deletion — no content to lint
|
||||
if [[ "$rsha" == "$zero" ]]; then
|
||||
# NEW ref: lint the delta against the default branch, never the whole
|
||||
# tree (pre-existing violations could never clear it). No resolvable
|
||||
# base FAILS CLOSED — a silent skip is a vacuous pass (#31/#134 class).
|
||||
base="$(git merge-base "$lsha" "$default_ref" 2>/dev/null || true)"
|
||||
[[ -n "$base" ]] || {
|
||||
echo "pre-push: no common history with $default_ref — cannot scope the lint gate (orphan branch or missing default ref); refusing." >&2
|
||||
exit 1
|
||||
}
|
||||
range=("$base" "$lsha")
|
||||
else
|
||||
range=("$rsha" "$lsha")
|
||||
fi
|
||||
while IFS= read -r f; do swift_files+=("$f"); done < <(git diff --name-only --diff-filter=ACMR "${range[@]}" -- '*.swift')
|
||||
done
|
||||
# NOTE: lints the WORKING-TREE copies of the pushed files, not the pushed
|
||||
# blobs — a local uncommitted fix lints clean while the broken blob ships.
|
||||
# Inherent to worktree pre-push hooks; blob-lint via `git show` if it bites.
|
||||
if [[ ${#swift_files[@]} -gt 0 ]]; then
|
||||
if ! { swiftformat "${swift_files[@]}" && swiftlint lint --quiet "${swift_files[@]}"; }; then
|
||||
echo "pre-push: linters failed — fix the violations above, then push again." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# 3. Autofix guard: if the pass MODIFIED anything, the pushed commits no
|
||||
# longer match the verified tree. Review, re-verify (scripts/full-test.sh),
|
||||
# commit, push again. Pre-existing unrelated dirt only warns.
|
||||
after="$(git status --porcelain)"
|
||||
if [[ $before != "$after" ]]; then
|
||||
echo "pre-push: linters MODIFIED the working tree:" >&2
|
||||
git status --short >&2
|
||||
echo "Review these, re-run scripts/full-test.sh, commit the results, push again." >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ -n $after ]]; then
|
||||
echo "pre-push: note — unrelated uncommitted changes present (not blocked):" >&2
|
||||
git status --short >&2
|
||||
fi
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
# install-hooks.sh — activate the repo-versioned git hooks (#190).
|
||||
# Idempotent; safe to re-run after cloning or when hooks go missing.
|
||||
# Trust note: versioned hooks mean repo content executes at push time —
|
||||
# install only in repos whose code you already build and run.
|
||||
set -euo pipefail
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
git config core.hooksPath scripts/hooks
|
||||
echo "core.hooksPath -> scripts/hooks (pre-push lint gate active)"
|
||||
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