feat: add Makelore Robot hardware module

This commit is contained in:
2026-08-13 23:17:22 +08:00
parent 22add3f01f
commit aba5cae286
25 changed files with 3169 additions and 72 deletions

View File

@@ -61,4 +61,32 @@ describe('Host API IPC proxy', () => {
data: { status: 200, ok: true, json: { success: true } },
});
});
it('preserves ordinary renderer headers but replaces forged security headers', async () => {
const fetchMock = vi.fn().mockResolvedValue(new Response(null, { status: 204 }));
vi.stubGlobal('fetch', fetchMock);
const { registerHostApiProxyHandlers } = await import('../../electron/main/ipc/host-api-proxy');
registerHostApiProxyHandlers();
const fetchHandler = handleMock.mock.calls.find(([channel]) => channel === 'hostapi:fetch')?.[1];
expect(fetchHandler).toBeTypeOf('function');
await fetchHandler(undefined, {
path: '/api/ai-hardware',
headers: {
Accept: 'application/json',
'X-Renderer-Request': 'hardware-overview',
authorization: 'Bearer renderer-forged-token',
'X-NIANCODE-RENDERER-CAPABILITY': 'renderer-forged-capability',
},
});
const [, init] = fetchMock.mock.calls[0] as [string, RequestInit];
const headers = new Headers(init.headers);
expect(headers.get('accept')).toBe('application/json');
expect(headers.get('x-renderer-request')).toBe('hardware-overview');
expect(headers.get('authorization')).toBe('Bearer host-token');
expect(headers.get('x-niancode-renderer-capability')).toBe('renderer-token');
});
});