From fb751c542bc935158aaa0d01c0694eb3bb6b2919 Mon Sep 17 00:00:00 2001
From: Jacob Richman <jacob314@gmail.com>
Date: Fri, 25 Jul 2025 16:29:15 -0700
Subject: Regression test for paste when the terminal lacks focus. (#4898)

---
 .../cli/src/ui/components/InputPrompt.test.tsx     | 31 ++++++++++++++++++++++
 1 file changed, 31 insertions(+)

(limited to 'packages/cli/src/ui/components/InputPrompt.test.tsx')

diff --git a/packages/cli/src/ui/components/InputPrompt.test.tsx b/packages/cli/src/ui/components/InputPrompt.test.tsx
index 60ba648d..1d0b868f 100644
--- a/packages/cli/src/ui/components/InputPrompt.test.tsx
+++ b/packages/cli/src/ui/components/InputPrompt.test.tsx
@@ -1121,4 +1121,35 @@ describe('InputPrompt', () => {
       unmount();
     });
   });
+
+  describe('unfocused paste', () => {
+    it('should handle bracketed paste when not focused', async () => {
+      props.focus = false;
+      const { stdin, unmount } = render(<InputPrompt {...props} />);
+      await wait();
+
+      stdin.write('\x1B[200~pasted text\x1B[201~');
+      await wait();
+
+      expect(mockBuffer.handleInput).toHaveBeenCalledWith(
+        expect.objectContaining({
+          paste: true,
+          sequence: 'pasted text',
+        }),
+      );
+      unmount();
+    });
+
+    it('should ignore regular keypresses when not focused', async () => {
+      props.focus = false;
+      const { stdin, unmount } = render(<InputPrompt {...props} />);
+      await wait();
+
+      stdin.write('a');
+      await wait();
+
+      expect(mockBuffer.handleInput).not.toHaveBeenCalled();
+      unmount();
+    });
+  });
 });
-- 
cgit v1.2.3

