feat: implement PI core chat timeline
This commit is contained in:
@@ -113,4 +113,48 @@ describe('Host API IPC proxy', () => {
|
||||
data: { status: 200, ok: true, json: { success: true, transport: 'test' }, transport: 'dispatcher' },
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps attachment upload bytes raw and returns image bytes through IPC', async () => {
|
||||
const fetchMock = vi.fn()
|
||||
.mockResolvedValueOnce(new Response(
|
||||
JSON.stringify({ attachmentId: 'attachment-1', mime: 'image/png', byteLength: 4 }),
|
||||
{ status: 201, headers: { 'content-type': 'application/json' } },
|
||||
))
|
||||
.mockResolvedValueOnce(new Response(
|
||||
new Uint8Array([1, 2, 3, 4]),
|
||||
{ status: 200, headers: { 'content-type': 'image/png' } },
|
||||
));
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
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 upload = await fetchHandler(undefined, {
|
||||
path: '/api/coding/attachments',
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'image/png' },
|
||||
body: new Uint8Array([1, 2, 3, 4]).buffer,
|
||||
});
|
||||
const [, uploadInit] = fetchMock.mock.calls[0] as [string, RequestInit];
|
||||
expect(Array.from(uploadInit.body as Uint8Array)).toEqual([1, 2, 3, 4]);
|
||||
expect(new Headers(uploadInit.headers).get('content-type')).toBe('image/png');
|
||||
expect(upload).toMatchObject({
|
||||
ok: true,
|
||||
data: { status: 201, json: { attachmentId: 'attachment-1' } },
|
||||
});
|
||||
|
||||
const preview = await fetchHandler(undefined, {
|
||||
path: '/api/coding/attachments/attachment-1/content',
|
||||
method: 'GET',
|
||||
});
|
||||
expect(preview).toMatchObject({
|
||||
ok: true,
|
||||
data: {
|
||||
status: 200,
|
||||
contentType: 'image/png',
|
||||
bytes: new Uint8Array([1, 2, 3, 4]),
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user