oficina / equipo Public

ci: rebalance the check shards; make lanes-check guards the lanes

The check step took as long as headless-rest, 154 to 158 s on a cold
run. Per-test times from a cold run that printed every test and subtest
(scratch branch ci-rebalance-times) set the new split:

- headless: 25 TestHeadless subtests and two token tests move from
  headless-rest (153 s) into the five other headless lanes; each lane
  is now 67 to 77 s of tests.
- thintest (105 s, all serial) splits into thintest-contract
  (^TestContract, 57 s) and thintest (48 s). One more shard: 20-check@29.
- equipotest: the lanes take letters by serial time (the long tests are
  parallel and wait together): A-D and Q, E-P, R, the rest.
- browser: a new browser-headless-connections lane takes the connections
  and paste-box drives; browser-headless-chat, -work and -rest give up
  tests to it (79 s each). browser-thintest goes: thintest's browser
  tests join plan3test's in browser-rest, whose shard ran 5 s.

scripts/ci-test.py check (make lanes-check, in the static checks shard)
fails when a lane names a test, subtest or package that is gone, two
lanes take the same test, a split package has no lane for the rest, a
browser lane's pattern takes a plain test, or 20-check@N is not the
lane count. TestLanesRunEveryTestOnce holds its rules. The quarantine
report now prints each test's time and each group's wall time.

Retry-once, FLAKE lines and the quarantine are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev aab990a472cf4805bcc80afbd86aea6c3dcfeaff parent 70e1e85
6 files changed, +284 −56
  • .amadan/ci.d/{20-check@28 => 20-check@29} +6 −5
  • Makefile +10 −2
  • docs/superpowers/plans/HOSTED-CI-PROGRESS.md +6 −2
  • internal/equipotest/foundation_test.go +1 −1
  • internal/testci/lanes_test.go +98 −0
  • scripts/ci-test.py +163 −46

CI passed — run details

