Files
hermes-agent/apps/desktop/electron/preload-version-scope.test.ts
Willy Morin c3d5d4eca6 fix(desktop): scope version label to the active connection/profile
The preload getVersion bridge dropped the {connectionId, profile} scope the
renderer passes (lost in merge b3bfc3afe5), so the version label always
reported the primary gateway. Forward the scope, re-fetch on any
connection/profile scope change with a stale-reply guard, and scope the
native About panel to the focused window.

Fixes #139333
2026-10-27 13:23:31 -07:00

36 lines
1.3 KiB
TypeScript

import { expect, it, vi } from 'vitest'
const host = vi.hoisted(() => ({
exposeInMainWorld: vi.fn(),
invoke: vi.fn().mockResolvedValue({ appVersion: '1.0.0' }),
send: vi.fn(),
sendSync: vi.fn((): unknown => ({}))
}))
vi.mock('electron', () => ({
contextBridge: { exposeInMainWorld: host.exposeInMainWorld },
ipcRenderer: { invoke: host.invoke, send: host.send, sendSync: host.sendSync, on: vi.fn(), removeListener: vi.fn() },
webFrame: {},
webUtils: {}
}))
type VersionBridge = { getVersion: (scope?: { connectionId?: string; profile?: string }) => Promise<unknown> }
async function bridge(): Promise<VersionBridge> {
await import('./preload')
const registration = host.exposeInMainWorld.mock.calls.find(([name]): boolean => name === 'hermesDesktop')
return registration![1] as VersionBridge
}
// The renderer scopes the version request to the selected connection/profile;
// dropping it here makes main answer from the primary route instead.
it('forwards the connection/profile scope to hermes:version', async (): Promise<void> => {
const exposed = await bridge()
host.invoke.mockClear()
await exposed.getVersion({ connectionId: 'remote-box', profile: 'work' })
expect(host.invoke).toHaveBeenCalledExactlyOnceWith('hermes:version', { connectionId: 'remote-box', profile: 'work' })
})