Skip to content

Commit 3c24068

Browse files
Cover reconnect path when cleanup set and delete both fail
Co-authored-by: Eric Allam <eric@trigger.dev>
1 parent 7eb4f5d commit 3c24068

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

packages/ai/src/chatTransport.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2353,6 +2353,48 @@ describe("TriggerChatTransport", function () {
23532353
expect(errors[0]?.error.message).toBe("reconnect root cause");
23542354
});
23552355

2356+
it("attempts both reconnect cleanup steps when set and delete both throw", async function () {
2357+
const errors: TriggerChatTransportError[] = [];
2358+
const runStore = new FailingCleanupSetAndDeleteRunStore();
2359+
runStore.set({
2360+
chatId: "chat-reconnect-cleanup-both-failure",
2361+
runId: "run_reconnect_cleanup_both_failure",
2362+
publicAccessToken: "pk_reconnect_cleanup_both_failure",
2363+
streamKey: "chat-stream",
2364+
lastEventId: "100-0",
2365+
isActive: true,
2366+
});
2367+
2368+
const transport = new TriggerChatTransport({
2369+
task: "chat-task",
2370+
stream: "chat-stream",
2371+
accessToken: "pk_trigger",
2372+
runStore,
2373+
onError: function onError(error) {
2374+
errors.push(error);
2375+
},
2376+
});
2377+
2378+
(transport as any).fetchRunStream = async function fetchRunStream() {
2379+
throw new Error("reconnect root cause");
2380+
};
2381+
2382+
const stream = await transport.reconnectToStream({
2383+
chatId: "chat-reconnect-cleanup-both-failure",
2384+
});
2385+
2386+
expect(stream).toBeNull();
2387+
expect(errors).toHaveLength(1);
2388+
expect(errors[0]).toMatchObject({
2389+
phase: "reconnect",
2390+
chatId: "chat-reconnect-cleanup-both-failure",
2391+
runId: "run_reconnect_cleanup_both_failure",
2392+
});
2393+
expect(errors[0]?.error.message).toBe("reconnect root cause");
2394+
expect(runStore.setCalls).toContain("chat-reconnect-cleanup-both-failure");
2395+
expect(runStore.deleteCalls).toContain("chat-reconnect-cleanup-both-failure");
2396+
});
2397+
23562398
it(
23572399
"preserves reconnect root failures when cleanup and onError callbacks both fail",
23582400
async function () {

0 commit comments

Comments
 (0)