Skip to content

[qa] Address QA Coverage Gaps from PR #556 — Single Clipboard Write Refactor #563

@coderabbitai

Description

@coderabbitai

Context

PR #556 refactored clipboard handling so ClipboardRouter has sole ownership of each clipboard write (single write per R-* operation). Insert factories (AIAssistantInsertFactory, TerminalInsertFactory, ManualPasteInsertFactory) no longer write to the clipboard; they only execute paste commands. Smart padding was moved upstream to four call sites (LinkGenerator, TextSelectionPaster, FilePathPaster, TerminalSelectionService).

The QA Gap Check bot flagged four missing test cases in this comment. This issue tracks their implementation.

Requested by @couimet.


Gap 1 — Automatable: Verify single clipboard write operation

Goal: Assert that ClipboardRouter.copyAndSendToDestination calls vscode.env.clipboard.writeText (or the equivalent adapter method) exactly once per R-* operation, regardless of destination type.

Proposed implementation:

  • Add unit tests in ClipboardRouter.test.ts (or a new ClipboardRouter.single-write.test.ts).
  • Spy on clipboardPreserver.preserve / writeTextToClipboard and assert toHaveBeenCalledTimes(1) for each destination type: editor, terminal, AI assistant, manual paste.
  • Cover the executeCopyAndSend internal path for the no-destination and self-paste early-exit branches (assert clipboard write still happens exactly once via ClipboardPreserver).
  • Confirm the pasteSucceeded boolean returned by executeCopyAndSend is forwarded correctly into isClipboardRestorationApplicable.

Gap 2 — Automatable: Verify paste command execution without clipboard write

Goal: Assert that insert factories execute only paste commands and make zero clipboard write calls.

Proposed implementation (per factory):

AIAssistantInsertFactory

  • File: aiAssistantInsertFactory.test.ts
  • Spy on vscodeAdapter.writeTextToClipboard and assert not.toHaveBeenCalled().
  • Spy on vscodeAdapter.pasteTextFromClipboard and assert toHaveBeenCalledTimes(1).
  • Verify insert() returns true on success and false on pasteTextFromClipboard rejection (already partially covered — add the no-write assertion).

TerminalInsertFactory

  • File: terminalInsertFactory.test.ts
  • Spy on vscodeAdapter.writeTextToClipboard and assert not.toHaveBeenCalled().
  • Spy on vscodeAdapter.pasteIntoTerminal and assert toHaveBeenCalledTimes(1) with the correct terminal.
  • Verify the text argument passed to the returned closure is ignored (i.e., pasteIntoTerminal is called with only the terminal reference).

ManualPasteInsertFactory

  • File: manualPasteInsertFactory.test.ts
  • Spy on vscodeAdapter.writeTextToClipboard (if adapter were passed — confirm it is NOT in the constructor) and assert it is never called.
  • Assert insert() resolves true and logs 'Link ready for manual paste'.

Gap 3 — Manual: Verify padding is applied correctly during paste operations

Goal: Confirm that smart padding is pre-applied at the four upstream call sites and that destinations receive already-padded content.

QA test case additions (add to qa-test-cases-v1.1.0-003.yaml or a follow-up YAML):

ID Scenario Expected result
padding-001 R-L on a text selection with smart padding enabled; destination = editor Pasted text has a leading and trailing space (e.g., mySelection)
padding-002 R-L on a file path with smart padding enabled; destination = terminal Terminal receives the quoted, padded path (e.g., '/path/to/file')
padding-003 R-L RangeLink with smart padding enabled; destination = AI assistant Clipboard contains padded link; AI chat input receives padded link
padding-004 R-L on terminal selection with smart padding enabled; destination = editor Editor receives padded terminal-selected text
padding-005 Smart padding disabled (setting off); destination = any No leading/trailing spaces added to clipboard or destination

Suggested unit test additions:

  • In LinkGenerator.test.ts: assert applySmartPadding is called and the padded value is both the clipboard payload and the send payload in the ClipboardRouter strategy.
  • In FilePathPaster.test.ts, TextSelectionPaster.test.ts, TerminalSelectionService.test.ts: same pattern — spy on applySmartPadding and assert the padded value propagates to sendFn / sendTextToDestination without a paddingMode argument.

Gap 4 — Manual: Verify clipboard behavior with AI assistants

Goal: End-to-end verification that the clipboard write/restore lifecycle works correctly across the three built-in AI assistants under cold and warm paste flows.

QA test case additions (extend the "Built-in AI Assistants" section already added in PR #556):

ID Scenario Expected result
clipboard-ai-001 Cold paste → Claude Code; prior clipboard content exists After paste, prior clipboard content is restored
clipboard-ai-002 Warm paste → Claude Code (panel already open) Single clipboard write; prior content restored after CLIPBOARD_POST_PASTE_DELAY_MS
clipboard-ai-003 Cold paste → Cursor AI; prior clipboard content exists After paste, prior clipboard content is restored
clipboard-ai-004 Warm paste → Cursor AI Single clipboard write; prior content restored
clipboard-ai-005 Cold paste → GitHub Copilot Chat; prior clipboard content exists After paste, prior clipboard content is restored
clipboard-ai-006 Warm paste → GitHub Copilot Chat Single clipboard write; prior content restored
clipboard-ai-007 AI assistant focus/paste command throws; prior clipboard content exists RangeLink remains in clipboard (guided manual-paste); prior content NOT yet restored (user must paste manually)
clipboard-ai-008 Two rapid R-* operations to same AI assistant Second write does not clobber first; only the last write is in clipboard before paste

Suggested integration test additions (extend builtInAiAssistants.test.ts):

  • After cold/warm paste, read clipboard via vscode.env.clipboard.readText() and assert prior content is restored.
  • Assert log emission of clipboard restoration (or its absence on failure paths).

Acceptance Criteria

  • ClipboardRouter unit tests assert single clipboard write per operation for all destination types.
  • AIAssistantInsertFactory, TerminalInsertFactory, ManualPasteInsertFactory tests assert zero clipboard writes inside the factory.
  • QA YAML updated with padding scenarios (Gap 3) covering all four upstream call sites.
  • QA YAML updated with AI assistant clipboard-lifecycle scenarios (Gap 4) covering cold/warm flows and failure path.
  • Optional: integration tests in builtInAiAssistants.test.ts assert clipboard restoration after successful paste.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions