Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

test(desktop-app): cover the non-left-button guard on the chat-drawer resize handle

Diego Zacariasf0314177360b
diff --git a/desktop-app/ui/src/hooks/__tests__/useChatDrawerResize.reentry.test.tsx b/desktop-app/ui/src/hooks/__tests__/useChatDrawerResize.reentry.test.tsx
index c698ac48e..d9a3f3828 100644
--- a/desktop-app/ui/src/hooks/__tests__/useChatDrawerResize.reentry.test.tsx
+++ b/desktop-app/ui/src/hooks/__tests__/useChatDrawerResize.reentry.test.tsx
@@ -62,4 +62,57 @@ describe('useChatDrawerResize re-entrant drag leak', () => {
expect(result.current.width).toBe(settledWidth)
expect(result.current.isResizing).toBe(false)
})
+
+ // L1: the `if (event.button !== 0) return` guard on the mousedown handler had
+ // no direct coverage — the reentry test above fires `button: 0` on both
+ // mousedowns, so an inverted or deleted guard stayed green there. A right-click
+ // over the 8px strip while the left button is held (button 2) must be a no-op:
+ // it must not start/alter a drag, and no stray resize may follow the release.
+ it('ignores a non-left mousedown during an active drag and starts no second drag', () => {
+ const ref = createRef<HTMLElement>()
+ const { result } = renderHook(() => useChatDrawerResize(ref, true))
+
+ // Left button starts drag #1.
+ const leftPreventDefault = vi.fn()
+ act(() =>
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ (result.current as any).onResizeHandleMouseDown({
+ button: 0,
+ clientX: 500,
+ preventDefault: leftPreventDefault,
+ currentTarget: { closest: () => null },
+ } as unknown as React.MouseEvent<HTMLElement>)
+ )
+ // Inverted guard (`=== 0`) would ignore this and never start the drag.
+ expect(result.current.isResizing).toBe(true)
+ expect(leftPreventDefault).toHaveBeenCalledTimes(1)
+
+ // Right button (button 2) mousedown WHILE drag #1 is live. The guard returns
+ // before touching anything — no preventDefault, drag #1 untouched.
+ const rightPreventDefault = vi.fn()
+ act(() =>
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ (result.current as any).onResizeHandleMouseDown({
+ button: 2,
+ clientX: 50,
+ preventDefault: rightPreventDefault,
+ currentTarget: { closest: () => null },
+ } as unknown as React.MouseEvent<HTMLElement>)
+ )
+ // A deleted guard would let this proceed and call preventDefault.
+ expect(rightPreventDefault).not.toHaveBeenCalled()
+ // Drag #1 is still the one and only active drag.
+ expect(result.current.isResizing).toBe(true)
+
+ // Release drag #1.
+ act(() => window.dispatchEvent(new MouseEvent('mouseup')))
+ expect(result.current.isResizing).toBe(false)
+ const settledWidth = result.current.width
+
+ // The button-2 mousedown installed no second, orphanable drag: a bare
+ // mousemove after release must not resize.
+ act(() => window.dispatchEvent(new MouseEvent('mousemove', { clientX: 10 })))
+ expect(result.current.width).toBe(settledWidth)
+ expect(result.current.isResizing).toBe(false)
+ })
})