The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(desktop): cover the real macOS Cmd+F chord in the main-process handler (#81727)
Chen Jin75f0602301cc
diff --git a/apps/desktop/electron/find-in-page.test.ts b/apps/desktop/electron/find-in-page.test.tsindex a21db92d77a..8e7352e9647 100644--- a/apps/desktop/electron/find-in-page.test.ts+++ b/apps/desktop/electron/find-in-page.test.ts@@ -253,15 +253,39 @@ describe('installFindShortcut', () => {uninstall()})- test('sends hermes:open-find-bar on Cmd+F (macOS primary accelerator)', () => {+ // macOS branch: inject `isMac: () => true` so we exercise the REAL+ // `meta` (Cmd) path — previously untested, because `process.platform` is+ // baked at import time and the old "Cmd+F" case actually sent Ctrl.+ test('sends hermes:open-find-bar on Cmd+F (meta) on macOS and prevents default', () => {const wc = makeFakeWebContents()const win = makeFakeWindow(wc)- const uninstall = installFindShortcut(win)+ const uninstall = installFindShortcut(win, () => true)++ // Cmd+F on macOS: meta held, no control/alt/shift.+ wc.emit('before-input-event', {}, {+ key: 'f',+ control: false,+ meta: true,+ alt: false,+ shift: false,+ })++ assert.deepEqual(wc.calls.send, [+ { channel: 'hermes:open-find-bar', payload: undefined }+ ])++ uninstall()+ })++ // The design intentionally accepts literal Ctrl on macOS too (dual-channel)+ // so a non-macOS layout still works. Pin that behavior so the width of the+ // chord doesn't silently drift.+ test('accepts literal Ctrl+F on macOS (dual-channel with Cmd)', () => {+ const wc = makeFakeWebContents()+ const win = makeFakeWindow(wc)+ const uninstall = installFindShortcut(win, () => true)- // On macOS, Cmd is `meta`. We can't flip IS_MAC at runtime in the- // module under test, but the helper also accepts literal Ctrl on macOS- // so a non-macOS layout still works — verify the macOS-equivalent- // chord via Ctrl here (the macOS-specific Cmd path is a thin alias).+ // Ctrl+F with no meta on macOS still opens the FindBar.wc.emit('before-input-event', {}, {key: 'F',control: true,@@ -270,8 +294,30 @@ describe('installFindShortcut', () => {shift: false,})- assert.equal(wc.calls.send.length, 1)- assert.equal(wc.calls.send[0].channel, 'hermes:open-find-bar')+ assert.deepEqual(wc.calls.send, [+ { channel: 'hermes:open-find-bar', payload: undefined }+ ])++ uninstall()+ })++ // Cross-check: a bare Ctrl+F WITHOUT meta must NOT open on Linux/Windows,+ // where only `control` counts (the macOS `meta || control` widening must not+ // leak across the platform boundary).+ test('does NOT fire for Ctrl+F with meta only on Linux/Windows', () => {+ const wc = makeFakeWebContents()+ const win = makeFakeWindow(wc)+ const uninstall = installFindShortcut(win, () => false)++ wc.emit('before-input-event', {}, {+ key: 'f',+ control: false,+ meta: true,+ alt: false,+ shift: false,+ })++ assert.equal(wc.calls.send.length, 0, 'meta (Cmd) is not a valid chord on non-macOS')uninstall()})diff --git a/apps/desktop/electron/find-in-page.ts b/apps/desktop/electron/find-in-page.tsindex 1ad3275320c..497810c1d5e 100644--- a/apps/desktop/electron/find-in-page.ts+++ b/apps/desktop/electron/find-in-page.ts@@ -135,11 +135,14 @@ export function installFoundInPageForwarder(webContents: Electron.WebContents |* `webContents.findInPage`). This helper just guarantees that a Ctrl/Cmd+F* press reaches that pipeline.*+ * `isMac` is injectable so the macOS-modifier branch can be exercised by+ * unit tests without rebooting the process under a different platform.+ ** Returns an uninstall fn that detaches the listener.*/-const IS_MAC = process.platform === 'darwin'+const IS_MAC = () => process.platform === 'darwin'-export function installFindShortcut(window: Electron.BrowserWindow): () => void {+export function installFindShortcut(window: Electron.BrowserWindow, isMac: () => boolean = IS_MAC): () => void {const { webContents } = windowif (!webContents || webContents.isDestroyed()) {return () => {}@@ -155,7 +158,7 @@ export function installFindShortcut(window: Electron.BrowserWindow): () => void// is on a non-macOS layout. On Pop!_OS / GNOME the GTK compositor owns// Ctrl+F before the renderer's keydown fires — this main-process handler// runs strictly before that (#81727).- const hasMod = IS_MAC ? input.meta || input.control : input.control+ const hasMod = isMac() ? input.meta || input.control : input.controlconst isFindChord =key === 'f' &&hasMod &&