Skip to content

Commit 677fc06

Browse files
Cover reconnect behavior when cleanup and onError all fail
Co-authored-by: Eric Allam <eric@trigger.dev>
1 parent 50b9407 commit 677fc06

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

packages/ai/src/chatTransport.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2494,6 +2494,43 @@ describe("TriggerChatTransport", function () {
24942494
}
24952495
);
24962496

2497+
it(
2498+
"preserves reconnect root failures when cleanup set/delete and onError callbacks all fail",
2499+
async function () {
2500+
const runStore = new FailingCleanupSetAndDeleteRunStore();
2501+
runStore.set({
2502+
chatId: "chat-reconnect-cleanup-all-failure",
2503+
runId: "run_reconnect_cleanup_all_failure",
2504+
publicAccessToken: "pk_reconnect_cleanup_all_failure",
2505+
streamKey: "chat-stream",
2506+
lastEventId: "100-0",
2507+
isActive: true,
2508+
});
2509+
2510+
const transport = new TriggerChatTransport({
2511+
task: "chat-task",
2512+
stream: "chat-stream",
2513+
accessToken: "pk_trigger",
2514+
runStore,
2515+
onError: async function onError() {
2516+
throw new Error("onError failed");
2517+
},
2518+
});
2519+
2520+
(transport as any).fetchRunStream = async function fetchRunStream() {
2521+
throw new Error("reconnect root cause");
2522+
};
2523+
2524+
const stream = await transport.reconnectToStream({
2525+
chatId: "chat-reconnect-cleanup-all-failure",
2526+
});
2527+
2528+
expect(stream).toBeNull();
2529+
expect(runStore.setCalls).toContain("chat-reconnect-cleanup-all-failure");
2530+
expect(runStore.deleteCalls).toContain("chat-reconnect-cleanup-all-failure");
2531+
}
2532+
);
2533+
24972534
it("normalizes non-Error reconnect failures before reporting onError", async function () {
24982535
const errors: TriggerChatTransportError[] = [];
24992536
const runStore = new InMemoryTriggerChatRunStore();

0 commit comments

Comments
 (0)