Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

test(hud): pin the sequence and the window, not the tail and the prototype

Claude57bd437fdfa1
diff --git a/src/components/launch/LaunchWindow.test.tsx b/src/components/launch/LaunchWindow.test.tsx
index 0038ca2ea..305ee8a01 100644
--- a/src/components/launch/LaunchWindow.test.tsx
+++ b/src/components/launch/LaunchWindow.test.tsx
@@ -484,8 +484,16 @@ describe("LaunchWindow record button", () => {
</StrictMode>,
);
+ // The whole sequence, not its tail: because the wrapper dedupes, a cleanup
+ // that is deleted outright and a cleanup that asks for the wrong value both
+ // collapse to a lone [true] and would satisfy an assertion on the last call.
+ // Only mount → hand input back → mount again distinguishes the three.
await waitFor(() => {
- expect(window.electronAPI.setHudOverlayIgnoreMouseEvents).toHaveBeenLastCalledWith(true);
+ expect(vi.mocked(window.electronAPI.setHudOverlayIgnoreMouseEvents).mock.calls).toEqual([
+ [true],
+ [false],
+ [true],
+ ]);
});
});
diff --git a/technical-documentation/architecture/recording.md b/technical-documentation/architecture/recording.md
index e765a3cc5..1dc638375 100644
--- a/technical-documentation/architecture/recording.md
+++ b/technical-documentation/architecture/recording.md
@@ -18,7 +18,7 @@ The HUD starts and controls a recording. The source selector chooses a display o
## The HUD
-`LaunchWindow` is the recording controller. Its control row exposes recording, pause, source, microphone, system-audio, webcam, cursor, settings, and stop/restart actions through the HUD controls. The overlay is click-through, so it does not intercept the application being recorded — but it is never *born* that way: the renderer asks for it on mount over `hud-overlay-ignore-mouse-events`, and `electron/windows.ts` applies it as `setIgnoreMouseEvents(ignore)`, with no `{ forward: true }`. While the window is input-transparent Chromium delivers it no pointer events at all, so the way back out is a poll: the main process samples the OS cursor and pushes the window-relative point over `hud-overlay-cursor`, and the renderer hit-tests it to decide when the HUD's own controls temporarily opt into pointer handling. (Until #385 the lift was Electron's `{ forward: true }` — a global `WH_MOUSE_LL` hook on Windows that Windows can revoke without telling the app, leaving the HUD painted and permanently dead. The poll replaced it.)
+`LaunchWindow` is the recording controller. Its control row exposes recording, pause, source, microphone, system-audio, webcam, cursor, settings, and stop/restart actions through the HUD controls. The overlay is click-through, so it does not intercept the application being recorded — but it is never *born* that way: the renderer asks for it on mount over `hud-overlay-ignore-mouse-events`, and `electron/windows.ts` applies it as `setIgnoreMouseEvents(ignore)`, with no `{ forward: true }`. While the window is input-transparent Chromium delivers it no pointer events at all, so the way back out is a poll: the main process samples the OS cursor and pushes the window-relative point over `hud-overlay-cursor`, and the renderer hit-tests it to decide when the HUD's own controls temporarily opt into pointer handling. On Linux none of this runs: `setIgnoreMouseEvents` is a no-op there, so the renderer never asks for click-through and the HUD stays interactive — which is why its drag region sits on the grab handle rather than on the transparent root. (Until #385 the lift was Electron's `{ forward: true }` — a global `WH_MOUSE_LL` hook on Windows that Windows can revoke without telling the app, leaving the HUD painted and permanently dead. The poll replaced it.)
Electron applies `setContentProtection(true)` to the HUD window (`electron/windows.ts:83`). This keeps the controller out of captures and also makes it invisible in screenshots. For a testing session only, `OPENSCREEN_DISABLE_CONTENT_PROTECTION=1` disables the protection; the code warns that the HUD then appears in captures. The tray icon is the reliable way to refocus OpenScreen or stop a recording when the click-through HUD is not convenient or is not visible.
diff --git a/tests/e2e/windows-native-checklist.spec.ts b/tests/e2e/windows-native-checklist.spec.ts
index 407494ea4..0945de93f 100644
--- a/tests/e2e/windows-native-checklist.spec.ts
+++ b/tests/e2e/windows-native-checklist.spec.ts
@@ -196,7 +196,7 @@ test.describe("Windows native checklist smoke tests", () => {
// so no IPC from the renderer can slip into it: what comes back is
// construction, and construction only.
const duringConstruction = await app.evaluate(({ app: electronApp, BrowserWindow }) => {
- const tape: unknown[][] = [];
+ const tape: Array<{ hud: boolean; args: unknown[] }> = [];
const original = BrowserWindow.prototype.setIgnoreMouseEvents;
globalThis.__hudTape = tape;
globalThis.__hudSetIgnoreMouseEvents = original;
@@ -204,7 +204,19 @@ test.describe("Windows native checklist smoke tests", () => {
this: InstanceType<typeof BrowserWindow>,
...args: Parameters<typeof original>
) {
- tape.push(args);
+ // The patch is on the prototype, so every window's calls land here.
+ // Tag them: an unfiltered tape would let another overlay's options
+ // object fail the `forward` claim under this test's name, and let its
+ // bare [true] satisfy the first-ask claim. Tag rather than filter,
+ // because loadURL runs after this handler is installed — during
+ // construction the URL is still "", and that is exactly the window
+ // the empty-tape assertion below has to be able to see.
+ tape.push({
+ hud: this.isDestroyed()
+ ? false
+ : this.webContents.getURL().includes("windowType=hud-overlay"),
+ args,
+ });
return original.apply(this, args);
};
@@ -218,19 +230,29 @@ test.describe("Windows native checklist smoke tests", () => {
expect(duringConstruction).toEqual([]);
- // And the renderer does ask, once it has mounted.
+ // And the renderer does ask, once it has mounted. Keep the snapshot the
+ // poll settled on rather than fetching a second time, so all three claims
+ // below are made about one state of the tape and not three.
+ let hudCalls: unknown[][] = [];
await expect
- .poll(() => app.evaluate(() => globalThis.__hudTape ?? []), { timeout: 20_000 })
+ .poll(
+ async () => {
+ hudCalls = await app.evaluate(() =>
+ (globalThis.__hudTape ?? []).filter((entry) => entry.hud).map((entry) => entry.args),
+ );
+ return hudCalls;
+ },
+ { timeout: 20_000 },
+ )
.toContainEqual([true]);
// Containment is not enough by itself: a second caller asking with
// `forward` would sit in the tape beside the renderer's own bare [true]
// and still satisfy it, which is exactly the shape a re-arm of the hook
- // takes. So pin the whole tape — the first ask is the renderer's, and no
- // ask anywhere carries an options object, the only way `forward` returns.
- const tape = await app.evaluate(() => globalThis.__hudTape ?? []);
- expect(tape[0]).toEqual([true]);
- expect(tape.filter((call) => call.length > 1)).toEqual([]);
+ // takes. So pin the HUD's whole tape — the first ask is the renderer's,
+ // and no ask carries an options object, the only way `forward` returns.
+ expect(hudCalls[0]).toEqual([true]);
+ expect(hudCalls.filter((call) => call.length > 1)).toEqual([]);
} finally {
await app.evaluate(({ BrowserWindow }) => {
const original = globalThis.__hudSetIgnoreMouseEvents;
@@ -248,7 +270,7 @@ test.describe("Windows native checklist smoke tests", () => {
declare global {
// Set inside the main process by the click-through test above, read back by a
// second evaluate — the only way to observe calls that land between two of them.
- var __hudTape: unknown[][] | undefined;
+ var __hudTape: Array<{ hud: boolean; args: unknown[] }> | undefined;
var __hudSetIgnoreMouseEvents:
| ((ignore: boolean, options?: { forward?: boolean }) => void)
| undefined;