test(ui): bound the copy wait by a deadline, not an attempt count - #3477
Conversation
Under load each poll costs more wall-clock, so a fixed number of attempts is an arbitrary proxy for how long the test is willing to wait. The deadline is checked after the predicate, so a state landing exactly on it still counts, and before the sleep, so a failed final check does not pay for a tick it will never use.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe test polling helper replaces a fixed attempt limit with a 2-second wall-clock deadline. It evaluates the predicate before timeout checks, avoids an unnecessary final sleep, and reports the configured duration and description on timeout. ChangesPolling timeout update
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a76027dbd3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/react/components/ui/code-block.test.tsx`:
- Around line 79-91: Add focused direct tests for the waitFor helper covering a
predicate that succeeds exactly at the deadline, the configured timeout error
including its description, and a final failed check that does not trigger an
additional sleep. Use deterministic clock/sleep control rather than real delays,
and preserve the existing WAIT_FOR_TIMEOUT_MS contract.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: bcfd408c-f79f-406a-8d2f-daf778b1f1d1
📒 Files selected for processing (1)
src/react/components/ui/code-block.test.tsx
A wall clock corrected mid-run by NTP or a VM host can jump backwards, holding the loop open past its bound, or forwards, timing out a test that was about to pass. Elapsed time is what this measures, so it now measures it with `performance.now()`. `waitFor` also had no tests of its own, which matters more than it looks: it decides whether the clipboard assertions run against a settled render, so a version that resolved early or swallowed its timeout would leave those tests passing without checking anything. Four cases now pin the contract -- returning on the poll that succeeds, accepting a state that arrives late, throwing an error naming its timeout, and sleeping between polls but never after the check that gives up. The timeout is injectable so they run in milliseconds. I confirmed the trailing-sleep case fails when the loop is reordered to sleep before its deadline check, rather than trusting it green.
Follow-up to #3476, which merged before this landed on its branch. The review finding there is currently unaddressed on
main, and my reply on that thread claiming it was fixed was premature — this is the change it described.waitForstopped after 100 polling iterations. Under load each poll costs more wall-clock, so an attempt count is an arbitrary proxy for how long the test is willing to wait, and it gets shorter in wall-clock terms exactly when the machine is slow — which is when the flake happens. It is now a 2s deadline.The loop order also changed so the trailing sleep is gone: predicate, then deadline, then sleep. A state landing exactly on the deadline still counts, and a failed final check no longer pays for a tick it will never use.
Still fails loudly rather than waiting a regression out: pointing the predicate at a sentinel that is never true reports
Timed out after 2000ms waiting for the copy control to report failure. Verified that explicitly, as with the original.Summary by CodeRabbit