#!/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 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 "kindnamehoststamp" 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 → "pidcommand" 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