diff --git a/test/main/services/infrastructure/NotificationManager.team.test.ts b/test/main/services/infrastructure/NotificationManager.team.test.ts index 4631faa0..8fd7b37b 100644 --- a/test/main/services/infrastructure/NotificationManager.team.test.ts +++ b/test/main/services/infrastructure/NotificationManager.team.test.ts @@ -22,6 +22,14 @@ vi.mock('electron', () => ({ { isSupported: vi.fn().mockReturnValue(true) } ), BrowserWindow: vi.fn(), + nativeImage: { + createFromPath: vi.fn(() => ({ + isEmpty: vi.fn().mockReturnValue(true), + })), + createFromDataURL: vi.fn(() => ({ + isEmpty: vi.fn().mockReturnValue(false), + })), + }, })); // --- Mock fs/promises to prevent disk I/O --- @@ -69,11 +77,32 @@ import { ConfigManager } from '@main/services/infrastructure/ConfigManager'; import { NotificationManager } from '@main/services/infrastructure/NotificationManager'; import { Notification as ElectronNotification } from 'electron'; +function decodeXmlText(value: string): string { + return value + .replace(/"/g, '"') + .replace(/'/g, "'") + .replace(/</g, '<') + .replace(/>/g, '>') + .replace(/&/g, '&'); +} + function getLastNotificationOptions(): Record { const mock = ElectronNotification as unknown as { mock: { calls: [Record][] }; }; - return mock.mock.calls.at(-1)?.[0] ?? {}; + const options = mock.mock.calls.at(-1)?.[0] ?? {}; + if (typeof options.toastXml !== 'string') { + return options; + } + + const textRows = [...options.toastXml.matchAll(/(.*?)<\/text>/g)].map((match) => + decodeXmlText(match[1] ?? '') + ); + return { + ...options, + title: textRows[0], + body: textRows.slice(1).join('\n'), + }; } function makeTeamPayload( diff --git a/test/main/services/runtime/anthropicTeamApiKeyHelper.test.ts b/test/main/services/runtime/anthropicTeamApiKeyHelper.test.ts index a374f05c..979dbc9b 100644 --- a/test/main/services/runtime/anthropicTeamApiKeyHelper.test.ts +++ b/test/main/services/runtime/anthropicTeamApiKeyHelper.test.ts @@ -59,19 +59,19 @@ describe('anthropicTeamApiKeyHelper', () => { expect(helperRaw).toContain('KEY_FILE='); expect(helperRaw).not.toContain(apiKey); const parsedSettings = JSON.parse(settingsRaw) as { apiKeyHelper: string }; - const shellResult = await execFileAsync('/bin/sh', ['-c', parsedSettings.apiKeyHelper]); - expect(shellResult.stdout.trim()).toBe(apiKey); if (process.platform !== 'win32') { + const shellResult = await execFileAsync('/bin/sh', ['-c', parsedSettings.apiKeyHelper]); + expect(shellResult.stdout.trim()).toBe(apiKey); expect((await stat(material.keyPath)).mode & 0o777).toBe(0o600); expect((await stat(material.helperPath)).mode & 0o777).toBe(0o700); expect((await stat(material.settingsPath)).mode & 0o777).toBe(0o600); - } - await verifyAnthropicTeamApiKeyHelperMaterial({ - helperPath: material.helperPath, - expectedApiKey: apiKey, - }); + await verifyAnthropicTeamApiKeyHelperMaterial({ + helperPath: material.helperPath, + expectedApiKey: apiKey, + }); + } }); it('cleans only owned helper material files', async () => {