Skip to content

test(server): drop avoidable waits from the slowest server tests - #667

Merged
Rinat S (rsolmano) merged 3 commits into
mainfrom
test-speedup-server
Oct 7, 2026
Merged

Rinat S (rsolmano) merged 3 commits into
mainfrom
test-speedup-server

Conversation

@rsolmano

Copy link
Copy Markdown
Collaborator

Problem

An uncached bun run test takes ~2 min locally, and almost all of it is @thinkrail/server (115 s): its 97 test files run one after another, and a handful of tests spend seconds waiting on real time or doing expensive setup. The single slowest test started git commit 200 times in a bash loop.

Approach

Remove the avoidable waits without weakening any assertion. Each changed test was mutation-checked: I broke the guarded behaviour and confirmed the test fails.

  • Cheap fixtures instead of slow ones: the 200-commit cap test builds its history with one git fast-import stream. It keeps the real COMMIT_LIST_MAX and real git, so it still proves resolveListedCommit and listCommits use the same limit.
  • Move the clock instead of sleeping past a throttle or TTL: setSystemTime for the history revalidate throttle. For the Central status TTL, a Date.now offset instead, because Bun freezes the clock after setSystemTime and that code has its own Date.now() deadlines.
  • Wait for an observable signal instead of a fixed sleep: the terminal tests wait for shell output. The "displaced client can't type" check now syncs on a marker typed by the current client (PTY input is ordered), which is also stricter: it rejects the displaced command's echo too.
  • Shorter retry delay for the analytics tests: posthog-node retries 503s after 3 s, so the tests waited on that. PostHogSinkOptions gets an optional retryDelayMs (default unchanged), and the tests pass 10 ms through the existing initializeAnalyticsWithSinkFactoryForTests seam.

Left alone on purpose: the watch tests (they wait on the watcher's real debounce constants), boot's "waits beyond one second", and the runBounded timeout tests, because their waits are what they test.

Not in this PR: bun test --parallel. It runs the server suite in ~20 s, but on Bun 1.4.2 about 1 in 6 runs hung for good: a worker spins at 100% CPU with a zombie child. That's oven-sh/bun#34069, a lost child exit in spawnSync under --parallel. The fix (oven-sh/bun#44581) is merged but not released yet. Follow-up: once a Bun release includes it, bump Bun and switch packages/server to bun test --parallel.

Changes

Test Before After
todos/adoptedCommits — newest-200 cap 3.63 s 0.19 s
analytics/analytics.test.ts (whole file) 7.65 s 0.38 s
auth/jbcentral — signed-out / stopped-proxy quota 3.34 s 0.42 s
history/historyIndex — 2 s throttle 2.12 s 0.02 s
terminal/terminalManager — attached-client + displaced tests 2.6 s 0.46 s
@thinkrail/server suite (serial) 115 s ~97 s

Production change: only packages/server/src/analytics/sink.ts (+2 lines, an optional retryDelayMs → posthog fetchRetryDelay). Everything else is test-only.

Screenshots

Not applicable — no frontend changes.

Related issues

None.

Checklist

  • Fast gates pass: bun run lint, bun run typecheck, bun run test
  • E2E suite passes for app-affecting changes (bun run e2e, or bun run e2e:full when touching agent behavior) — not app-affecting: test changes plus an optional, default-off sink option
  • Before/after screenshots are included for frontend changes, or marked not applicable
  • Relevant SPEC.md / top-level specs updated to reflect any boundary, contract, or behavior change — no boundary, contract or behavior change
  • I have read the Contributing guide and agree to the Code of Conduct

Testing

@jetbrains-air jetbrains-air Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved — ready to merge.

@jetbrains-air jetbrains-air Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved — ready to merge.

@rsolmano
Rinat S (rsolmano) added this pull request to the merge queue Oct 7, 2026
Merged via the queue into main with commit 6b402a5 Oct 7, 2026
33 of 34 checks passed
@rsolmano
Rinat S (rsolmano) deleted the test-speedup-server branch October 7, 2026 06:40
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