Squashed from wei's #1146, onto main. Each test now starts from state of
its own instead of what an earlier test (or an earlier -count run) left:
- plugin: changed() counts the OnChange hooks still running; Told waits
for them, and Settle ends with Told and UseCached(nil), so a change one
test made isn't told in the next and the next test's plugin list isn't
read as changed. Only tests call Settle/Told; in production changed()
only counts. New TestSettleWaitsForTheHooksItTold and
TestSettleForgetsTheFoldersPlugins.
- provider: isolate forgets Copilot's state, the plans' quota cards and
balances; the warm-up, Cursor sign-in, hold and moved-plugin tests wait
for what they started.
- gateway: fresh() forgets refused seals, and TestRouting,
TestSmartRouting and TestQuotaRestsUntilItsReset start from
forgetRouting; codexSignedIn and TestForeignReasoningIsLeftOut start
from fresh.
- codexcat: XDG_CONFIG_HOME under the test's home. tui: costAt reset.
gui: the fake Cursor account no longer outlives its test. cli: Settle.
Left out as already on main: the cli_identity keepIdentities switch
(9c3772311 keeps the asks in a sandbox via testenv's marker) and the
omarchy reset (main's TestCurrent already resets cached/seen/asked).
Run (darwin, loaded machine):
- On main 043e0cfc7, -count=3: TestRouting, TestSmartRouting,
TestQuotaRestsUntilItsReset, TestForeignReasoningIsLeftOut,
TestStandaloneNativeFallback fail; codexcat and tui fail; provider
-shuffle=1791359851244745000 fails TestCopilotAuto and
TestCopilotSignAndModels, and -count=2 -shuffle=1791856220860256000
-run 'Copilot|TestPlanQuotas|TestCachedCardsAskNobody' fails
TestPlanQuotas and TestCachedCardsAskNobody. With this change, that
provider run (-shuffle=on, -count=2), the same gateway tests,
./internal/codexcat, ./internal/tui and the Settle/Hold/warm-up tests
in plugin and provider pass -count=3.
- Breaking Settle by hand: without Told(),
TestSettleWaitsForTheHooksItTold fails; without UseCached(nil),
TestSettleForgetsTheFoldersPlugins fails.
- gofmt -l; go vet ./... on darwin, GOOS=linux -tags nogui, GOOS=windows.
Not run: the whole ./... suite at once (the machine's load times it out)
and Windows/Linux test runs.
TestSignInInstallsMissingCLI and TestMovedSignInAsBuiltIn hold their fake
installer on a channel the test closes only after its first checks. A
Fatal before that left the installer blocked for the rest of the package's
run. f3c098da8 fixed the same hold in the Grok sibling with a cleanup;
these two were already gated and kept the leak. The hold now also ends on
the test's cleanup, and the installer returns an error then.
The installsMissingCLI fake also called testenv.Program(t, ...) on the
sign-in's goroutine. Under load (~125) its test hit waitPast's 5s first,
and the fake's late t.Fatal panicked the whole package ("Fail in goroutine
after TestSignInInstallsMissingCLI has completed"). It now uses
testenv.WriteProgram and returns the error.
Ran:
- An injected t.Fatal right after StartSignIn / StartPluginSignIn, plus a
test that dumps goroutines a second later: on origin/main the fake is
still blocked at install_test.go:40; with this, nothing is left.
- -race -count=20 of both tests, 2 runs each beside origin/main at load
~125-140: green on both.
- gofmt -l; go vet, GOOS=linux and GOOS=windows go vet ./internal/provider.
65dcc573 (ggbdpq's patch 1) warmed the bun on PATH before the root
package's one-minute plugin contexts. The same lookup of the bun on PATH
is in 40 more places in internal/provider (28), internal/gateway (8),
internal/plugin (3) and internal/gui (1), and in the root package's
TestPluginListSaysClash. Many of them then open a one- or two-minute
context (internal/provider's sign-in, fetch and move tests,
internal/plugin's sandbox), and there macOS's first-exec check of a
just-installed or upgraded bun landed inside the deadline. The rest
are covered the same way, so no test has to remember which is which.
testenv.Bun now does what the root package's pathBun did: it finds the
bun on PATH (skipping the test when there is none) and runs
`bun --version` before the test opens its context, once per bun per test
binary. pathBun is gone; every `exec.LookPath("bun")` + skip block in
the tests uses testenv.Bun instead. Three tests reach for the bun some
other way and are left as they were: TestHostRunsAsMagpieBun (7ddea2c2
covers its copy), the plugin_git test's realBun and netproxy's
TestBunThroughBridge, none of which runs the plugin host under a
deadline on the PATH bun. migrate_test.go needed two `err` declarations
that the removed block used to provide.
What was run (macOS arm64, bun 1.4.2), with a wrapper bun first on PATH
whose first exec sleeps 61s (marker-gated, then execs the real bun):
- Red, old code:
- internal/provider TestPluginSignInTakesAPastedCallback: FAIL at
61.1s, "pluginsignin_paste_test.go:36: starting plugins: context
deadline exceeded".
- internal/plugin TestFakePlugin: FAIL at 62.0s, "plugin_test.go:66:
Plugins = [], starting plugins: context deadline exceeded".
- internal/gateway TestPluginFailover passed on the old code too (its
calls have no deadline that short), so the gateway is not shown red.
- Green, this change, same cold wrapper: the three tests passed (61.1s,
62.9s, 61.2s).
- go test -tags nogui -count=1 for the root package and for
internal/testenv, gateway, gui, plugin and provider, under a temp HOME
with GOMODCACHE, GOCACHE and GOPATH pinned: all ok.
- gofmt -l on the changed files: clean. go vet of those packages for
darwin (-tags nogui), GOOS=linux and GOOS=windows (-tags nogui), and
GOOS=windows without the tag: clean.
Not run: a really cold bun on a loaded machine; the sleep stands in for
the check. Not run on Linux or Windows, where the warm-up is one extra
`bun --version` per test binary.
macOS checks a newly written executable before its first exec: 0.27s
alone, 2-5s while other new programs start (a go test ./... starting its
test binaries). The same file again takes 0.009s, and the pass is kept
across a rename and an in-place rewrite. 108852b4 worked round this for one
test with /bin/sh -c; the class was every test that writes a `#!/bin/sh`
fake and times its answer.
testenv.Program(t, path, script) replaces os.WriteFile(path, script, 0o755)
for fakes. On macOS it renames a file that has run once from a pool to path
and writes the script into it in place; at the test's cleanup the file goes
back to the pool (only a path the test created; a stand-in it wrote over
stays). Fakes still end with their tests: nothing about how they are
started or waited on changed. Run (and gateway's TestMain) remove the pool
at the end. TestMain's PATH stand-ins are run once in the background
(testenv.StandIns). Other systems write the file as before.
Converted every `#!/bin/sh` fake written by tests under internal/ (agent,
gateway, gui, library, plugin, proc, provider, update). Windows, binary
and node/bun fakes are unchanged.
Under the same load (3 loops each starting 8 freshly written scripts at a
time), 4 rounds each, before (108852b4 / origin/main) vs after:
- provider TestSavedButSignedOutClaudeServed: 4/4 fail (8.01s) -> 4/4 pass
- provider TestClaudeSignInOverStaleCredentials: 4/4 fail (5.00s) -> 4/4 pass
- provider TestDevinSignedInOnlyInMagpie: 3/4 fail ("CLI's own []") -> 4/4 pass
- gateway TestClaudeRunEndsWhenTheClientLeaves: 4/4 fail -> 4/4 pass
(and 3/3 fail -> 3/3 pass at a third of that load)
- gateway TestClientGoneRecordedAsCanceled: 4/4 fail -> 4/4 pass
- gui TestProvidersAnswerWhileListsComeIn ("cursor found false" at 3.03s):
4/4 fail -> 4/4 pass. The same class, not bfe8bcaf's test order.
- proc TestUserPath (login shell's PATH never came, 7.01s): 4/4 fail ->
4/4 pass
Unloaded, every touched package passes; no pool directory or process is
left after a run.