Repository navigation
Make SelectionCopy's clear-then-write test deterministic - #242
Merged
Merged
Conversation
The test modelled an app's late clipboard write with a detached Task that slept 30 ms, racing SelectionCopy's 500 ms wall-clock deadline. On a loaded CI runner the Task ran after the deadline: the copier gave up, restored the user's clipboard, and the late write then clobbered it — both expectations failed (seen on the v0.1.63 release PR's check run). The fake pasteboard now applies the late write the moment the cleared clipboard is first read, so the copier always sees the clear on one poll and the write on a later one. Verified the test still fails when SelectionCopy stops at the first change instead of waiting for a string. 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
SelectionCopyTests› "a clear before the write isn't mistaken for an empty copy" failed on the v0.1.63 release PR'scheckrun (#241). The same code passed onmain.The test modelled the app's late write with a detached
Taskthat slept 30 ms, racingSelectionCopy's 500 ms wall-clock deadline. On a busy runner the task ran after the deadline (the test took 0.640 s). The copier gave up and restored the user's clipboard, and then the late write overwrote it.Fix
Test-only.
FakeCopyPasteboardgets alateWritethat it applies the moment the cleared clipboard is first read. The copier therefore always sees the clear on one poll and the write on a later one, with no timer to race. The timeout is raised to 5 s. It only bounds the failure case, since a passing run returns after two polls (~20 ms).Verification
swift test --filter SelectionCopypasses three runs in a row.SelectionCopyto stop at the first change (while seen == before) instead of waiting for a string makes the test fail with 2 issues, so it still guards the behaviour.swiftlint --strictandswift-format lint --strictpass.🤖 Generated with Claude Code