Skip to content

test(tui): clipboard.ts coverage gap - #22253

Closed
wesleysimplicio wants to merge 1 commit into
NousResearch:mainfrom
wesleysimplicio:tests/tui-clipboard-coverage
Closed

test(tui): clipboard.ts coverage gap#22253
wesleysimplicio wants to merge 1 commit into
NousResearch:mainfrom
wesleysimplicio:tests/tui-clipboard-coverage

Conversation

@wesleysimplicio

@wesleysimplicio wesleysimplicio commented May 9, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

ui-tui/src/lib/clipboard.ts had several uncovered branches in clipboard.test.ts:

Root cause

The detailed rationale from the original PR body is preserved below. This template update keeps the review structure consistent with #29640.

Fix

Why this shape

This shape mirrors #29640 so reviewers can quickly compare scope, root cause, fix, tests, and related context without having to decode a custom PR description.

Tests

  • Veja a descrição original preservada abaixo para detalhes de validação, testes e notas de verificação.
Original body

Related PRs / issues

  • Original body preserved below for full context.
Original body

Summary

ui-tui/src/lib/clipboard.ts had several uncovered branches in clipboard.test.ts:

What Changed

  • Standardized this PR body to the current Hermes Turbo template.
  • Preserved the original detailed description below for reference.

Fluxo

A mudança continua seguindo o fluxo original descrito na seção preservada abaixo, sem ampliar o escopo funcional deste PR.

Visão

A padronização melhora a revisão, reduz ruído e evita deriva de formatação entre PRs abertos.

Test Plan

  • Veja a descrição original preservada abaixo para detalhes de validação, testes e notas de verificação.
Original body

Summary

ui-tui/src/lib/clipboard.ts had several uncovered branches in clipboard.test.ts:

  • isUsableClipboardText: null input, NUL-byte rejection mid-text, whitespace-control allowance (\n\r\t), absolute floor of 2 stray controls in short text, the 2% scaling threshold for long text, and U+FFFD replacement-char counting.
  • readClipboardText: WSL powershell.exe failure → xclip fallback, non-string stdout returning null, bare-Linux skipping wl-paste straight to xclip.
  • writeClipboardText: empty-string forwarded to backend (no short-circuit), bare-Linux failing both xclip and xsel.

Adds 13 tests in a new file clipboardCoverageGap.test.ts — no production code change, only fills gaps.

Test plan

  • npx vitest run src/__tests__/clipboardCoverageGap.test.ts → 13/13 pass
  • Full ui-tui regression: npx vitest run661/661 pass

Generated by Hermes Turbo


Generated by Hermes Turbo

…cks)

The existing clipboard.test.ts covers the happy paths for pbpaste, PowerShell,
wl-paste, and xclip, plus 3 isUsableClipboardText cases (normal/empty/binary).
Several real branches had no coverage:

isUsableClipboardText:
- null input (early !text guard)
- NUL byte rejection regardless of surrounding printable text
- Tab/CR/LF allowed as non-suspicious whitespace controls
- The 2-control floor for short strings (boundary at 2 vs 3)
- The 2% scaling on long strings (boundary at 2% vs >2%)
- U+FFFD replacement char counted as suspicious

readClipboardText:
- WSL falls through powershell.exe to xclip on first failure
- Returns null if backend resolves with non-string stdout
- Bare Linux skips wl-paste and goes straight to xclip

writeClipboardText:
- Empty string forwarded to backend without short-circuit
- Bare Linux returns false when xclip AND xsel both exit non-zero

Pure helper coverage; no production change.
Copilot AI review requested due to automatic review settings May 9, 2026 03:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds targeted Vitest coverage for previously untested branches in ui-tui/src/lib/clipboard.ts, without changing production behavior. It focuses on edge cases across clipboard text validation and backend fallback logic.

Changes:

  • Added new test suite covering additional isUsableClipboardText edge cases (null, NUL byte, tolerated controls, 2% threshold, U+FFFD).
  • Added new test cases for readClipboardText fallback/selection behavior (WSL fallback, non-string stdout, bare-Linux path).
  • Added new test cases for writeClipboardText behavior (empty string passthrough, bare-Linux xclip→xsel failure).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@alt-glitch alt-glitch added type/test Test coverage or test infrastructure comp/tui Terminal UI (ui-tui/ + tui_gateway/) P3 Low — cosmetic, nice to have labels May 9, 2026
@wesleysimplicio

Copy link
Copy Markdown
Contributor Author

Closing non-fix PR as requested — mantendo apenas PRs de fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tui Terminal UI (ui-tui/ + tui_gateway/) P3 Low — cosmetic, nice to have type/test Test coverage or test infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants