Skip to content

Commit 8e8f3e0

Browse files
Cover consumeTracking behavior when cleanup and onError all fail
Co-authored-by: Eric Allam <eric@trigger.dev>
1 parent 87f92e7 commit 8e8f3e0

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

packages/ai/src/chatTransport.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2474,6 +2474,58 @@ describe("TriggerChatTransport", function () {
24742474
}
24752475
);
24762476

2477+
it(
2478+
"preserves consumeTracking root failures when cleanup set/delete and onError callbacks all fail",
2479+
async function () {
2480+
const runStore = new FailingCleanupSetAndDeleteRunStore();
2481+
2482+
const server = await startServer(function (req, res) {
2483+
if (req.method === "POST" && req.url === "/api/v1/tasks/chat-task/trigger") {
2484+
res.writeHead(200, {
2485+
"content-type": "application/json",
2486+
"x-trigger-jwt": "pk_run_tracking_cleanup_all_failure",
2487+
});
2488+
res.end(JSON.stringify({ id: "run_tracking_cleanup_all_failure" }));
2489+
return;
2490+
}
2491+
2492+
res.writeHead(404);
2493+
res.end();
2494+
});
2495+
2496+
const transport = new TriggerChatTransport({
2497+
task: "chat-task",
2498+
stream: "chat-stream",
2499+
accessToken: "pk_trigger",
2500+
baseURL: server.url,
2501+
runStore,
2502+
onError: async function onError() {
2503+
throw new Error("onError failed");
2504+
},
2505+
});
2506+
2507+
(transport as any).fetchRunStream = async function fetchRunStream() {
2508+
return new ReadableStream({
2509+
start(controller) {
2510+
controller.error(new Error("tracking failed root cause"));
2511+
},
2512+
});
2513+
};
2514+
2515+
const stream = await transport.sendMessages({
2516+
trigger: "submit-message",
2517+
chatId: "chat-tracking-cleanup-all-failure",
2518+
messageId: undefined,
2519+
messages: [],
2520+
abortSignal: undefined,
2521+
});
2522+
2523+
await expect(readChunks(stream)).rejects.toThrowError("tracking failed root cause");
2524+
expect(runStore.setCalls).toContain("chat-tracking-cleanup-all-failure");
2525+
expect(runStore.deleteCalls).toContain("chat-tracking-cleanup-all-failure");
2526+
}
2527+
);
2528+
24772529
it("reports reconnect failures through onError", async function () {
24782530
const errors: TriggerChatTransportError[] = [];
24792531
const runStore = new InMemoryTriggerChatRunStore();

0 commit comments

Comments
 (0)