carlos / platform Public

test-gate: go list outside a pipeline, pgrep required (Astra round 2)

P1: rest came from `go list ./... | while ...`, whose status is the
loop's, so a go list that failed or was killed halfway handed on a short
package list and the gate went green without those packages. go list now
runs on its own under set -e, an empty result fails, and an empty rest is
not run (go test with no packages tests the current directory).

P2: without pgrep, a stopped gate silently orphaned its jobs; it now
refuses to start. Discovery (go test -list) runs in the background and is
waited on, so a signal reaches the trap at once. Only a job that has not
yet written its .secs file is signalled, so a finished job's recycled pid
is never sent TERM on this shared machine.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 58c3c0c0ddb4a355f8f2219c9b79fe20eb8216cb parent b3ede36
1 file changed, +51 −12
  • .amadan/test-gate.sh +51 −12

CI cancelled — superseded by a newer push — run details

diff --git a/.amadan/test-gate.sh b/.amadan/test-gate.sh
index 35fa13ee8..54cac6bce 100755
--- a/.amadan/test-gate.sh
+++ b/.amadan/test-gate.sh
@@ -65,9 +65,20 @@ done
# an interrupt, a TERM from the runner, and an early exit while jobs are
# already running. Process groups (set -m) would be simpler, but dash
# turns job control off without a terminal, which is how CI runs it, so
-# each job's tree is walked with pgrep -P instead.
+# each job's tree is walked with pgrep -P instead, and the gate refuses
+# to start without it rather than leave orphans when it is stopped.
+if ! command -v pgrep >/dev/null 2>&1; then
+ echo "pgrep is required: without it a stopped gate cannot stop its jobs" >&2
+ exit 2
+fi
out=$(mktemp -d "${TMPDIR:-/tmp}/carlos-gate-XXXXXX")
-pids=""
+# started holds name:pid for every job started; discovery is the one
+# foreground command in flight, if any. A job is only signalled while its
+# .secs file (the last thing it writes) is absent, so a finished job's
+# pid, which the system may since have handed to someone else's process
+# on this shared machine, is never touched.
+started=""
+discovery=""
kill_tree() {
for child in $(pgrep -P "$1" 2>/dev/null); do
kill_tree "$child"
@@ -75,8 +86,13 @@ kill_tree() {
kill -TERM "$1" 2>/dev/null || true
}
stop_jobs() {
- for pid in $pids; do
- kill_tree "$pid"
+ if [ -n "$discovery" ]; then
+ kill_tree "$discovery"
+ fi
+ for job in $started; do
+ if [ ! -e "$out/${job%:*}.secs" ]; then
+ kill_tree "${job##*:}"
+ fi
done
wait 2>/dev/null || true
rm -rf "$out"
@@ -105,7 +121,18 @@ start() {
echo $? >"$out/$start_name.rc"
echo $(($(date +%s) - t0)) >"$out/$start_name.secs"
) &
- pids="$pids $!"
+ started="$started $start_name:$!"
+}
+
+# Runs one discovery command in the background and waits for it, so an
+# interrupt reaches the trap at once instead of after a compile.
+discover() {
+ "$@" &
+ discovery=$!
+ discover_rc=0
+ wait "$discovery" || discover_rc=$?
+ discovery=""
+ return "$discover_rc"
}
start launchctx sh -c 'cd launchctx && go vet ./... && go test ./... -count=1'
@@ -118,14 +145,26 @@ split_paths=""
for spec in $TEST_SPLIT; do
split_paths="$split_paths $(go list "${spec%=*}")"
done
-rest=$(go list ./... | while read -r p; do
+# go list runs on its own, not in a pipeline: a pipeline's status is its
+# last command's, and a go list that failed halfway would hand on a short
+# package list with a zero status.
+all=$(go list ./...)
+if [ -z "$all" ]; then
+ echo "go list ./... found no packages" >&2
+ exit 1
+fi
+rest=""
+for p in $all; do
case " $split_paths " in
*" $p "*) ;;
- *) echo "$p" ;;
+ *) rest="$rest $p" ;;
esac
-done)
-# shellcheck disable=SC2086 # one word per package, on purpose
-start rest go test -count=1 -timeout 30m $rest
+done
+# With no packages left, go test would test the current directory instead.
+if [ -n "$rest" ]; then
+ # shellcheck disable=SC2086 # one word per package, on purpose
+ start rest go test -count=1 -timeout 30m $rest
+fi
for spec in $TEST_SPLIT; do
dir=${spec%=*}
@@ -136,7 +175,7 @@ for spec in $TEST_SPLIT; do
# -list compiles the test binary, which the shards below then reuse
# from the build cache. Benchmarks are listed but never run by a plain
# `go test`, so they are left out of the deal.
- if ! go test -count=1 -list '.*' "$dir" >"$out/list-$tag.raw" 2>&1; then
+ if ! discover go test -count=1 -list '.*' "$dir" >"$out/list-$tag.raw" 2>&1; then
cp "$out/list-$tag.raw" "$out/$tag.log"
fail_job "$tag" "could not list the tests in $pkg"
continue
@@ -185,7 +224,7 @@ for spec in $TEST_SPLIT; do
done
wait
-pids=""
+started=""
failed=""
for name in $names; do