Reduce repeated database/server fixtures and fixed timer waits in chat
tests without changing production code or assertions.
`TestTransitionMatrix_AllCombinations` shares one database and seeded
dependencies across 272 leaves, with a unique chat and recording
publisher per leaf. `TestPostChatFile` shares one authenticated client
across 20 upload leaves. `TestResolveFallbackModelConfigID` shares one
database with independently seeded model configurations. The
requires-action test closes its server after the expected state
persists; the stopped-workspace test advances a trapped Quartz
validation timer; two tool-filtering tests no longer start unused
workspace agents.
| Test | Before | After |
|---|---|---|
| `chatstate/TestTransitionMatrix_AllCombinations` (272 leaves) | 94.06s
| 16.86s |
| `coderd/TestPostChatFile` (20 leaves) | 31.23s | 0.95s |
| `chatd/TestRequiresActionChatPersistsWaitingStatusLabel` | 11.21s |
1.25s |
| `chatd/TestSubagentChatExcludesWorkspaceProvisioningTools` | 7.90s |
2.84s |
| `chatd/TestPlanModeSubagentChatExcludesAskUserQuestion` | 8.25s |
3.00s |
| `chatd/TestStoppedWorkspaceWithPersistedAgentBindingDoesNotBlockChat`
| 6.91s | 1.91s |
| `chatd/TestResolveFallbackModelConfigID` (12 leaves) | 7.58s | 0.34s |
Independent review measurements on September 18, 2026: median summed
leaf time from two runs per side in A/B/B/A order, comparing base
`0ea777a341` with head `e378f9e936`. Every run used
`-tags=testsmallbatch -count=1 -v -p 1 -parallel 8`, PostgreSQL 17, and
the same test selection per package. Other agents shared the host, so
absolute times varied. The speedups reproduced, but not the original
ratios: the matrix improved 5.58x and uploads 32.87x. Summed leaf time
excludes shared parent fixture setup and cleanup; it is not package wall
time. Median package elapsed was 19.26s to 9.76s for the full
`chatstate` package, 4.47s to 1.28s for `coderd` with only
`TestPostChatFile`, and 11.43s to 3.36s for the five targeted `chatd`
tests. Compilation time is excluded.
<details>
<summary>Investigation notes</summary>
- Transition matrix: the shared user, organization, membership,
provider, and model are not mutated by any leaf. Each leaf seeds its own
chat, messages, and queue, and copies the fixture with a new recording
publisher (`transitions_matrix_test.go:617,728,762`).
`ChatMachine.Update` still opens real transactions on the shared
database store; no outer transaction masks rollback assertions
(`chatstate/machine.go:161`, `transitions_helpers_test.go:891`). Parent
cleanup runs after every leaf.
- Requires-action: the old idle hook reached its 10s timeout because the
runner remains active while awaiting dynamic-tool results
(`testhooks.go:14`, `worker.go:114`). The test now waits for the
persisted status and label, closes and drains the server, and retains
the no-web-push assertion (`chatd_test.go:3072`).
- Stale binding: the test injects a new Quartz mock, traps the 5s
validation timer, waits for `MustRelease` to finish timer registration
and for the dial to start, then advances the clock
(`chatd_test.go:4907`). The one-dial, model-call, and
unavailable-workspace tool-result assertions remain intact.
- Tool filtering: both tests create templates but no workspace, and
their mocked model only invokes `spawn_agent` before returning text. The
removed workspace agents could not authenticate and were never used by
the tested flow; their shutdown added about 5s
(`chatd_test.go:229,384`).
- Fallback models: configurations and providers are independently
inserted. Most leaves use unique organizations; the two
default-organization cases insert distinct models, and only one inserts
a default. No leaf mutates another leaf's model or provider
(`chatd_internal_test.go:3512`).
Validation: all changed tests passed with `-count=5` and `-race
-count=2`; the full `chatstate` package passed both checks (2,350 and
940 test executions, including parents). All 272 matrix, 20 upload, and
12 fallback leaves remain present. `gofmt -l`, `git diff --check`, and
`golangci-lint run` on the three changed packages were clean. The full
`coderd` package was not run. No correctness changes were needed during
review. `ARCHITECTURE.md` was read; this test-only PR does not affect
the documented architecture, so no TODO or architecture edit is needed.
</details>
_Investigated, implemented, and validated by Coder Agents on behalf of
@ibetitsmike._