Repository navigation
test(chat): wait for each throttled delivery in the jump-to-latest test - #327
Merged
Merged
Conversation
The test failed intermittently under load ("expected to be called 1
times, but got 2"), on a loaded local machine and in CI on #325. The
streaming bubble delivers text through useThrottledText's timer. The
test clicked "Jump to latest" while the delivery of "more " could still
be pending; when that delivery landed in the same act as the click, it
ran after jumpToLatest had marked the reader as back at the end, so
followStreamedOutput correctly followed it with an instant scroll, and
the test counted two scrolls.
Each step now waits until its text is in the bubble, so nothing is
pending at the click. The test also checks one more thing than before:
no scroll at all happens while the reader is scrolled away. The
assertions on what it protects are unchanged: following is instant and
only the reader's jump is smooth.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ChatPage.renderCost.test.tsx> "follows streamed output instantly, and animates only the jump the reader asks for" fails intermittently withAssertionError: expected "vi.fn()" to be called 1 times, but got 2 times:It blocks merging unrelated pull requests.
Root cause
The streaming bubble shows text through
useThrottledText, which delivers each change from asetTimeout. The test:stream("more ");The button already exists after the earlier "tok " delivery, so the "more " delivery could still be pending at the click. When that delivery's render landed in the same
actas the click, it ran afterjumpToLatesthad set the reader back at the end.followStreamedOutputthen, correctly, followed the new text with an instant scroll, and the test counted two scrolls.The product behaves as designed: a reader who jumped to the end is followed when new text arrives. Only the test's timing assumption was wrong.
Change
Test-only. Each step waits until its text is in the bubble before going on, so nothing is pending at the click. The mock is cleared right after scrolling away, and a new assertion checks that delivering "more " while scrolled away scrolls nothing. The existing assertions are unchanged:
{ behavior: "instant" };{ behavior: "smooth" }scroll.Checks
npx vitest run src/features/chat/ChatPage.renderCost.test.tsx, 10 consecutive runs: 10 passed, 0 failed.npx eslinton the file: clean.npx tsc --noEmit -p .: clean.scripts/check.ps1quick tier): all checks passed. Backend 3071 passed; vitest 77 files, 1047 tests passed.Limits
act.Plan item: none (flaky test)
🤖 Generated with Claude Code