Skip to content

Make the thread action coalescing test deterministic with fake timers - #7215

Merged
ymichael merged 1 commit into
mainfrom
bb/make-threadactionsmenu-coalescing-test-determini-thr_k8tatkzgy8
Nov 7, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/make-threadactionsmenu-coalescing-test-determini-thr_k8tatkzgy8

Conversation

@ymichael

@ymichael ymichael commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

ThreadActionsMenu.test.tsx › "coalesces rows that mount a moment apart into one change" failed on a Windows CI run of #7208 and passed on rerun. The thread-id subscription debounce in thread-action-registry.tsx flushes after 32 ms with no new rows (100 ms max wait). The test mounted two rows, slept 20 ms on a real timer, then added a third. On a slow runner the sleep can last longer than 32 ms, so the first two ids flush on their own and the test sees an extra change.

What changed

Only the test changed. The thread action data input describe block now uses vi.useFakeTimers(). Vitest 4 fakes setTimeout and performance.now() by default, so this controls both the quiet window and the max wait. Real sleeps and waitFor polling were replaced with act(() => vi.advanceTimersByTimeAsync(ms)). The other three tests in the block used the same real-timer settle (150 ms), so they were converted too. Their assertions are unchanged; each waitFor is now a settle() followed by the same expect. No other test in the file relies on real-time delays.

How you verified

  • pnpm exec turbo run test --filter=@bb/app -- src/components/thread/ThreadActionsMenu.test.tsx: 64 passed, 1 skipped.
  • Ran the file 5 more times: 2 runs in a row, then 3 at the same time to add load. All passed.
  • Mutation check: with THREAD_IDS_QUIET_MS lowered to 10, the coalescing test fails, so it still checks the debounce.
  • turbo run typecheck --filter=@bb/app, oxlint and prettier: all clean.

AGENT GENERATED

🤖 Generated with Claude Code

The coalescing test waited 20 ms on a real timer between mounts while the
code under test flushes after 32 ms of quiet, so a slow runner could flush
early and record an extra change. The whole describe block now drives the
debounce with fake timers and explicit advances instead of real sleeps and
waitFor polling.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit 34606aa into main Nov 7, 2026
30 checks passed
@ymichael
ymichael deleted the bb/make-threadactionsmenu-coalescing-test-determini-thr_k8tatkzgy8 branch November 7, 2026 03:05
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