Skip to content

chat-ui: drive timer-backstop hooks with an injected clock (CL-7488) - #678

Merged
TheGreatAxios merged 3 commits into
mainfrom
cl-7488-chat-ui-flake
Sep 6, 2026
Merged

TheGreatAxios merged 3 commits into
mainfrom
cl-7488-chat-ui-flake

Conversation

@TheGreatAxios

Copy link
Copy Markdown
Contributor

Summary

packages/chat-ui/test/use-turn-activity.test.tsx and use-streaming-reply.test.tsx drove their backstop-timer assertions with real setTimeout/sleep against 20-60ms windows. Since CL-7484 made bun run test run packages concurrently (and CI shards them), those tests intermittently lost the race under CPU contention on build-test-shard (3).

  • useTurnActivity and useStreamingReply now take an optional Clock (now/setTimeout/clearTimeout — see new packages/chat-ui/src/clock.ts), defaulting to the real one (REAL_CLOCK), instead of calling Date.now()/setTimeout directly.
  • Both test files drive a new synchronous createFakeClock() test helper (packages/chat-ui/test/fake-clock.ts) instead of sleeping on the real clock — advance(ms) fires due timers immediately, so a 30ms/60ms backstop test takes ~0ms of wall time and can never race a contended CPU.

Ran the whole packages/chat-ui suite once and with --rerun-each 5: 4630/4630 pass, 0 fail (composer.test.tsx included — it did not fail locally, so nothing there needed touching).

Resolves CL-7488

Test plan

  • bunx tsc --noEmit -p packages/chat-ui
  • bun test packages/chat-ui/test/use-turn-activity.test.tsx packages/chat-ui/test/use-streaming-reply.test.tsx --rerun-each 20 — 540/540 pass
  • bun test packages/chat-ui — 926/926 pass
  • bun test packages/chat-ui --rerun-each 5 — 4630/4630 pass

useTurnActivity's and useStreamingReply's backstop tests drove real
setTimeout via sleep(), racing CI's sharded, CPU-contended test runs
against their 20-60ms windows. Rework the harnesses in both suites to
advance a synchronous fake clock instead.
useStreamingReply and useTurnActivity now take an optional Clock (now/
setTimeout/clearTimeout), defaulting to the real one, instead of
calling Date.now()/setTimeout directly. This is what lets their tests
advance a fake clock synchronously rather than racing real timers.
@linear-code

linear-code Bot commented Sep 6, 2026

Copy link
Copy Markdown

CL-7488

@TheGreatAxios
TheGreatAxios merged commit 67fce5d into main Sep 6, 2026
25 checks passed
@TheGreatAxios
TheGreatAxios deleted the cl-7488-chat-ui-flake branch September 6, 2026 22:26
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