Skip to content

test(cli): speed up managed service tests - #53441

Merged
kitlangton merged 1 commit into
v2from
faster-service-tests
Oct 5, 2026
Merged

kitlangton merged 1 commit into
v2from
faster-service-tests

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

Why

The CLI's managed-service tests spawn real serve --service processes and are among the slowest in the CLI suite. Much of that time is avoidable test overhead: every spawned process transpiles the CLI from a cold cache, and three tests wait out a server's real 5 s registration check to prove decision logic that doesn't need a real process.

What Changes

Test-only. No production code changes.

  • Shared transpiler cache: each isolated test home sets XDG_CACHE_HOME, which also moved Bun's transpiler cache into it, so every spawned CLI process started cold. isolatedEnv and serviceEnv now point BUN_RUNTIME_TRANSPILER_CACHE_PATH at one shared directory.
  • In-process registration checks: deleting, corrupting, or replacing a managed registration now runs ServiceRegistration.register in-process under TestClock, instead of starting a real server and waiting 5 s. The real-process test for a server whose boot failed stays, because it proves the failed server is still watching its registration. service-lifecycle.test.ts also still shows a real server exiting after its registration is corrupted.
  • One duplicate removed: the occupied-port test in service.test.ts repeated the case in service-lifecycle.test.ts. That case now also asserts the exact conflict message, the opencode service set port <port> hint, and that no registration was written.

Unchanged on purpose: the 8 s wait in the bind-race incumbent test, which must exceed the earlier 6 s incumbent window, and the server's 15 s bind-recovery window that the occupied-port cases wait out.

Verification

cd packages/cli
bun typecheck
bun test --timeout 60000 test/service.test.ts test/service-lifecycle.test.ts
  • All tests pass: service.test.ts 21/21 and service-lifecycle.test.ts 7/7.
  • Back-to-back on the same heavily loaded machine (load average around 35), the two files went from 244 s on v2 to 196 s. service.test.ts alone went from 114 s to 70 s.

@kitlangton
kitlangton force-pushed the faster-service-tests branch from d312a58 to 77b6b37 Compare October 5, 2026 22:31
@kitlangton
kitlangton merged commit 7d27d6a into v2 Oct 5, 2026
9 checks passed
@kitlangton
kitlangton deleted the faster-service-tests branch October 5, 2026 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant