Skip to content

test(studio): a failed copy test waits for each copy's read, not 10 ms - #8964

Merged
miguel-heygen merged 1 commit into
mainfrom
test/clipboard-copy-waits-on-read
Nov 27, 2026
Merged

miguel-heygen merged 1 commit into
mainfrom
test/clipboard-copy-waits-on-read

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

useClipboard.source.test.ts, "a copy that fails > leaves the previous copy on the clipboard", now waits for each copy's file read to be answered instead of waiting a fixed 10 ms after each copy.

Why

The test copies, turns on read failures, copies again, then pastes and expects the first copy. It gave each copy 10 ms of real time to finish its read. When the first read took longer (a busy Windows runner), the read was answered after failures were turned on, so the first copy failed as well and the paste had nothing: expected [] to have a length of 1 but got +0 on Windows in the merge queue.

Related work

Test-only change; the clipboard code is unchanged.

How

  • answered(n) waits until the test's fetch stand-in has been called n times, then for that call's answer.
  • The stand-in's first read now answers after 15 ms and later reads at once. That pins the schedule that failed on Windows (a slow first read, then a quick one), so the test covers it on every machine.

Test plan

  • Unit tests added/updated
  • Manual testing performed
  • Documentation updated (if applicable)
  • Comments follow CONTRIBUTING.md "Comments": they say why, not what, and a bug fix says what the code must do and how to reproduce the bug

On Linux (vitest, packages/studio):

  • The old 10 ms waits with the slow first read: the test fails 3 of 3 runs alone.
  • This change: passes 3 of 3 alone and 3 of 3 in the whole file (23 tests); format, lint and typecheck pass.
  • The old test without the slow read passed 12 of 12 alone under CPU load, so plain load on Linux does not reproduce it; the pinned slow first read does.

Not run: the Windows job itself; its CI run on this PR is the check.

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 5db25d6. Approving.

Read whole: useClipboard.source.test.ts. Read in part: useClipboard.ts (the copy and paste paths, lines 243-380). Nothing was run.

What I checked:

  • The stand-in reads fail.on after its delay, so the old fixed 10 ms wait could flip the switch before the first read was answered. That matches the reported failure (expected [] to have a length of 1).
  • answered(n) waits for the nth call and then for that call's own answer, so fail.on is settled for read 1 before it is turned on, and for read 2 before it is turned off. The paste then awaits the clipboard's own chain, so no further wait is needed.
  • The 15 ms first read pins the slow-then-quick order on every machine, and the delay is reset before the second copy.
  • Test-only: the clipboard code is unchanged.

Notes, not blockers:

  • toHaveBeenCalledTimes(n) is exact. If a copy ever makes a second read, this test stops with a wait timeout instead of a clear message. Fine today since each copy reads one file.
  • The body has no literal "fails without the fix:" line. Since this changes only a test, I took the Test plan line (old waits plus the slow first read fail 3 of 3) as that statement.

Need: yes, removes a timing flake · Size: 11/3, one file · Reuse: uses the file's existing delayMs · Simpler: no · Structure: fine
Risk: low, test-only.

— Rames

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 27, 2026
Merged via the queue into main with commit 8cb53b8 Nov 27, 2026
66 checks passed
@miguel-heygen
miguel-heygen deleted the test/clipboard-copy-waits-on-read branch November 27, 2026 07:16
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.

2 participants