fix: recover Robot configuration loading
This commit is contained in:
@@ -326,6 +326,41 @@ describe('AI hardware Host API route', () => {
|
||||
expect(hugeResult.payload).toMatchObject({ success: false, status: 502, code: 'AI_HARDWARE_RESPONSE_TOO_LARGE' });
|
||||
});
|
||||
|
||||
it('keeps the upstream deadline active while reading a stalled configuration body', async () => {
|
||||
let bodyController: ReadableStreamDefaultController<Uint8Array> | undefined;
|
||||
const fetchImpl = vi.fn<typeof fetch>((_input, init) => {
|
||||
const body = new ReadableStream<Uint8Array>({
|
||||
start(controller) {
|
||||
bodyController = controller;
|
||||
controller.enqueue(new TextEncoder().encode('{"id":"a-1"'));
|
||||
init?.signal?.addEventListener('abort', () => {
|
||||
controller.error(new DOMException('secret stalled body', 'AbortError'));
|
||||
}, { once: true });
|
||||
},
|
||||
});
|
||||
return Promise.resolve(new Response(body, {
|
||||
headers: { 'content-type': 'application/json', etag: '"0"' },
|
||||
}));
|
||||
});
|
||||
const { handler } = setup(fetchImpl);
|
||||
const pending = invoke(handler, 'GET', '/api/works/ai-hardware/agents/a-1');
|
||||
const result = await Promise.race([
|
||||
pending,
|
||||
new Promise<null>((resolve) => setTimeout(() => resolve(null), 100)),
|
||||
]);
|
||||
|
||||
if (result === null) {
|
||||
bodyController?.close();
|
||||
await pending;
|
||||
}
|
||||
expect(result?.payload).toMatchObject({
|
||||
success: false,
|
||||
status: 504,
|
||||
code: 'AI_HARDWARE_TIMEOUT',
|
||||
retryable: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('bounds request bodies and distinguishes unrelated and unknown hardware routes', async () => {
|
||||
const { handler, fetchImpl } = setup();
|
||||
const unrelated = response();
|
||||
|
||||
Reference in New Issue
Block a user