From ef18a7a79f19ff6ac4af077acc666dab22b2a19b Mon Sep 17 00:00:00 2001 From: adityarao3 Date: Fri, 4 Sep 2026 09:53:32 +0530 Subject: [PATCH] test(hud): guard full-screen passthrough bounds while recording getHudOverlayBounds() used to pass `isHudOverlayMousePassthroughSupported() && !hudOverlayRecordingActive` to getHudOverlayWindowBounds(), so starting a recording dropped the HUD from the full-screen click-through overlay to the compact 860x160 fallback window. That window is opaque to clicks, so it swallowed every click landing in the bottom-centre of the screen instead of passing it to the app being recorded, and the HUD's own Stop button became unreachable once the renderer requested passthrough. dd7af604 removed the `&& !hudOverlayRecordingActive` term while working on the recording webcam, but nothing covers that decision, so the regression can return unnoticed. The bug is still present in every published release (v1.3.3, v1.3.4-beta.1, v1.3.5-beta.2). This adds a test that drives the real createHudOverlayWindow() and setHudOverlayRecordingActive() code paths with electron mocked, and asserts the bounds applied while recording still cover the full work area. Verified it fails with the old expression restored and passes on current main. The test is skipped on Linux, where passthrough is unsupported and the compact fallback is the intended behaviour. Test-only; no production code changes. --- electron/hudOverlayRecordingBounds.test.ts | 98 ++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 electron/hudOverlayRecordingBounds.test.ts diff --git a/electron/hudOverlayRecordingBounds.test.ts b/electron/hudOverlayRecordingBounds.test.ts new file mode 100644 index 000000000..216c22d76 --- /dev/null +++ b/electron/hudOverlayRecordingBounds.test.ts @@ -0,0 +1,98 @@ +import { beforeEach, describe, expect, it, vi } from "vitest"; + +// A recording-sized work area keeps the expected bounds easy to read: the +// compact fallback window is 860x160 anchored to the bottom centre, while the +// passthrough overlay covers the whole work area. +const WORK_AREA = { x: 0, y: 0, width: 1920, height: 1080 }; + +const setBounds = vi.fn(); + +const electronScreen = { + getPrimaryDisplay: () => ({ workArea: WORK_AREA }), + getDisplayMatching: () => ({ workArea: WORK_AREA }), + getCursorScreenPoint: () => ({ x: 0, y: 0 }), + on: vi.fn(), + off: vi.fn(), + removeListener: vi.fn(), +}; + +// windows.ts reaches the screen module through createRequire("electron"), which +// bypasses vi.mock("electron"), so the CJS require has to be mocked as well. +vi.mock("node:module", async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + default: actual, + createRequire: () => (id: string) => { + if (id === "electron") { + return { screen: electronScreen }; + } + return actual.createRequire(import.meta.url)(id); + }, + }; +}); + +vi.mock("electron", () => { + class FakeBrowserWindow { + webContents = { send: vi.fn(), on: vi.fn(), setWindowOpenHandler: vi.fn() }; + isDestroyed = () => false; + isVisible = () => true; + getBounds = () => WORK_AREA; + setBounds = setBounds; + setIgnoreMouseEvents = vi.fn(); + setContentProtection = vi.fn(); + setAlwaysOnTop = vi.fn(); + showInactive = vi.fn(); + show = vi.fn(); + moveTop = vi.fn(); + once = vi.fn(); + on = vi.fn(); + loadURL = vi.fn(); + loadFile = vi.fn(); + } + + return { + app: { + getPath: () => "/tmp/recordly-test", + isPackaged: false, + isReady: () => true, + whenReady: vi.fn(), + on: vi.fn(), + }, + BrowserWindow: FakeBrowserWindow, + ipcMain: { on: vi.fn(), handle: vi.fn() }, + screen: electronScreen, + }; +}); + +describe("HUD overlay bounds while recording", () => { + beforeEach(() => { + vi.resetModules(); + setBounds.mockClear(); + }); + + // Regression guard for the overlay swallowing clicks during a recording. + // getHudOverlayBounds() used to pass + // `isHudOverlayMousePassthroughSupported() && !hudOverlayRecordingActive`, + // so starting a recording dropped the HUD to the opaque 860x160 fallback + // window. Every click inside that region hit the overlay instead of the app + // being recorded, and the HUD's own Stop button became unreachable once the + // renderer asked for passthrough. + // Linux has no mouse passthrough, so the compact fallback window is the + // expected behaviour there and this guard does not apply. + it.skipIf(process.platform === "linux")( + "keeps the full work area on passthrough platforms once recording starts", + async () => { + const windows = await import("./windows"); + + windows.createHudOverlayWindow(); + setBounds.mockClear(); + + windows.setHudOverlayRecordingActive(true); + + expect(setBounds).toHaveBeenCalled(); + const appliedBounds = setBounds.mock.calls.at(-1)?.[0]; + expect(appliedBounds).toEqual(WORK_AREA); + }, + ); +});