Skip to content

Commit bf7bee8

Browse files
Assert onError remains silent on successful chat streams
Co-authored-by: Eric Allam <eric@trigger.dev>
1 parent e782303 commit bf7bee8

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

packages/ai/src/chatTransport.test.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,66 @@ describe("TriggerChatTransport", function () {
14421442
expect(errors[0]?.error.message).toBe("callback failed");
14431443
});
14441444

1445+
it("does not call onError during successful trigger and stream flows", async function () {
1446+
const errors: TriggerChatTransportError[] = [];
1447+
const server = await startServer(function (req, res) {
1448+
if (req.method === "POST" && req.url === "/api/v1/tasks/chat-task/trigger") {
1449+
res.writeHead(200, {
1450+
"content-type": "application/json",
1451+
"x-trigger-jwt": "pk_run_no_error_callback",
1452+
});
1453+
res.end(JSON.stringify({ id: "run_no_error_callback" }));
1454+
return;
1455+
}
1456+
1457+
if (
1458+
req.method === "GET" &&
1459+
req.url === "/realtime/v1/streams/run_no_error_callback/chat-stream"
1460+
) {
1461+
res.writeHead(200, {
1462+
"content-type": "text/event-stream",
1463+
});
1464+
writeSSE(
1465+
res,
1466+
"1-0",
1467+
JSON.stringify({ type: "text-start", id: "no_error_1" })
1468+
);
1469+
writeSSE(
1470+
res,
1471+
"2-0",
1472+
JSON.stringify({ type: "text-end", id: "no_error_1" })
1473+
);
1474+
res.end();
1475+
return;
1476+
}
1477+
1478+
res.writeHead(404);
1479+
res.end();
1480+
});
1481+
1482+
const transport = new TriggerChatTransport({
1483+
task: "chat-task",
1484+
stream: "chat-stream",
1485+
accessToken: "pk_trigger",
1486+
baseURL: server.url,
1487+
onError: function onError(error) {
1488+
errors.push(error);
1489+
},
1490+
});
1491+
1492+
const stream = await transport.sendMessages({
1493+
trigger: "submit-message",
1494+
chatId: "chat-no-error-callback",
1495+
messageId: undefined,
1496+
messages: [],
1497+
abortSignal: undefined,
1498+
});
1499+
1500+
const chunks = await readChunks(stream);
1501+
expect(chunks).toHaveLength(2);
1502+
expect(errors).toHaveLength(0);
1503+
});
1504+
14451505
it("normalizes non-Error onTriggeredRun failures before reporting onError", async function () {
14461506
const errors: TriggerChatTransportError[] = [];
14471507

0 commit comments

Comments
 (0)