Skip to content

The agent that grows with you

test(desktop): cover both notification transports from any host

kshitijk4poora327f1ec1483
diff --git a/apps/desktop/electron/notification-ipc.test.ts b/apps/desktop/electron/notification-ipc.test.ts
index b69437089a5..9d857244724 100644
--- a/apps/desktop/electron/notification-ipc.test.ts
+++ b/apps/desktop/electron/notification-ipc.test.ts
@@ -27,23 +27,6 @@ vi.mock('electron', () => ({
import { registerNativeNotifications } from './notification-ipc'
-vi.mock('./notification-linux', () => ({
- createLinuxNotifications: () => ({
- create: () => {
- const notification = Object.assign(new EventEmitter(), {
- show() {
- host.shown.push(notification)
-
- return Promise.resolve(true)
- },
- close() {}
- })
-
- return notification
- }
- })
-}))
-
function windowStub() {
return {
isDestroyed: vi.fn(() => false),
@@ -62,8 +45,8 @@ it('returns native clicks and approval actions to the emitting window, not the p
const source = windowStub()
host.fromWebContents.mockReturnValue(source)
const focusWindow = vi.fn()
- registerNativeNotifications({ getMainWindow: () => primary as unknown as BrowserWindow, focusWindow })
- const notify = host.handle.mock.calls[0][1] as (event: IpcMainInvokeEvent, payload: HermesNotification) => boolean
+ registerNativeNotifications({ getMainWindow: () => primary as unknown as BrowserWindow, focusWindow, platform: 'darwin' })
+ const notify = host.handle.mock.calls[0][1] as (event: IpcMainInvokeEvent, payload: HermesNotification) => Promise<boolean>
const payload = {
kind: 'approval',
@@ -102,8 +85,8 @@ it('delivers plugin callbacks to their source and falls back only for navigation
const source = windowStub()
host.fromWebContents.mockReturnValue(source)
const focusWindow = vi.fn()
- registerNativeNotifications({ getMainWindow: () => primary as unknown as BrowserWindow, focusWindow })
- const notify = host.handle.mock.calls[0][1] as (event: IpcMainInvokeEvent, payload: HermesNotification) => boolean
+ registerNativeNotifications({ getMainWindow: () => primary as unknown as BrowserWindow, focusWindow, platform: 'darwin' })
+ const notify = host.handle.mock.calls[0][1] as (event: IpcMainInvokeEvent, payload: HermesNotification) => Promise<boolean>
await notify({ sender: source.webContents } as unknown as IpcMainInvokeEvent, {
kind: 'plugin',
notifyId: 'source-callback',
diff --git a/apps/desktop/electron/notification-ipc.ts b/apps/desktop/electron/notification-ipc.ts
index a06dc77b61f..c39f883dff8 100644
--- a/apps/desktop/electron/notification-ipc.ts
+++ b/apps/desktop/electron/notification-ipc.ts
@@ -9,13 +9,18 @@ import type { HermesNotification } from './notification-types'
interface NotificationHost {
getMainWindow: () => BrowserWindow | null
focusWindow: (window: BrowserWindow) => void
+ platform?: NodeJS.Platform
}
-export function registerNativeNotifications({ getMainWindow, focusWindow }: NotificationHost): void {
+export function registerNativeNotifications({
+ getMainWindow,
+ focusWindow,
+ platform = process.platform
+}: NotificationHost): void {
const dedupeIntervalMs = 1000
const isDuplicateNotification = createEventDeduper(dedupeIntervalMs)
const deliveries = new Map<string, Promise<boolean>>()
- const linux = process.platform === 'linux' ? createLinuxNotifications() : undefined
+ const linux = platform === 'linux' ? createLinuxNotifications() : undefined
const notifications = createNotificationRegistry({ releaseOnClose: Boolean(linux) })
ipcMain.handle('hermes:notify', async (event, payload: HermesNotification) => {
diff --git a/apps/desktop/electron/notification-linux.test.ts b/apps/desktop/electron/notification-linux.test.ts
index 9aaaf147837..11b10d048cc 100644
--- a/apps/desktop/electron/notification-linux.test.ts
+++ b/apps/desktop/electron/notification-linux.test.ts
@@ -135,7 +135,7 @@ function setup(alreadyRunning = false) {
const source = { isDestroyed: vi.fn(() => false), webContents: { send: vi.fn() } }
host.fromWebContents.mockReturnValue(source)
const focusWindow = vi.fn()
- registerNativeNotifications({ getMainWindow: () => primary as unknown as BrowserWindow, focusWindow })
+ registerNativeNotifications({ getMainWindow: () => primary as unknown as BrowserWindow, focusWindow, platform: 'linux' })
const notify = (payload: HermesNotification) =>
Promise.resolve(
@@ -187,7 +187,7 @@ afterEach(() => {
vi.unstubAllEnvs()
})
-it.skipIf(process.platform !== 'linux')(
+it(
'bounds failed delivery without dropping older callbacks, and retries only on a later request',
async () => {
const unavailable = setup()
@@ -245,7 +245,7 @@ it.skipIf(process.platform !== 'linux')(
}
)
-it.skipIf(process.platform !== 'linux')(
+it(
'releases naturally closed notifications while retaining other click targets',
async () => {
const h = setup(true)
@@ -270,7 +270,7 @@ it.skipIf(process.platform !== 'linux')(
}
)
-it.skipIf(process.platform !== 'linux')(
+it(
'preserves activation, dedupe and source ownership while fencing daemon ID reuse',
async () => {
const race = setup(true)