fix(ci): handle windows-only test behavior
This commit is contained in:
parent
92a1c2067b
commit
24d96b5bec
2 changed files with 37 additions and 8 deletions
|
|
@ -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<string, unknown> {
|
||||
const mock = ElectronNotification as unknown as {
|
||||
mock: { calls: [Record<string, unknown>][] };
|
||||
};
|
||||
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>(.*?)<\/text>/g)].map((match) =>
|
||||
decodeXmlText(match[1] ?? '')
|
||||
);
|
||||
return {
|
||||
...options,
|
||||
title: textRows[0],
|
||||
body: textRows.slice(1).join('\n'),
|
||||
};
|
||||
}
|
||||
|
||||
function makeTeamPayload(
|
||||
|
|
|
|||
|
|
@ -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 () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue