Skip to content

Commit c441984

Browse files
Cover completion path behavior when cleanup delete fails
Co-authored-by: Eric Allam <eric@trigger.dev>
1 parent ed2207f commit c441984

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

packages/ai/src/chatTransport.test.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,6 +2337,74 @@ describe("TriggerChatTransport", function () {
23372337
expect(trackedRunStore.get("chat-cleanup")).toBeUndefined();
23382338
});
23392339

2340+
it("keeps completed streams successful when cleanup delete fails", async function () {
2341+
const errors: TriggerChatTransportError[] = [];
2342+
const runStore = new FailingCleanupDeleteRunStore(1);
2343+
2344+
const server = await startServer(function (req, res) {
2345+
if (req.method === "POST" && req.url === "/api/v1/tasks/chat-task/trigger") {
2346+
res.writeHead(200, {
2347+
"content-type": "application/json",
2348+
"x-trigger-jwt": "pk_run_cleanup_delete_failure",
2349+
});
2350+
res.end(JSON.stringify({ id: "run_cleanup_delete_failure" }));
2351+
return;
2352+
}
2353+
2354+
if (
2355+
req.method === "GET" &&
2356+
req.url === "/realtime/v1/streams/run_cleanup_delete_failure/chat-stream"
2357+
) {
2358+
res.writeHead(200, {
2359+
"content-type": "text/event-stream",
2360+
});
2361+
writeSSE(
2362+
res,
2363+
"1-0",
2364+
JSON.stringify({ type: "text-start", id: "cleanup_delete_failure_1" })
2365+
);
2366+
writeSSE(
2367+
res,
2368+
"2-0",
2369+
JSON.stringify({ type: "text-end", id: "cleanup_delete_failure_1" })
2370+
);
2371+
res.end();
2372+
return;
2373+
}
2374+
2375+
res.writeHead(404);
2376+
res.end();
2377+
});
2378+
2379+
const transport = new TriggerChatTransport({
2380+
task: "chat-task",
2381+
stream: "chat-stream",
2382+
accessToken: "pk_trigger",
2383+
baseURL: server.url,
2384+
runStore,
2385+
onError: function onError(error) {
2386+
errors.push(error);
2387+
},
2388+
});
2389+
2390+
const stream = await transport.sendMessages({
2391+
trigger: "submit-message",
2392+
chatId: "chat-cleanup-delete-failure",
2393+
messageId: undefined,
2394+
messages: [],
2395+
abortSignal: undefined,
2396+
});
2397+
2398+
const chunks = await readChunks(stream);
2399+
expect(chunks).toHaveLength(2);
2400+
expect(errors).toHaveLength(0);
2401+
2402+
await waitForCondition(function () {
2403+
const state = runStore.get("chat-cleanup-delete-failure");
2404+
return Boolean(state && state.isActive === false);
2405+
});
2406+
});
2407+
23402408
it("returns null from reconnect after stream completion cleanup", async function () {
23412409
const server = await startServer(function (req, res) {
23422410
if (req.method === "POST" && req.url === "/api/v1/tasks/chat-task/trigger") {

0 commit comments

Comments
 (0)