Skip to content

test(e2e): fix flaky paste-upload clipboard assertion - #158

Merged
vishwajeet-13 merged 1 commit into
bwhtech:developfrom
vishwajeet-13:fix/e2e-paste-upload-clipboard
Sep 7, 2026
Merged

test(e2e): fix flaky paste-upload clipboard assertion#158
vishwajeet-13 merged 1 commit into
bwhtech:developfrom
vishwajeet-13:fix/e2e-paste-upload-clipboard

Conversation

@vishwajeet-13

Copy link
Copy Markdown
Collaborator

Problem

UI Tests has been red on develop for weeks — one test:

[chromium] › e2e/tests/paste-upload.spec.ts:54 › uploads a pasted image and copies its review link
Error: page.evaluate: TypeError: Cannot read properties of undefined (reading 'readText')

Cause

The workflow serves the app from http://vms.test:8000 (BASE_URL / SITE_HOST in ui-tests.yml). vms.test is not a secure context — only localhost, 127.0.0.1, *.localhost and HTTPS are — so navigator.clipboard is undefined in the page.

The app copes with this already: lib/clipboard.ts copyText() falls back to a hidden <textarea> + execCommand('copy'), so the copy succeeds and the toast shows. Only the test broke, because it read the link back through navigator.clipboard.readText().

Fix

Before navigating, stub navigator.clipboard.writeText (or define navigator.clipboard when it's missing) to record what the app copies, then assert on the recorded value instead of reading the OS clipboard. Works in both a secure context (local) and a non-secure one (CI).

Scope is the one test; the other paste-upload tests only called grantPermissions, which was a no-op for them.

Verified

  • explains itself when the format is not supported, leaves a paste inside a text field alone still pass locally.
  • Standalone check: the stub captures the app's writeText call and the regex matches even after delete navigator.clipboard (simulating vms.test).
  • The full test needs MinIO + a configured site — CI on this PR is the real check.

🤖 Generated with Claude Code

…adText

CI serves the app from http://vms.test:8000, which is not a secure context,
so navigator.clipboard is undefined and the readText() call threw. The app's
own copy path already falls back to a textarea, so the copied link was never
observable through the async clipboard API here.

Capture what the app writes instead: stub navigator.clipboard.writeText (or
define it when missing) before navigation and read the recorded value.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N6kPRDGo6QbcVcc8DPkMTf
@greptile-apps

greptile-apps Bot commented Sep 7, 2026

Copy link
Copy Markdown

Greptile Summary

This PR replaces an unreadable OS-clipboard assertion with page-level instrumentation that records the generated review link.

  • Installs a writeText recorder before navigation.
  • Asserts against the recorded link instead of calling navigator.clipboard.readText().
  • Leaves a coverage gap for the non-secure-origin textarea clipboard fallback.

Confidence Score: 4/5

The PR appears safe to merge, with a non-blocking test-coverage gap around the production clipboard fallback.

The new recorder should fix the flaky clipboard read, but defining a successful Clipboard API prevents this test from detecting regressions in the otherwise-uncovered textarea fallback.

Files Needing Attention: e2e/tests/paste-upload.spec.ts

Important Files Changed

Filename Overview
e2e/tests/paste-upload.spec.ts Stabilizes the copied-link assertion, but bypasses the production clipboard fallback used by CI's non-secure origin.

Fix all with Greploop Fix All in Claude Code Fix All in Codex

Prompt To Fix All With AI
### Issue 1
e2e/tests/paste-upload.spec.ts:68-72
**Fallback path loses coverage**

On CI's non-secure origin, defining a successful `navigator.clipboard.writeText` forces `copyText()` down the Clipboard API path. The test therefore no longer exercises the textarea and `execCommand('copy')` fallback that production uses there. Because no other test covers that fallback, it could regress while this end-to-end test remains green. Capture the copied value without replacing the absent Clipboard API, or add dedicated fallback coverage.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "test(e2e): stop paste-upload test depend..." | Re-trigger Greptile

Comment on lines +68 to +72
Object.defineProperty(navigator, "clipboard", {
configurable: true,
value: { writeText: record },
});
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Fallback path loses coverage

On CI's non-secure origin, defining a successful navigator.clipboard.writeText forces copyText() down the Clipboard API path. The test therefore no longer exercises the textarea and execCommand('copy') fallback that production uses there. Because no other test covers that fallback, it could regress while this end-to-end test remains green. Capture the copied value without replacing the absent Clipboard API, or add dedicated fallback coverage.

Prompt To Fix With AI
This is a comment left during a code review.
Path: e2e/tests/paste-upload.spec.ts
Line: 68-72

Comment:
**Fallback path loses coverage**

On CI's non-secure origin, defining a successful `navigator.clipboard.writeText` forces `copyText()` down the Clipboard API path. The test therefore no longer exercises the textarea and `execCommand('copy')` fallback that production uses there. Because no other test covers that fallback, it could regress while this end-to-end test remains green. Capture the copied value without replacing the absent Clipboard API, or add dedicated fallback coverage.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code Fix in Codex

@vishwajeet-13
vishwajeet-13 merged commit 94dd9be into bwhtech:develop Sep 7, 2026
5 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