Skip to content

test(clipboard): don't let copy-status tests overwrite the shared clipboard mock - #1154

Merged
davedbase merged 1 commit into
mainfrom
fix/clipboard-test-leak
Dec 1, 2026
Merged

davedbase merged 1 commit into
mainfrom
fix/clipboard-test-leak

Conversation

@davedbase

@davedbase davedbase commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes an intermittent CI failure: createClipboard > reads clipboard items after refetch fails with expected 'a' to be 'InitialValue' (seen on #1144 and #1152, neither touches clipboard, and once locally).

Cause

The vitest config uses isolate: false, so test files that land in the same worker share module state. Both clipboard test files import ./setup, whose navigator.clipboard mock keeps its last written value in a module-level variable. copy-status.test.ts spied on writeText/write but called through, so whatever it copied last ('a') stayed in the mock, and index.test.ts read it when it ran second. Whether that happens depends on how the files are scheduled onto workers, which is why it only fails sometimes.

The leak was introduced by the createCopyToClipboard tests from #1140.

Fix

The copy-status spies now resolve without calling through, so they can't change the shared mock.

Verification

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Clipboard tests now mock successful write operations, preventing clipboard data from carrying over between tests.

…pboard mock

createClipboard's 'reads clipboard items after refetch' failed intermittently in CI
(expected 'a' to be 'InitialValue'). Test files share a worker (isolate: false) and both
clipboard test files use the same module-level mock from setup.ts; copy-status spied on
writeText/write but called through, so whatever it copied last stayed in the mock and
index.test.ts read it when it ran second. Reproduced with a forced file order; the spies
now resolve without calling through.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Dec 1, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 5c1d859

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The copy-status tests now configure the writeText and write spies to resolve successfully by default instead of calling through to the clipboard methods.

Changes: Clipboard test mock isolation

Layer / File(s) Summary
Configure clipboard spies
packages/clipboard/test/copy-status.test.ts
The writeText and write spies now resolve successfully by default. A comment notes that the shared mock can retain written data across tests.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Other · Severity of issue fixed: Low

Possibly related PRs

Merge Risk: Minimal · up to 5c1d8

This change only affects clipboard tests. It stops one test file from leaving data in a shared mock that another file reads, which removes an intermittent test failure. There is no production impact and no merge-blocking risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the test scope (copy-status tests), the affected module (clipboard), and the fix (stopping the tests from overwriting the shared clipboard mock). The raw summary says the writeText and…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the test scope (copy-status tests), the affected module (clipboard), and the fix (stopping the tests from overwriting the shared clipboard mock). The raw summary says the writeText and write spies now resolve by default instead of calling through, and the objectives describe the same cause and fix. The title matches the main change.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 06711c05-cc25-4a61-9a82-a5dbc8d48479
Commits

Reviewing files that changed from the base of the PR and between 0e21b3d and 5c1d859.

Files selected for processing: 1

  • packages/clipboard/test/copy-status.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

@davedbase
davedbase merged commit f88d75e into main Dec 1, 2026
7 of 8 checks passed
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