Skip to content

Commit d604b94

Browse files
Assert inactive reconnect cleanup never attempts stream fetch
Co-authored-by: Eric Allam <eric@trigger.dev>
1 parent bec4401 commit d604b94

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

packages/ai/src/chatTransport.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,49 @@ describe("TriggerChatTransport", function () {
582582
expect(errors[0]?.error.message).toBe("cleanup delete failed");
583583
});
584584

585+
it("does not attempt reconnect stream fetch for inactive run cleanup failures", async function () {
586+
const errors: TriggerChatTransportError[] = [];
587+
const runStore = new FailingCleanupDeleteRunStore(1);
588+
runStore.set({
589+
chatId: "chat-inactive-no-fetch",
590+
runId: "run_inactive_no_fetch",
591+
publicAccessToken: "pk_inactive_no_fetch",
592+
streamKey: "chat-stream",
593+
lastEventId: "10-0",
594+
isActive: false,
595+
});
596+
597+
const transport = new TriggerChatTransport({
598+
task: "chat-task",
599+
stream: "chat-stream",
600+
accessToken: "pk_trigger",
601+
runStore,
602+
onError: function onError(error) {
603+
errors.push(error);
604+
},
605+
});
606+
607+
let fetchAttempted = false;
608+
(transport as any).fetchRunStream = async function fetchRunStream() {
609+
fetchAttempted = true;
610+
throw new Error("unexpected reconnect fetch");
611+
};
612+
613+
const stream = await transport.reconnectToStream({
614+
chatId: "chat-inactive-no-fetch",
615+
});
616+
617+
expect(stream).toBeNull();
618+
expect(fetchAttempted).toBe(false);
619+
expect(errors).toHaveLength(1);
620+
expect(errors[0]).toMatchObject({
621+
phase: "reconnect",
622+
chatId: "chat-inactive-no-fetch",
623+
runId: "run_inactive_no_fetch",
624+
});
625+
expect(errors[0]?.error.message).toBe("cleanup delete failed");
626+
});
627+
585628
it("retries inactive reconnect cleanup on subsequent reconnect attempts", async function () {
586629
const errors: TriggerChatTransportError[] = [];
587630
const runStore = new FailingCleanupDeleteRunStore(1);

0 commit comments

Comments
 (0)