Skip to content

test(web): add unit tests for terminal paste guard - #78

Merged
wolfiesch merged 1 commit into
LycaonLLC:mainfrom
dylantirandaz:test/paste-guard-unit-tests
Jul 19, 2026
Merged

test(web): add unit tests for terminal paste guard#78
wolfiesch merged 1 commit into
LycaonLLC:mainfrom
dylantirandaz:test/paste-guard-unit-tests

Conversation

@dylantirandaz

@dylantirandaz dylantirandaz commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

What this changes

Adds unit tests for apps/web/src/features/terminal/paste-guard.ts, the paste-safety heuristics module that decides whether clipboard text needs an explicit confirmation before reaching a PTY. The module had no test coverage; this PR adds tests only — no source behavior changes.

The colocated paste-guard.test.ts covers the observable contract:

  • Each of the 11 destructive patterns matches representative input and surfaces its exact deduplicated label (e.g. rm -rf /tmp/x → "force-deletes files", curl example.com/x | sh → "pipes a download into a shell", :(){ :|:& };: → "is a fork bomb"), including label ordering and deduplication when a pattern matches twice.
  • Negative cases: benign single-line input (ls -la) requires no confirmation, and ordinary prose / safe commands that the regexes intentionally don't match (e.g. "the rm command is dangerous", "read the sudoers file", "rebooting the conversation", curl example.com without a pipe) stay clean.
  • Boundaries: exactly LARGE_PASTE_CHARS chars is large, one char under is not; a single trailing newline counts as multiline; the empty string reports 0 lines and no confirmation.
  • preparePasteForPty: CRLF, LF, and mixed newlines normalize to CR; lone CRs pass through.
  • pastePreview: input over PASTE_PREVIEW_CHARS truncates with truncated: true, input over 6 lines truncates to 6 lines, and short input passes through with truncated: false.

Verification

  • pnpm --filter @t4-code/web test — 72 test files, 1038 tests, all passed (new file included; 43 tests in paste-guard.test.ts alone).
  • pnpm check — passed (release contract, provenance, lint, typecheck).

Checklist

  • pnpm check passes (release contract, provenance, lint, typecheck)
  • pnpm test passes; new behavior has a test that fails without this change
  • Any pasted logs or screenshots are redacted: no secrets, tokens, pairing codes, or private paths
  • Ported code (T3 Code / OMP) follows the provenance rules in THIRD_PARTY_NOTICES.md

@wolfiesch
wolfiesch force-pushed the test/paste-guard-unit-tests branch from 3861f80 to dd36b8d Compare July 19, 2026 22:31
@wolfiesch
wolfiesch merged commit 827001d into LycaonLLC:main Jul 19, 2026
4 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.

2 participants