Skip to content

perf(test): speed up unit tests by ~60% - #1137

Merged
EhabY merged 1 commit into
mainfrom
perf/speed-up-unit-tests
Oct 6, 2026
Merged

EhabY merged 1 commit into
mainfrom
perf/speed-up-unit-tests

Conversation

@EhabY

@EhabY EhabY commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Cuts unit test time on CI by roughly 60% on every job. Test and config changes only.

  • Stop every extension test file importing most of src/. testHelpers.ts imported @/commands at runtime for one helper (~450ms per file). createTestCommands now lives in test/mocks/commands.ts.
  • Run the webview project on vmForks (~70% faster for jsdom). test/webview/setup.ts removes its uncaughtException filter per file, since vmForks shares process across files.
  • Replace as unknown as CoderApi casts with createTestCoderApi: a real CoderApi with typed overrides. Five casts remain, each for the reason listed below.
CI job (vitest Duration) Before After
Linux, Electron 37 63s / 91s 32s
Linux, Electron latest 96s / 91s 32s
Windows 85s / 109s 43s
Windows ARM64 105s / 102s 43s
macOS 85s / 112s 31s
Investigation notes

Pools (local, 4 workers, before these changes):

Config Time Result
forks (default) 23.9s pass
threads 36.0s pass
vmForks / vmThreads 8.2s / 9.5s 5 failures
isolate: false 79.5s 376 failures (mock leakage)
fsModuleCache 22.5s negligible
helper split + webview vmForks 11.6s pass

The extension project stays on forks. In a vm context, values from Node built-ins (execFile errors, AbortController reasons, fs.readdir arrays) are cross-realm, so instanceof Error / toStrictEqual diverge from Electron (isAbortError, toError, cliError).

Remaining as unknown as CoderApi: inbox (the stub doesn't match the real return type), authInterceptor (fakes internal state), deploymentManager ×2 (CoderApi.create is mocked), workspacesProvider (class mock; Object.assign can't copy prototype methods).

Windows ARM64 setup (~190–290s of pnpm cache restore + install) is unchanged. The image has no fast D: drive and Defender real-time protection is on. Temporary side-by-side jobs, 3 runs each, median job total: baseline 257s, Defender off 302s, verifyStoreIntegrity=false 286s, both 314s. Single runs: no cache 349s, Dev Drive 613s. None beat runner noise (baseline alone ranged 249–318s).


Generated by Coder Agents on behalf of @EhabY.

@EhabY EhabY changed the title perf(test): move createTestCommands out of shared test helpers perf(test): speed up unit tests by ~60% Oct 6, 2026
- Move createTestCommands out of testHelpers into test/mocks/commands.ts.
  testHelpers imported @/commands at runtime, so every extension test file
  loaded most of src/ (~450ms each).
- Run the webview project on vmForks, ~70% faster for jsdom. The setup
  file's uncaughtException filter is removed per file, since vmForks
  shares process across files. The extension project stays on forks
  because vm contexts break instanceof Error for Node built-in values.
- Replace `as unknown as CoderApi` casts with createTestCoderApi, a real
  CoderApi with typed overrides.
@EhabY
EhabY force-pushed the perf/speed-up-unit-tests branch from a292aa0 to 42cc406 Compare October 6, 2026 10:18
@EhabY
EhabY marked this pull request as ready for review October 6, 2026 11:16
@EhabY
EhabY requested a review from jakehwll October 6, 2026 11:16
@EhabY
EhabY merged commit f852fdd into main Oct 6, 2026
14 checks passed
@EhabY
EhabY deleted the perf/speed-up-unit-tests branch October 6, 2026 11:22
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.

2 participants