carlos / platform Public

make test: run checks side by side and split the slow packages' tests

The gate's wall clock was the slowest package, because go test runs a
package's own tests one after another: internal/console took 443 s on
CI's 32 cores and set the whole run.

scripts/test-gate.sh now starts launchctx, vet, gofmt and the tests at
once, and deals the top-level tests of the packages in TEST_SPLIT
(console 8 ways, root 3) across concurrent go test -run processes,
heaviest first by .amadan/test-weights.tsv. Every name from go test
-list lands in exactly one shard, and a shard whose pattern matches
nothing fails the gate. 10-gate runs go build beside make test.

TestClaimConsoleMutationInvariant (200 s of console's 398 s locally)
gets a shard to itself and is now the floor; it is not split or changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev ce9f4c5d1cf7345dd0426fa3e84ddb7de5618d57 parent f54aa2f
6 files changed, +249 −14
  • .amadan/ci.d/10-gate +14 −9
  • .amadan/test-weights.tsv +28 −0
  • AGENTS.md +7 −1
  • Makefile +5 −4
  • scripts/test-gate.sh +158 −0
  • scripts/test-weights.sh +37 −0

CI failed — run details

diff --git a/.amadan/ci.d/10-gate b/.amadan/ci.d/10-gate
index 434170661..b46bff652 100755
--- a/.amadan/ci.d/10-gate
+++ b/.amadan/ci.d/10-gate
@@ -36,16 +36,21 @@
# same target a maintainer runs on a laptop — so CI and the local gate
# cannot drift apart, and a check added to one is a check added to both.
# That is how the gofmt check gets here at all: `make test` runs vet, a
-# repo-wide `gofmt -l .`, then the tests, and this file no longer restates
-# any of it.
+# repo-wide `gofmt -l .` and the tests (side by side, through
+# scripts/test-gate.sh), and this file no longer restates any of it.
#
-# `go build ./...` stays spelled out because `make test` does not do it —
-# the Makefile's test target starts at vet.
+# `go build ./...` stays spelled out because `make test` does not do it.
#
-# -count=1 and -timeout 30m moved to the Makefile's go test line along with
-# the reasoning for them; they are still in force here, just no longer
-# written down twice.
+# -count=1 and -timeout 30m live in scripts/test-gate.sh, on each go test
+# line, with the Makefile's note on why; they are still in force here,
+# just not written down twice.
set -eu
-go build ./...
-exec make test
+# The build runs beside the tests rather than before them: neither needs
+# the other, and the gate's wall clock is whichever finishes last.
+go build ./... &
+build=$!
+status=0
+make test || status=$?
+wait "$build" || status=1
+exit "$status"
diff --git a/.amadan/test-weights.tsv b/.amadan/test-weights.tsv
new file mode 100644
index 000000000..0ad59657c
--- /dev/null
+++ b/.amadan/test-weights.tsv
@@ -0,0 +1,28 @@
+# package test seconds (scripts/test-weights.sh, 2026-10-21)
+github.com/carlosframework/platform/internal/console TestClaimConsoleMutationInvariant 199.7
+github.com/carlosframework/platform/internal/console TestRetiringAnInstancePurgesItsMoveLogRows 9.3
+github.com/carlosframework/platform/internal/console TestDeclaredLostIsLoggedByTheConsole 7.2
+github.com/carlosframework/platform/internal/console TestClaimConsoleMutationInvariantWitnesses 6.6
+github.com/carlosframework/platform/internal/console TestClaimMailPushCountsOutboundEffects 6.4
+github.com/carlosframework/platform/internal/console TestEconomicsPassWritesCensusOnce 5.0
+github.com/carlosframework/platform/internal/console TestCallbackPostsToSelectedHost 3.8
+github.com/carlosframework/platform/internal/console TestClaimDeleteRetryWhileParkingIsNotDone 3.2
+github.com/carlosframework/platform/internal/console TestClaimProbeRunnerDetectsAHollowRequest 3.2
+github.com/carlosframework/platform/internal/console TestClaimPurgeMailRecordRefusesBeforeEffects 2.5
+github.com/carlosframework/platform/internal/console TestDestroyedLocalOnlyLogsNoMoveEvent 2.4
+github.com/carlosframework/platform/internal/console TestSystemOperatorRollsSignedReleases 2.3
+github.com/carlosframework/platform/internal/console TestSystemDoorsRefuseAPreLayoutMoveWhileABoxIsNested 2.2
+github.com/carlosframework/platform/internal/console TestSystemStatusAndRollback 2.2
+github.com/carlosframework/platform/internal/console TestTodaysFleetWithNoLayoutFieldKeepsRollbackAndUpdate 2.2
+github.com/carlosframework/platform/internal/console TestPublishSurvivesDatabasesThatHangOrPanicTheParser 2.1
+github.com/carlosframework/platform/internal/console TestSelectMoveBoxesComposesTheCreateDoorsInputs 1.7
+github.com/carlosframework/platform/internal/console TestClaimPurgeStoreInventoryRefusesBeforeEffects 1.6
+github.com/carlosframework/platform/internal/console TestJ4HostDoorRoutesOnlyMoveKinds 1.2
+github.com/carlosframework/platform/internal/console TestJ4MoveDoorInspectsThenDeclares 1.2
+github.com/carlosframework/platform/internal/console TestJ4MoveDoorStaleSubmission 1.2
+github.com/carlosframework/platform/internal/console TestAPIPromoteRetryResignsThePointer 1.1
+github.com/carlosframework/platform/internal/console TestMoveDoorRefusesAnIneligibleSource 1.1
+github.com/carlosframework/platform/internal/console TestPlan9RollbackCASConflictIsAConflictAndNotRetried 1.1
+github.com/carlosframework/platform/internal/console TestAnIncompletePlacementReadIsNotNoRoom 1.0
+github.com/carlosframework/platform/internal/console TestClaimLossPagesScanProgressSurvivesRestartAndWraps 1.0
+github.com/carlosframework/platform/internal/console TestCreateDoorsRefuseWithNoRoomBeforeRegistering 1.0
diff --git a/AGENTS.md b/AGENTS.md
index cedb4c57c..948b3f691 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -190,9 +190,15 @@ anything.
that used to run this gate was deleted on 2026-08-24, once the amadan
steps covered everything it did and more; `.amadan/README.md` records
what each step descends from, and `.amadan/ci.d/10-gate`'s header
- records why the switch was safe. `10-gate` is `go build ./...` then
+ records why the switch was safe. `10-gate` is `go build ./...` beside
`make test`, so CI and what you run locally are one definition rather
than two that can drift.
+- **`make test` splits the slowest packages' tests across processes**
+ (`scripts/test-gate.sh`, `TEST_SPLIT`). Each shard is its own process,
+ so a test must not depend on another top-level test having run first
+ in the same process. Shards are dealt by `.amadan/test-weights.tsv`;
+ refresh it when the gate's shard times in the CI log drift far apart
+ (its header says how). A test missing from it still runs.
- **CI is triggered by a push to amadan, not by GitHub.** Nothing on
GitHub runs a build. A branch that exists only on GitHub has been gated
by exactly nothing. Read a branch's verdict with
diff --git a/Makefile b/Makefile
index 8228319ee..ed614e3b6 100644
--- a/Makefile
+++ b/Makefile
@@ -11,11 +11,12 @@ GOARCH ?=
# -count=1 is CLAUDE.md's rule: never satisfy the gate from a cached pass.
# The 30m timeout is above Go's 10m default because the root package's e2e
# tests compile the carlos binary many times over.
+#
+# scripts/test-gate.sh runs launchctx, vet, gofmt and the tests at once,
+# and splits the slowest packages' tests across processes. TEST_SPLIT
+# overrides which packages and how many ways (TEST_SPLIT= runs none split).
test:
- cd launchctx && go vet ./... && go test ./... -count=1
- go vet ./...
- @fmt_out=$$(gofmt -l .); if [ -n "$$fmt_out" ]; then echo "gofmt needed:"; echo "$$fmt_out"; exit 1; fi; echo "gofmt -l .: clean"
- go test ./... -count=1 -timeout 30m
+ scripts/test-gate.sh
build:
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags "$(LDFLAGS)" -o carlos .
diff --git a/scripts/test-gate.sh b/scripts/test-gate.sh
new file mode 100755
index 000000000..d6720758d
--- /dev/null
+++ b/scripts/test-gate.sh
@@ -0,0 +1,158 @@
+#!/bin/sh
+# The test half of `make test`, and so of CI: `.amadan/ci.d/10-gate` runs
+# `make test`, which runs this. Still one definition.
+#
+# What it checks is what `make test` always checked: launchctx's vet and
+# tests, `go vet ./...`, a repo-wide `gofmt -l .`, and every test in every
+# package with -count=1. What changed is the shape of the run.
+#
+# The gate's wall clock was the slowest single package, because Go runs
+# packages side by side but a package's own tests one after another.
+# internal/console took about 440 s on CI's 32 cores while most of them
+# sat idle, and the root package was not far behind. So:
+#
+# - vet, gofmt, launchctx and the tests all start at once instead of
+# vet finishing before the first test starts;
+# - the packages named in TEST_SPLIT have their top-level tests dealt
+# across several `go test -run` processes running concurrently.
+#
+# The deal is by measured weight (.amadan/test-weights.tsv, longest first
+# onto the least-loaded shard), so one slow test gets a shard to itself
+# rather than dragging its neighbours along. A test missing from the
+# weights file still runs; it is only dealt as if it were short. Stale
+# weights cost balance, never coverage.
+#
+# THE FENCE. Each split package's test list comes from `go test -list`,
+# every name on it goes to exactly one shard, and a shard whose -run
+# pattern matches nothing fails the gate. A test can therefore be added,
+# renamed or removed without touching this file, and no edit to the
+# deal can drop one silently.
+#
+# Shards are separate processes, so tests that leaned on running in the
+# same process as some other test (package state one test leaves for the
+# next) can surface here. That is a bug in the test, not in the split.
+set -eu
+
+: "${TEST_SPLIT=./internal/console=8 .=3}"
+weights=$(pwd)/.amadan/test-weights.tsv
+
+out=$(mktemp -d "${TMPDIR:-/tmp}/carlos-gate-XXXXXX")
+trap 'rm -rf "$out"' EXIT INT TERM
+
+names=""
+# A failure found before any test runs (a package that will not list, a
+# deal that lost a test) is reported as a job of its own, so the jobs
+# already running still finish and print rather than being cut off.
+fail_job() {
+ names="$names $1"
+ printf '%s\n' "$2" >>"$out/$1.log"
+ echo 1 >"$out/$1.rc"
+ echo 0 >"$out/$1.secs"
+}
+start() {
+ start_name=$1
+ shift
+ names="$names $start_name"
+ (
+ set +e
+ t0=$(date +%s)
+ "$@" >"$out/$start_name.log" 2>&1
+ echo $? >"$out/$start_name.rc"
+ echo $(($(date +%s) - t0)) >"$out/$start_name.secs"
+ ) &
+}
+
+start launchctx sh -c 'cd launchctx && go vet ./... && go test ./... -count=1'
+start vet go vet ./...
+start gofmt sh -c 'fmt_out=$(gofmt -l .); if [ -n "$fmt_out" ]; then echo "gofmt needed:"; echo "$fmt_out"; exit 1; fi; echo "gofmt -l .: clean"'
+
+# Everything not split runs as one ordinary `go test`. Packages are named
+# by import path, so match TEST_SPLIT's directories through `go list`.
+split_paths=""
+for spec in $TEST_SPLIT; do
+ split_paths="$split_paths $(go list "${spec%=*}")"
+done
+rest=$(go list ./... | while read -r p; do
+ case " $split_paths " in
+ *" $p "*) ;;
+ *) echo "$p" ;;
+ esac
+done)
+# shellcheck disable=SC2086 # one word per package, on purpose
+start rest go test -count=1 -timeout 30m $rest
+
+for spec in $TEST_SPLIT; do
+ dir=${spec%=*}
+ shards=${spec#*=}
+ pkg=$(go list "$dir")
+ tag=$(echo "$dir" | sed 's|^\./||; s|^\.$|root|; s|/|_|g')
+
+ # -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
+ cp "$out/list-$tag.raw" "$out/$tag.log"
+ fail_job "$tag" "could not list the tests in $pkg"
+ continue
+ fi
+ grep -E '^(Test|Example|Fuzz)' "$out/list-$tag.raw" | sort -u >"$out/list-$tag" || true
+ listed=$(wc -l <"$out/list-$tag")
+ if [ "$listed" -eq 0 ]; then
+ fail_job "$tag" "go test -list found no tests in $pkg, which is not believable"
+ continue
+ fi
+
+ # Longest-processing-time first: heaviest test onto the least-loaded
+ # shard. Unweighted tests count as 0.2 s.
+ awk -v pkg="$pkg" -v n="$shards" -F '\t' '
+ FILENAME == ARGV[1] { if ($1 == pkg) w[$2] = $3; next }
+ { print (($0 in w) ? w[$0] : 0.2) "\t" $0 }
+ ' "$weights" "$out/list-$tag" | sort -t "$(printf '\t')" -k1,1gr -k2,2 |
+ awk -v n="$shards" -F '\t' '
+ {
+ best = 0
+ for (i = 1; i < n; i++) if (load[i] < load[best]) best = i
+ load[best] += $1
+ print best "\t" $2
+ }
+ ' >"$out/deal-$tag"
+
+ dealt=$(wc -l <"$out/deal-$tag")
+ if [ "$dealt" -ne "$listed" ]; then
+ fail_job "$tag" "dealt $dealt of $listed tests in $pkg"
+ continue
+ fi
+
+ i=0
+ while [ "$i" -lt "$shards" ]; do
+ pattern=$(awk -v i="$i" -F '\t' '$1 == i { printf "%s%s", sep, $2; sep = "|" }' "$out/deal-$tag")
+ if [ -n "$pattern" ]; then
+ start "$tag@$i" go test -count=1 -timeout 30m -run "^($pattern)\$" "$dir"
+ fi
+ i=$((i + 1))
+ done
+done
+
+wait
+
+failed=""
+for name in $names; do
+ rc=$(cat "$out/$name.rc")
+ echo "=== $name ($(cat "$out/$name.secs") s)"
+ cat "$out/$name.log"
+ case $name in
+ *@*)
+ if grep -q 'no tests to run' "$out/$name.log"; then
+ echo "--- $name matched no tests; its -run pattern has drifted from the list"
+ rc=1
+ fi
+ ;;
+ esac
+ [ "$rc" -eq 0 ] || failed="$failed $name"
+done
+
+if [ -n "$failed" ]; then
+ echo
+ echo "FAILED:$failed"
+ exit 1
+fi
diff --git a/scripts/test-weights.sh b/scripts/test-weights.sh
new file mode 100755
index 000000000..5b237131f
--- /dev/null
+++ b/scripts/test-weights.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+# Rewrites .amadan/test-weights.tsv, the measured weights scripts/test-gate.sh
+# deals the split packages' tests by.
+#
+# go test -count=1 -json ./internal/console/ >console.json
+# go test -count=1 -json . >root.json
+# scripts/test-weights.sh console.json root.json
+#
+# Measure on a quiet machine with the temp root on tmpfs, as CI has it, or
+# the fsync-heavy tests weigh several times what they do there. Only
+# top-level tests of a second or more are kept; everything else is dealt
+# as short, which is what it is.
+set -eu
+
+[ $# -gt 0 ] || {
+ echo "usage: scripts/test-weights.sh go-test-json-file..." >&2
+ exit 2
+}
+
+out=.amadan/test-weights.tsv
+{
+ printf '# package\ttest\tseconds (scripts/test-weights.sh, %s)\n' "$(date -u +%Y-%m-%d)"
+ cat "$@" | awk '
+ /"Action":"(pass|fail)"/ && /"Test":"/ {
+ if (!match($0, /"Test":"[^"]*"/)) next
+ test = substr($0, RSTART + 8, RLENGTH - 9)
+ if (index(test, "/")) next
+ if (!match($0, /"Package":"[^"]*"/)) next
+ pkg = substr($0, RSTART + 11, RLENGTH - 12)
+ if (!match($0, /"Elapsed":[0-9.]+/)) next
+ secs = substr($0, RSTART + 10, RLENGTH - 10) + 0
+ if (secs >= 1) printf "%s\t%s\t%.1f\n", pkg, test, secs
+ }
+ ' | sort -t "$(printf '\t')" -k1,1 -k3,3gr
+} >"$out.tmp"
+mv "$out.tmp" "$out"
+echo "wrote $out: $(($(wc -l <"$out") - 1)) weighted tests"