Skip to content

Commit e24d1c4

Browse files
committed
test(ai): cover proxy streams ending without message_stop
ClawSweeper P1: the proxy exemption had no focused test, so the lenient branch could regress silently. A non-anthropic provider through a custom endpoint now proves stopReason=stop with no error when the stream ends without message_stop.
1 parent a578ca6 commit e24d1c4

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

‎packages/ai/src/transports/anthropic-transport-stream.test.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,6 +1663,43 @@ describe("anthropic transport stream", () => {
16631663
expect(result.errorMessage).toBe("Anthropic stream ended before message_stop");
16641664
});
16651665

1666+
it("accepts proxy provider streams that end without message_stop", async () => {
1667+
guardedFetchMock.mockResolvedValueOnce(
1668+
createSseResponse([
1669+
{
1670+
type: "message_start",
1671+
message: { id: "msg_proxy", usage: { input_tokens: 3, output_tokens: 0 } },
1672+
},
1673+
{ type: "content_block_start", index: 0, content_block: { type: "text", text: "" } },
1674+
{
1675+
type: "content_block_delta",
1676+
index: 0,
1677+
delta: { type: "text_delta", text: "proxy answer" },
1678+
},
1679+
{ type: "content_block_stop", index: 0 },
1680+
{
1681+
type: "message_delta",
1682+
delta: { stop_reason: "end_turn" },
1683+
usage: { input_tokens: 3, output_tokens: 2 },
1684+
},
1685+
]),
1686+
);
1687+
1688+
// Proxy identity: non-anthropic provider through a custom endpoint is not
1689+
// held to the first-party message_stop framing contract.
1690+
const result = await runTransportStream(
1691+
makeAnthropicTransportModel({
1692+
provider: "openrouter",
1693+
baseUrl: "https://proxy.example.com/v1",
1694+
}),
1695+
{ messages: [{ role: "user", content: "hello" }] } as AnthropicStreamContext,
1696+
{ apiKey: "sk-proxy" } as AnthropicStreamOptions,
1697+
);
1698+
1699+
expect(result.stopReason).toBe("stop");
1700+
expect(result.errorMessage).toBeUndefined();
1701+
});
1702+
16661703
it("defers a pre-tool text block's text_end until it carries the commentary phase", async () => {
16671704
guardedFetchMock.mockResolvedValueOnce(
16681705
createSseResponse([

0 commit comments

Comments
 (0)