diff --git a/.amadan/ci.d/20-check@28 b/.amadan/ci.d/20-check@29
similarity index 70%
rename from .amadan/ci.d/20-check@28
rename to .amadan/ci.d/20-check@29
index 8bd34ec1..fa9d6d3f 100755
--- a/.amadan/ci.d/20-check@28
+++ b/.amadan/ci.d/20-check@29
@@ -1,13 +1,14 @@
#!/bin/sh
-# Everything but perf, as 28 shards side by side; AMADAN_SHARD picks one
-# (scripts/ci-test.py: LANES, BROWSER_LANES, then EXTRA_SHARDS). Seventeen
-# test lanes of about a minute each. Then five browser lanes: the
+# Everything but perf, as 29 shards side by side; AMADAN_SHARD picks one
+# (scripts/ci-test.py: LANES, BROWSER_LANES, then EXTRA_SHARDS). Eighteen
+# test lanes of 80 s at most on a cold run. Then five browser lanes: the
# -tags browser tests, each driving the pinned headless Chromium
# (scripts/ci-chromium.json). Then the quarantine: known flaky tests
# (scripts/ci-quarantine.txt), kept out of the lanes. Then runner-host: the exact bubblewrap build,
# the pinned programs, real namespaces and the cgroup move, uncached. Then
-# the static checks: build, vet, format, budgets, references and the
-# migration check; staticcheck; govulncheck; gitleaks.
+# the static checks: build, vet, format, budgets, references, the lanes
+# (every test in exactly one) and the migration check; staticcheck;
+# govulncheck; gitleaks.
#
# A failed test is retried once where it failed. A pass on the retry stays
# green and prints "FLAKE <package>:<test> <lane> <commit> <seconds>s
diff --git a/Makefile b/Makefile
index f12af546..5f2e7679 100644
--- a/Makefile
+++ b/Makefile
@@ -27,7 +27,7 @@ RUNNER_RELEASE_DIR = releases/equipo-runner-linux-amd64-$(RELEASE_VERSION)
# and a suite running beside it would be measured too.
.NOTPARALLEL:
-.PHONY: build release test test-lane ci-shard ci-compile test-quarantine vet fmt-check staticcheck govulncheck gitleaks budget perf migration-check runner-adapter-test runner-namespace-test runner-host runner-dead-references ci
+.PHONY: build release test test-lane ci-shard ci-compile lanes-check test-quarantine vet fmt-check staticcheck govulncheck gitleaks budget perf migration-check runner-adapter-test runner-namespace-test runner-host runner-dead-references ci
RASTRILLO := go run amadan.net/rastrillo/rastrillo/cmd/rastrillo
@@ -130,6 +130,14 @@ ci-compile:
test-quarantine:
python3 scripts/ci-test.py quarantine
+# lanes-check fails when the lanes do not run every test exactly once: a
+# lane names a test or package that no longer exists, two lanes take the
+# same test, or a split package has no lane for the tests nobody names.
+# It also holds the shard count of .amadan/ci.d/20-check@N to the lanes.
+# It reads the test files every time, so it runs on CI uncached.
+lanes-check:
+ python3 scripts/ci-test.py check
+
# The perf lane: every GET screen at 150ms to first byte, cold boot at
# 500ms. Serial (-p 1 -parallel 1) and uncached (-count=1), because a
# measurement taken beside other work, or replayed from a cache, is not
@@ -235,7 +243,7 @@ runner-host: runner-adapter-test runner-namespace-test
# fails the build the moment models.go and migrations/ disagree,
# instead of at boot on whatever machine notices next. If the app
# declares manifest resources, also add: rastrillo generate --check
-ci: copy-release-check runner-dead-references build vet fmt-check staticcheck govulncheck gitleaks budget test test-quarantine runner-host migration-check perf
+ci: copy-release-check runner-dead-references lanes-check build vet fmt-check staticcheck govulncheck gitleaks budget test test-quarantine runner-host migration-check perf
.PHONY: copy-release-check direct-release-check release-runner runner-prerequisites
copy-release-check:
diff --git a/docs/superpowers/plans/HOSTED-CI-PROGRESS.md b/docs/superpowers/plans/HOSTED-CI-PROGRESS.md
index 27f19a2c..396f7f4a 100644
--- a/docs/superpowers/plans/HOSTED-CI-PROGRESS.md
+++ b/docs/superpowers/plans/HOSTED-CI-PROGRESS.md
@@ -101,7 +101,7 @@ between two delegated cgroups. So:
| `00-prepare` | fetch and verify the pinned programs and Chromium, pull the image, deepen the clone, set file times |
| `05-copy` | `make copy-release-check`: copy still marked COPY REVIEW REQUIRED fails here, not at the staging build |
| `10-compile` | compile every package and its tests once (the browser packages with `-tags browser` too), link no test; build rastrillo and the static check tools |
-| `20-check@28` | 17 test lanes, 5 browser lanes, the quarantine, `runner-host` (bubblewrap build, pinned codex, namespaces, cgroup move, uncached), and the static checks in four groups; a failed test is retried once |
+| `20-check@29` | 18 test lanes, 5 browser lanes, the quarantine, `runner-host` (bubblewrap build, pinned codex, namespaces, cgroup move, uncached), and the static checks in four groups (with `make lanes-check`); a failed test is retried once |
| `50-perf` | alone, it measures time |
| `90-cache` | report and trim the caches |
@@ -129,7 +129,11 @@ side, so everything that can run together is one step.
To rebalance: each shard's log ends with its time and its five slowest
tests; move names between lanes of a package, keep `20-check@N` equal to
-the lanes plus the extra shards (a test checks the count).
+the lanes plus the extra shards. `make lanes-check` (in the static checks
+shard) fails when a lane names a test or package that is gone, two lanes
+take the same test, a split package has no lane for the rest, or the
+count is wrong. "The rebalance of 2026-11-12" below says how to get every
+test's and subtest's time, which the five slowest do not give.
## Before (docs-t1)
diff --git a/internal/equipotest/foundation_test.go b/internal/equipotest/foundation_test.go
index 4b09c5fd..73311d15 100644
--- a/internal/equipotest/foundation_test.go
+++ b/internal/equipotest/foundation_test.go
@@ -175,7 +175,7 @@ func TestFoundationMigratesTwice(t *testing.T) {
// on a runner host, so the fake make sees what each step asks for.
func TestCIGateSteps(t *testing.T) {
root := filepath.Join("..", "..")
- want := []string{"copy-release-check", "build", "vet", "fmt-check", "staticcheck", "govulncheck", "gitleaks", "budget", "test", "test-quarantine", "runner-host", "runner-dead-references", "migration-check", "perf"}
+ want := []string{"copy-release-check", "build", "vet", "fmt-check", "staticcheck", "govulncheck", "gitleaks", "budget", "test", "test-quarantine", "runner-host", "runner-dead-references", "lanes-check", "migration-check", "perf"}
sort.Strings(want)
// The step scripts run outside this process; their bytes are inputs.
testci.Files(t, filepath.Join(root, ".amadan"), filepath.Join(root, "scripts", "ci-test.py"), filepath.Join(root, "scripts", "ci-box.py"))
diff --git a/internal/testci/lanes_test.go b/internal/testci/lanes_test.go
new file mode 100644
index 00000000..874968f3
--- /dev/null
+++ b/internal/testci/lanes_test.go
@@ -0,0 +1,98 @@
+package testci_test
+
+import (
+ "encoding/json"
+ "strings"
+ "testing"
+
+ "amadan.net/oficina/equipo/internal/testci"
+)
+
+// The lanes split packages by test name, and every test must run in
+// exactly one of them: scripts/ci-test.py check (make lanes-check, in the
+// static checks shard) reads the real test files on CI. This holds its
+// rules on made-up packages: each broken layout names what is wrong, and
+// the good one passes.
+func TestLanesRunEveryTestOnce(t *testing.T) {
+ testci.Files(t, "../../scripts/ci-test.py")
+ inventory := map[string]any{
+ "packages": []string{"./a", "./b", "./c"},
+ "tests": map[string][]string{
+ "./a": {"TestAlpha", "TestBeta", "TestScenarios"},
+ "./b": {"TestOne", "TestTwo"},
+ "./c": {"TestC"},
+ },
+ "sources": map[string]string{"./a": `{"first", run}, {"second", run}`},
+ }
+ good := [][]any{
+ {"a-scenarios", []string{"./a"}, []string{"TestScenarios/first"}},
+ {"a-more", []string{"./a"}, []string{"^TestA", "TestScenarios/second"}},
+ {"a-rest", []string{"./a"}, nil},
+ {"b", []string{"./b"}, nil},
+ {"rest", nil, nil},
+ }
+ with := func(name string, lane []any) [][]any {
+ var out [][]any
+ for _, l := range good {
+ if l[0] != name {
+ out = append(out, l)
+ }
+ }
+ if lane != nil {
+ out = append(out, lane)
+ }
+ return out
+ }
+ for _, c := range []struct {
+ name string
+ lanes [][]any
+ want string // "" is no problem
+ }{
+ {"good", good, ""},
+ {"the same subtest in two lanes", with("a-more", []any{"a-more", []string{"./a"}, []string{"^TestA", "TestScenarios/first"}}),
+ "./a TestScenarios/first runs in more than one lane: a-more, a-scenarios"},
+ {"a whole test beside its subtest", with("a-more", []any{"a-more", []string{"./a"}, []string{"TestScenarios"}}),
+ "./a TestScenarios runs in more than one lane: a-more whole; a-scenarios some of it"},
+ {"two patterns take one test", with("a-more", []any{"a-more", []string{"./a"}, []string{"^Test[A-Z]"}}),
+ "./a TestScenarios runs in more than one lane"},
+ {"a renamed test", with("a-more", []any{"a-more", []string{"./a"}, []string{"TestGamma"}}),
+ "lane a-more: TestGamma names no test in ./a"},
+ {"a renamed subtest", with("a-scenarios", []any{"a-scenarios", []string{"./a"}, []string{"TestScenarios/third"}}),
+ "lane a-scenarios: ./a has no subtest 'third' of TestScenarios"},
+ {"a pattern that takes nothing", with("a-more", []any{"a-more", []string{"./a"}, []string{"^TestZ"}}),
+ "lane a-more: ^TestZ names no test in ./a"},
+ {"a split package with nowhere for the rest", with("a-rest", nil),
+ "./a: want one lane that names no tests and runs what the others do not; have []"},
+ {"a package in two whole lanes", with("", []any{"b-again", []string{"./b"}, nil}),
+ "./b: want one lane that names no tests and runs what the others do not; have ['b', 'b-again']"},
+ {"a deleted package", with("", []any{"gone", []string{"./gone"}, nil}),
+ "lane gone: no package ./gone (renamed or deleted?)"},
+ {"tests across packages", with("b", []any{"b", []string{"./b", "./c"}, []string{"TestOne"}}),
+ "lane b names tests, so it must name one package"},
+ {"no lane for the other packages", with("rest", nil),
+ "want one lane that names no package"},
+ } {
+ out := python(t, nil, "-c", loadCITest+`
+args = json.loads(sys.argv[1])
+lanes = [tuple(l) for l in json.loads(sys.argv[2])]
+print(json.dumps(m.lane_problems(lanes, set(args["packages"]), args["tests"], args["sources"])))
+`, mustJSON(t, inventory), mustJSON(t, c.lanes))
+ var problems []string
+ if err := json.Unmarshal([]byte(out), &problems); err != nil {
+ t.Fatalf("%s: %v: %s", c.name, err, out)
+ }
+ if c.want == "" {
+ if len(problems) != 0 {
+ t.Errorf("%s: want no problems, got %q", c.name, problems)
+ }
+ continue
+ }
+ found := false
+ for _, p := range problems {
+ found = found || strings.Contains(p, c.want)
+ }
+ if !found {
+ t.Errorf("%s: want a problem containing %q, got %q", c.name, c.want, problems)
+ }
+ }
+}
diff --git a/scripts/ci-test.py b/scripts/ci-test.py
index 1e3a2d48..0f0d943c 100755
--- a/scripts/ci-test.py
+++ b/scripts/ci-test.py
@@ -9,6 +9,7 @@
scripts/ci-test.py retried LANE ARGS... go test ARGS, with the one retry
scripts/ci-test.py lanes print each lane and its packages
scripts/ci-test.py browser print each package's browser tests
+ scripts/ci-test.py check every test in exactly one lane (make lanes-check)
The slow packages each have a lane of their own and "rest" holds every
other package. The browser tests (files built only with -tags browser)
@@ -64,26 +65,34 @@ TIMEOUT = "15m"
# and anything starting with ^ is a regular expression over test names.
# A lane of the same package without tests runs everything the others do
# not name, so a new test always lands somewhere. Split a package when its
-# lane is the slowest shard, by the times its shard prints; the measured
-# seconds beside each lane are test time on a 32 CPU hosted machine.
-HEADLESS, RUNNER, EQUIPOTEST = "./internal/headless", "./internal/runner", "./internal/equipotest"
+# lane is the slowest shard, by the times its shard prints. The seconds
+# beside each lane are its tests' time on a cold run on a 32 CPU hosted
+# machine (2026-11-12, every shard started on an empty cache); a shard
+# takes about 3 s more, and a LATE one its wait too. `scripts/ci-test.py
+# check` (make lanes-check, in the static checks) fails when a lane names
+# a test or package that does not exist, two lanes take the same test, or
+# a package lacks the lane that runs what the others do not name.
+HEADLESS, RUNNER, EQUIPOTEST, THINTEST = "./internal/headless", "./internal/runner", "./internal/equipotest", "./internal/thintest"
LANES = [
- ("headless-work", [HEADLESS], ["TestHeadless/4c_rebase", "TestHeadless/4b_ask", "TestHeadless/4c_checks_card", "TestHeadless/4_step_crash"]), # 54
- ("headless-review", [HEADLESS], ["TestHeadless/4_review", "TestHeadless/2b_access", "TestHeadless/runner_crash", "TestHeadless/2b_first_message", "TestHeadless/4_checks_honest", "TestHeadless/7_stream_resume", "TestHeadless/2b_notebook", "TestHeadless/2b_move_in"]), # 50
- ("headless-connections", [HEADLESS], ["TestHeadlessConnections"]), # 52 without the quarantined
- ("headless-mac", [HEADLESS], ["TestMacWorker", "TestHeadlessAttachments", "TestHeadlessPrewarm"]), # 43
- ("headless-guards", [HEADLESS], ["TestHeadlessCopyRotation", "TestHeadlessPolicyGuards", "TestHeadlessRunnerKillLeavesNoCopies", "TestHeadlessNewHouseRuleStartsFresh"]), # 41
- ("headless-rest", [HEADLESS], None), # 52 of TestHeadless and the small ones
- ("thintest", ["./internal/thintest"], None), # 47
- ("runner-thin", ["./internal/runner/thin"], None), # 38
- ("runner-bug", [RUNNER], ["TestDirectBugWorkflow", "TestEnrolKeepsTheRole"]), # 65
- ("runner-plans", [RUNNER], ["TestPlanWorkflowCandidateOrder", "TestPlanWorkflowFeature", "TestCoordinatorRecoveryCallRefusalKeepsServing", "TestCoordinatorRefusalMatrix"]), # 54
- ("runner-rest", [RUNNER], None), # 36
- ("equipotest-a", [EQUIPOTEST], ["^Test[A-C]"]), # the whole package: 183
- ("equipotest-d", [EQUIPOTEST], ["^Test[D-P]"]),
- ("equipotest-r", [EQUIPOTEST], ["^TestR"]),
- ("equipotest-rest", [EQUIPOTEST], None),
- ("plan3test", ["./internal/plan3test"], None), # 35
+ ("headless-work", [HEADLESS], ["TestHeadless/4c_rebase", "TestHeadless/4b_ask", "TestHeadless/4c_checks_card", "TestHeadless/4_step_crash"]), # 75
+ ("headless-review", [HEADLESS], ["TestHeadless/4_review", "TestHeadless/2b_access", "TestHeadless/runner_crash", "TestHeadless/2b_first_message", "TestHeadless/4_checks_honest", "TestHeadless/7_stream_resume", "TestHeadless/2b_notebook", "TestHeadless/2b_move_in", "TestHeadless/2b_desk_failure", "TestHeadless/cancel"]), # 76
+ ("headless-connections", [HEADLESS], ["TestHeadlessConnections", "TestHeadlessTokenPasteEndToEnd", "TestHeadlessTokenConnection"]), # 76 without the quarantined
+ ("headless-mac", [HEADLESS], ["TestMacWorker", "TestHeadlessAttachments", "TestHeadlessPrewarm", "TestHeadless/1_first_token", "TestHeadless/6_quick_messages", "TestHeadless/8_instance_restart", "TestHeadless/3_runner_offline"]), # 77
+ ("headless-guards", [HEADLESS], ["TestHeadlessCopyRotation", "TestHeadlessPolicyGuards", "TestHeadlessRunnerKillLeavesNoCopies", "TestHeadlessNewHouseRuleStartsFresh", "TestHeadless/3_engineering", "TestHeadless/3_step_cancel", "TestHeadless/3_step_contained", "TestHeadless/3_empty_repo", "TestHeadless/3_empty_engineering", "TestHeadless/3_empty_merge", "TestHeadless/3_empty_merge_rebuilt", "TestHeadless/3_empty_fix_round"]), # 76
+ ("headless-rest", [HEADLESS], None), # 67: the rest of TestHeadless, Research, batching and the small ones
+ ("thintest-contract", [THINTEST], ["^TestContract"]), # 57
+ ("thintest", [THINTEST], None), # 48
+ ("runner-thin", ["./internal/runner/thin"], None), # 54
+ ("runner-bug", [RUNNER], ["TestDirectBugWorkflow", "TestEnrolKeepsTheRole"]), # 47
+ ("runner-plans", [RUNNER], ["TestPlanWorkflowCandidateOrder", "TestPlanWorkflowFeature", "TestCoordinatorRecoveryCallRefusalKeepsServing", "TestCoordinatorRefusalMatrix"]), # 51
+ ("runner-rest", [RUNNER], None), # 34
+ # equipotest's long tests call t.Parallel and wait together at the
+ # end, about 15 s; a lane is its serial tests plus that wait.
+ ("equipotest-a", [EQUIPOTEST], ["^Test[A-D]", "^TestQ"]), # 36 serial
+ ("equipotest-e", [EQUIPOTEST], ["^Test[E-P]"]), # 39 serial
+ ("equipotest-r", [EQUIPOTEST], ["^TestR"]), # 42 serial
+ ("equipotest-rest", [EQUIPOTEST], None), # 40 serial
+ ("plan3test", ["./internal/plan3test"], None), # 41
("rest", None, None), # every package no other lane names
]
@@ -98,11 +107,11 @@ LANES = [
# The browser tests wait on the page with short deadlines, so none of
# these is LATE.
BROWSER_LANES = [
- ("browser-headless-chat", [HEADLESS], ["TestBrowserChat", "TestBrowserChatSendStaysOnPage", "TestBrowserMoveIn", "TestBrowserComposer", "TestBrowserComposerReconcile", "TestBrowserComposerFocus", "TestBrowserComposerDock", "TestBrowserDraftStreamsFormatted", "TestBrowserDraftIsTheMessage", "TestBrowserRefreshRace"]), # 88
- ("browser-headless-work", [HEADLESS], ["TestBrowserTaskCard", "TestBrowserReceiptFollowsReview", "TestBrowserRailFollowsWork", "TestBrowserTaskThread", "TestBrowserAskAfterMerge", "TestBrowserReceiptsDesktop", "TestBrowserReceiptsTouch", "TestBrowserNotebook", "TestBrowserEmptyExplore", "TestNotebookScreenshots", "TestBrowserNotebookLook"]), # 75
- ("browser-headless-rest", [HEADLESS], None), # 74: the connections pages, thinking and cards, any new one
- ("browser-thintest", ["./internal/thintest"], None), # 80
- ("browser-rest", None, None), # plan3test and any new package
+ ("browser-headless-chat", [HEADLESS], ["TestBrowserChat", "TestBrowserChatSendStaysOnPage", "TestBrowserComposer", "TestBrowserComposerReconcile", "TestBrowserComposerFocus", "TestBrowserComposerDock", "TestBrowserDraftStreamsFormatted", "TestBrowserDraftIsTheMessage"]), # 79
+ ("browser-headless-work", [HEADLESS], ["TestBrowserTaskCard", "TestBrowserReceiptFollowsReview", "TestBrowserRailFollowsWork", "TestBrowserTaskThread", "TestBrowserAskAfterMerge", "TestBrowserReceiptsDesktop", "TestBrowserReceiptsTouch"]), # 79
+ ("browser-headless-connections", [HEADLESS], ["^TestBrowserConnections", "TestBrowserPasteBox", "TestBrowserPasteCopiesItsBox"]), # 77
+ ("browser-headless-rest", [HEADLESS], None), # 79: thinking and cards, moving in, the notebook, any new one
+ ("browser-rest", None, None), # 92: thintest's (91), plan3test's and any new package's
]
# Shards after the lanes: work that is not a lane of packages but runs
@@ -112,7 +121,7 @@ BROWSER_LANES = [
EXTRA_SHARDS = [
["test-quarantine"],
["runner-host"],
- ["runner-dead-references", "build", "vet", "fmt-check", "budget", "migration-check"],
+ ["runner-dead-references", "lanes-check", "build", "vet", "fmt-check", "budget", "migration-check"],
["staticcheck"],
["govulncheck"],
["gitleaks"],
@@ -161,7 +170,7 @@ BUILD_JOBS_MANY = 16 # for the lane of many small packages, where -p is also ho
CHECK_CPUS = 8
SETTLE, BUSY = 10, 10.0
LATE = {
- "equipotest-a": 30, "equipotest-d": 30, "equipotest-r": 30, "equipotest-rest": 30,
+ "equipotest-a": 30, "equipotest-e": 30, "equipotest-r": 30, "equipotest-rest": 30,
"plan3test": 30, "rest": 30,
"runner-dead-references": 30, "staticcheck": 30, "govulncheck": 30, "gitleaks": 30,
}
@@ -216,6 +225,32 @@ def lane_flags(name):
return []
+_files = {}
+
+
+def test_files(tags):
+ """{package: (directory, test file names)} as go list sees them with tags."""
+ if tags not in _files:
+ fmt = "{{.ImportPath}}|{{.Dir}}|{{join .TestGoFiles \" \"}} {{join .XTestGoFiles \" \"}}"
+ out = subprocess.check_output(["go", "list", "-tags", tags, "-f", fmt, "./..."], text=True)
+ found = {}
+ for line in out.splitlines():
+ path, directory, names = line.split("|", 2)
+ found["." + path[len(MODULE):]] = (directory, set(names.split()))
+ _files[tags] = found
+ return _files[tags]
+
+
+def read_tests(directory, names):
+ """The top-level tests in the named files, and the files' text."""
+ tests, text = set(), []
+ for name in sorted(names):
+ with open(os.path.join(directory, name)) as f:
+ text.append(f.read())
+ tests.update(TEST_FUNC.findall(text[-1]))
+ return tests, "\n".join(text)
+
+
_browser = None
@@ -225,24 +260,12 @@ def browser_tests():
global _browser
if _browser is not None:
return _browser
- fmt = "{{.ImportPath}}|{{.Dir}}|{{join .TestGoFiles \" \"}} {{join .XTestGoFiles \" \"}}"
-
- def files(tags):
- out = subprocess.check_output(["go", "list", "-tags", tags, "-f", fmt, "./..."], text=True)
- found = {}
- for line in out.splitlines():
- path, directory, names = line.split("|", 2)
- found["." + path[len(MODULE):]] = (directory, set(names.split()))
- return found
- plain, browser = files(TAGS), files(BROWSER_TAGS)
+ plain, browser = test_files(TAGS), test_files(BROWSER_TAGS)
_browser = {}
for package, (directory, names) in sorted(browser.items()):
- tests = []
- for name in sorted(names - plain.get(package, ("", set()))[1]):
- with open(os.path.join(directory, name)) as f:
- tests += TEST_FUNC.findall(f.read())
+ tests, _ = read_tests(directory, names - plain.get(package, ("", set()))[1])
if tests:
- _browser[package] = sorted(set(tests))
+ _browser[package] = sorted(tests)
return _browser
@@ -275,6 +298,96 @@ def browser_runs(name):
sys.exit(f"ci-test: unknown browser lane {name!r}")
+def lane_problems(lanes, packages, tests, sources, kind="lane"):
+ """What is wrong with one list of lanes, as messages; none when every
+ test of every package runs in exactly one lane. packages is every
+ package these lanes may run, tests {package: top-level tests} and
+ sources {package: its test files' text}, for the subtest names."""
+ problems = []
+ rest = [name for name, ps, _ in lanes if ps is None]
+ if len(rest) != 1:
+ problems.append(f"want one {kind} that names no package, for every package the others do not name; have {rest}")
+ named = {}
+ for name, ps, ts in lanes:
+ if ps is None:
+ if ts:
+ problems.append(f"{kind} {name} names tests but no package")
+ continue
+ if ts and len(ps) != 1:
+ problems.append(f"{kind} {name} names tests, so it must name one package, not {ps}")
+ for p in ps:
+ if p not in packages:
+ problems.append(f"{kind} {name}: no package {p} (renamed or deleted?)")
+ named.setdefault(p, []).append((name, ts))
+ claims = {} # (package, test) -> [(lane, subtest or None)]
+ for p, entries in sorted(named.items()):
+ whole = [name for name, ts in entries if not ts]
+ if len(whole) != 1:
+ problems.append(f"{p}: want one {kind} that names no tests and runs what the others do not; have {whole}")
+ for name, ts in entries:
+ for t in ts or []:
+ if t.startswith("^"):
+ try:
+ found = [x for x in tests.get(p, []) if re.search(t, x)]
+ except re.error as e:
+ problems.append(f"{kind} {name}: {t}: {e}")
+ continue
+ sub = None
+ else:
+ top, _, sub = t.partition("/")
+ found = [top] if top in tests.get(p, []) else []
+ if found and sub and f'"{sub}"' not in sources.get(p, ""):
+ problems.append(f"{kind} {name}: {p} has no subtest {sub!r} of {top}")
+ if not found:
+ problems.append(f"{kind} {name}: {t} names no test in {p}")
+ for x in found:
+ claims.setdefault((p, x), []).append((name, sub or None))
+ for (p, x), by in sorted(claims.items()):
+ whole, lanes_of = {name for name, sub in by if sub is None}, {name for name, _ in by}
+ if whole and len(lanes_of) > 1:
+ parts = [", ".join(sorted(whole)) + " whole"] + ([", ".join(sorted(lanes_of - whole)) + " some of it"] if lanes_of - whole else [])
+ problems.append(f"{p} {x} runs in more than one {kind}: {'; '.join(parts)}")
+ for sub in sorted({sub for _, sub in by if sub}):
+ lanes_of = sorted({name for name, s in by if s == sub})
+ if len(lanes_of) > 1:
+ problems.append(f"{p} {x}/{sub} runs in more than one {kind}: {', '.join(lanes_of)}")
+ return problems
+
+
+def check_lanes():
+ """make lanes-check: every test of every package runs in exactly one
+ lane, and 20-check@N has a shard for each lane and extra shard."""
+ plain, tagged = test_files(TAGS), test_files(BROWSER_TAGS)
+ tests, sources = {}, {}
+ for p, (directory, names) in tagged.items():
+ _, text = read_tests(directory, names)
+ sources[p] = text
+ tests[p], _ = read_tests(directory, plain.get(p, ("", set()))[1])
+ browser = browser_tests()
+ problems = lane_problems(LANES, set(plain), tests, sources)
+ problems += lane_problems(BROWSER_LANES, set(browser), browser, sources, "browser lane")
+ # A browser lane's -run would also take a plain test of the name; that
+ # test already runs in its own lane.
+ for name, ps, ts in BROWSER_LANES:
+ for t in ts or []:
+ top = t if t.startswith("^") else "^" + re.escape(t.partition("/")[0]) + "$"
+ for x in tests.get(ps[0] if ps else "", []):
+ if re.search(top, x):
+ problems.append(f"browser lane {name}: {t} also takes {x}, which is not a browser test")
+ names = all_lanes()
+ problems += [f"two lanes are called {n}" for n in sorted({n for n in names if names.count(n) > 1})]
+ steps = [n for n in os.listdir(os.path.join(root(), ".amadan", "ci.d")) if n.startswith("20-check@")]
+ want = f"20-check@{len(names) + len(EXTRA_SHARDS)}"
+ if steps != [want]:
+ problems.append(f".amadan/ci.d has {steps}; {len(names)} lanes and {len(EXTRA_SHARDS)} extra shards need {want}")
+ for p in problems:
+ print("lanes: " + p)
+ if problems:
+ return 1
+ print(f"lanes: {len(LANES)} lanes and {len(BROWSER_LANES)} browser lanes run every test once; {want}")
+ return 0
+
+
def all_lanes():
return [lane for lane, _, _ in LANES + BROWSER_LANES]
@@ -618,9 +731,10 @@ def commit():
return head if re.fullmatch(r"[0-9a-f]{40}", head) else "unknown"
-def failed_seconds(out, test):
- """How long test's failed attempt took, from go test's own FAIL line."""
- m = re.search(r"^\s*--- FAIL: " + re.escape(test) + r" \((\d+(?:\.\d+)?)s\)", out, re.M)
+def failed_seconds(out, test, result="FAIL"):
+ """How long test's failed attempt took, from go test's own FAIL line
+ (or, with result PASS, how long its pass took)."""
+ m = re.search(r"^\s*--- " + result + r": " + re.escape(test) + r" \((\d+(?:\.\d+)?)s\)", out, re.M)
return m.group(1) + "s" if m else "unknown"
@@ -695,8 +809,9 @@ def run_group(package, tests, env, tags=TAGS):
"""Run one top-level test's quarantined entries; retry failures once."""
report = []
base = ["-tags", tags, "-timeout", TIMEOUT]
+ started = time.time()
cmd, out, passed, failed, _ = go_test(package, tests, env, base, fresh=False)
- report.append(f"+ {cmd}")
+ report.append(f"+ {cmd} ({time.time() - started:.0f}s)")
missing = set(tests) - passed - failed
flaky, broken = [], sorted(missing)
for t in sorted(missing):
@@ -717,7 +832,7 @@ def run_group(package, tests, env, tags=TAGS):
if any(t in broken for t in failed):
report.append(tail(retry_out))
for t in sorted(passed - failed):
- report.append(f"ok {package} {t}")
+ report.append(f"ok {package} {t} {failed_seconds(out, t, 'PASS')}")
return report, flaky, broken
@@ -770,6 +885,8 @@ def main(argv):
for package, flags in browser_runs(name):
print(name + ": -tags " + BROWSER_TAGS + " " + " ".join([package] + [shlex.quote(f) for f in flags]))
return 0
+ if argv == ["check"]:
+ return check_lanes()
if argv == ["browser"]:
for package, tests in browser_tests().items():
print(package + ": " + " ".join(tests))