Skip to content

Commit 243a246

Browse files
committed
test(agents): cover null response body in proxy stream reader
1 parent 28dcb38 commit 243a246

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

‎src/agents/runtime/proxy.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,4 +598,33 @@ describe("streamProxy", () => {
598598
errorMessage: "Proxy stream ended before terminal event",
599599
});
600600
});
601+
602+
it("emits a business-level error when the proxy returns a null response body", async () => {
603+
vi.stubGlobal(
604+
"fetch",
605+
vi.fn(
606+
async () =>
607+
({
608+
ok: true,
609+
status: 200,
610+
body: null,
611+
}) as Response,
612+
),
613+
);
614+
615+
const stream = streamProxy(model, context, {
616+
authToken: "token",
617+
proxyUrl: "https://proxy.example",
618+
});
619+
const events = [];
620+
for await (const event of stream) {
621+
events.push(event);
622+
}
623+
624+
expect(events.at(-1)?.type).toBe("error");
625+
await expect(stream.result()).resolves.toMatchObject({
626+
stopReason: "error",
627+
errorMessage: "Proxy returned an empty response body",
628+
});
629+
});
601630
});

0 commit comments

Comments
 (0)