Skip to content

The agent that grows with you

test(tui): switcher-close tests re-send ^d until the switcher hears it

Teknium0f3eac0b8f7c
diff --git a/ui-tui/src/__tests__/canonicalSwitcherClose.test.tsx b/ui-tui/src/__tests__/canonicalSwitcherClose.test.tsx
index 1674e81f706..525c9195fed 100644
--- a/ui-tui/src/__tests__/canonicalSwitcherClose.test.tsx
+++ b/ui-tui/src/__tests__/canonicalSwitcherClose.test.tsx
@@ -165,9 +165,16 @@ function mountSwitcher(onClose: (id: string) => Promise<null | { closed?: boolea
const closeLive = async () => {
await vi.waitFor(() => expect(out.text).toContain('Current conversation'), WAIT)
- // `^d` on the live row the view is on (the initial selection lands there).
- stdin.write('\u0004')
- await vi.waitFor(() => expect(onClose).toHaveBeenCalledWith('live'), WAIT)
+ // `^d` on the live row the view is on (the initial selection lands there). Ink attaches the
+ // switcher's key listener in a passive effect that can land after the first frame paints on a
+ // loaded host, so a single early write is dropped: re-send until the switcher has heard it.
+ await vi.waitFor(() => {
+ if (!vi.mocked(onClose).mock.calls.length) {
+ stdin.write('\u0004')
+ }
+
+ expect(onClose).toHaveBeenCalledWith('live')
+ }, WAIT)
await vi.waitFor(() => {
instance.rerender(React.cloneElement(element))
expect(out.text).toMatch(/error: /)