Cover completion path when cleanup set and delete both fail

Co-authored-by: Eric Allam <eric@trigger.dev>
This commit is contained in:
Cursor Agent
2026-02-15 02:09:04 +00:00
parent 3c240685ba
commit 526b66f9b3
+70
View File
@@ -2701,6 +2701,76 @@ describe("TriggerChatTransport", function () {
expect(runStore.deleteCalls).toContain("chat-cleanup-set-failure");
});
it("keeps completed streams successful when cleanup set and delete both fail", async function () {
const errors: TriggerChatTransportError[] = [];
const runStore = new FailingCleanupSetAndDeleteRunStore(4);
const server = await startServer(function (req, res) {
if (req.method === "POST" && req.url === "/api/v1/tasks/chat-task/trigger") {
res.writeHead(200, {
"content-type": "application/json",
"x-trigger-jwt": "pk_run_cleanup_set_delete_failure",
});
res.end(JSON.stringify({ id: "run_cleanup_set_delete_failure" }));
return;
}
if (
req.method === "GET" &&
req.url === "/realtime/v1/streams/run_cleanup_set_delete_failure/chat-stream"
) {
res.writeHead(200, {
"content-type": "text/event-stream",
});
writeSSE(
res,
"1-0",
JSON.stringify({ type: "text-start", id: "cleanup_set_delete_failure_1" })
);
writeSSE(
res,
"2-0",
JSON.stringify({ type: "text-end", id: "cleanup_set_delete_failure_1" })
);
res.end();
return;
}
res.writeHead(404);
res.end();
});
const transport = new TriggerChatTransport({
task: "chat-task",
stream: "chat-stream",
accessToken: "pk_trigger",
baseURL: server.url,
runStore,
onError: function onError(error) {
errors.push(error);
},
});
const stream = await transport.sendMessages({
trigger: "submit-message",
chatId: "chat-cleanup-set-delete-failure",
messageId: undefined,
messages: [],
abortSignal: undefined,
});
const chunks = await readChunks(stream);
expect(chunks).toHaveLength(2);
expect(errors).toHaveLength(0);
await waitForCondition(function () {
const state = runStore.get("chat-cleanup-set-delete-failure");
return Boolean(state && state.isActive === true && state.lastEventId === "2-0");
});
expect(runStore.setCalls).toContain("chat-cleanup-set-delete-failure");
expect(runStore.deleteCalls).toContain("chat-cleanup-set-delete-failure");
});
it("returns null from reconnect after stream completion cleanup", async function () {
const server = await startServer(function (req, res) {
if (req.method === "POST" && req.url === "/api/v1/tasks/chat-task/trigger") {