perf: optimize app startup and background lifecycles

This commit is contained in:
inman
2026-08-19 00:56:15 +08:00
parent 31332f6d76
commit 927e13349b
121 changed files with 4359 additions and 1400 deletions

View File

@@ -89,4 +89,28 @@ describe('Host API IPC proxy', () => {
expect(headers.get('authorization')).toBe('Bearer host-token');
expect(headers.get('x-niancode-renderer-capability')).toBe('renderer-token');
});
it('dispatches short JSON requests in Main without opening loopback HTTP', async () => {
const fetchMock = vi.fn();
vi.stubGlobal('fetch', fetchMock);
vi.doMock('../../electron/api/host-api-dispatcher', () => ({
dispatchHostApiRequest: vi.fn().mockResolvedValue({
status: 200,
ok: true,
json: { success: true, transport: 'test' },
}),
}));
const { registerHostApiProxyHandlers } = await import('../../electron/main/ipc/host-api-proxy');
registerHostApiProxyHandlers({} as never);
const fetchHandler = handleMock.mock.calls.find(([channel]) => channel === 'hostapi:fetch')?.[1];
const result = await fetchHandler(undefined, { path: '/api/app/runtime-info' });
expect(fetchMock).not.toHaveBeenCalled();
expect(result).toEqual({
ok: true,
data: { status: 200, ok: true, json: { success: true, transport: 'test' }, transport: 'dispatcher' },
});
});
});