test(e2e): fix flaky paste-upload clipboard assertion - #158
Conversation
…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 SummaryThis PR replaces an unreadable OS-clipboard assertion with page-level instrumentation that records the generated review link.
Confidence Score: 4/5The 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
|
| 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. |
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
| Object.defineProperty(navigator, "clipboard", { | ||
| configurable: true, | ||
| value: { writeText: record }, | ||
| }); | ||
| } |
There was a problem hiding this comment.
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!
Problem
UI Testshas been red ondevelopfor weeks — one test:Cause
The workflow serves the app from
http://vms.test:8000(BASE_URL/SITE_HOSTinui-tests.yml).vms.testis not a secure context — onlylocalhost,127.0.0.1,*.localhostand HTTPS are — sonavigator.clipboardisundefinedin the page.The app copes with this already:
lib/clipboard.tscopyText()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 throughnavigator.clipboard.readText().Fix
Before navigating, stub
navigator.clipboard.writeText(or definenavigator.clipboardwhen 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 alonestill pass locally.writeTextcall and the regex matches even afterdelete navigator.clipboard(simulatingvms.test).🤖 Generated with Claude Code