Skip to content

perf(tests): slim test entry, shared isolate for side-effect-free tests - #101

Merged
leorfer23 merged 1 commit into
mainfrom
perf/route-tests
Oct 14, 2026
Merged

leorfer23 merged 1 commit into
mainfrom
perf/route-tests

Conversation

@leorfer23

Copy link
Copy Markdown
Contributor

Follow-up to #99. Three cuts to the unit suite's module-loading cost.

  • Slim test entry. wrangler.test.toml main → tests/worker-main.ts: only the DO classes, with ChatDO and Showtime stubbed. Those two pulled in the agent loop and the screenshot stack, ~8s on every file that touches a DO. session-do.test.ts (the only real ChatDO user) runs in a new workers-chat project whose main is still src/index.ts. DO tests: ~8s → ~3s each.
  • Shared isolate for side-effect-free files. New workers-shared project runs with isolate: false. tests/isolation.ts puts a file there only if neither it nor any local helper it imports mocks modules, patches globals, fakes timers, or touches D1/DO bindings. A vitest-isolate comment opts a file out (used once: artifacts/member-view.test.ts). That's 228 files, and 6 runs of that set with file order shuffled were all green.
  • source-timestamps.test.ts now reads src/ with fs in the node project instead of import.meta.glob inside workerd: 18s → 0.2s. It still fails on a planted datetime('now').
  • Also rebuilds public/_bundles/skill.zip, which went stale on main after docs(blobs): list the MIME types the blob API actually allows #97 (docs change without a rebuild).

Measured (load 3–8, machine shared with other agents)

  • Full suite: ~154s → 115–140s (one run took 190s under a load spike). Summed import time: 764s → ~600s.
  • Full gate with all tests: 166s, all green.

Biggest remaining cost: ~300 isolated files that use vi.mock against route modules. They can't share an isolate without rewriting their mocks.

🤖 Generated with Claude Code

- wrangler.test.toml main -> tests/worker-main.ts: only the DO classes, with
  ChatDO and Showtime stubbed (they pulled in the agent loop and screenshot
  stack, ~8s per DO test). session-do.test.ts runs in a workers-chat project
  whose main is still src/index.ts.
- New workers-shared project (isolate: false) for test files that do not
  mock, patch globals, fake timers or touch D1/DO bindings, following local
  imports. tests/isolation.ts decides; a `vitest-isolate` comment opts out.
  228 files; 6 file-shuffled runs of that set green.
- source-timestamps.test.ts reads src/ with fs in the node project (18s ->
  0.2s); still fails on a planted datetime(now).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@leorfer23
leorfer23 merged commit e801502 into main Oct 14, 2026
@leorfer23
leorfer23 deleted the perf/route-tests branch October 14, 2026 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant