Skip to content

Commit d79c586

Browse files
Cover static trigger options path in chat transport
Co-authored-by: Eric Allam <eric@trigger.dev>
1 parent 63e98c2 commit d79c586

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

packages/ai/src/chatTransport.test.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,80 @@ describe("TriggerChatTransport", function () {
475475
expect((options.idempotencyKey as string).length).toBe(64);
476476
});
477477

478+
it("supports static trigger options objects", async function () {
479+
let receivedTriggerBody: Record<string, unknown> | undefined;
480+
481+
const server = await startServer(function (req, res) {
482+
if (req.method === "POST" && req.url === "/api/v1/tasks/chat-task/trigger") {
483+
readJsonBody(req).then(function (body) {
484+
receivedTriggerBody = body;
485+
res.writeHead(200, {
486+
"content-type": "application/json",
487+
"x-trigger-jwt": "pk_run_static_opts",
488+
});
489+
res.end(JSON.stringify({ id: "run_static_opts" }));
490+
});
491+
return;
492+
}
493+
494+
if (req.method === "GET" && req.url === "/realtime/v1/streams/run_static_opts/chat-stream") {
495+
res.writeHead(200, {
496+
"content-type": "text/event-stream",
497+
});
498+
writeSSE(
499+
res,
500+
"1-0",
501+
JSON.stringify({ type: "text-start", id: "static_1" })
502+
);
503+
writeSSE(
504+
res,
505+
"2-0",
506+
JSON.stringify({ type: "text-end", id: "static_1" })
507+
);
508+
res.end();
509+
return;
510+
}
511+
512+
res.writeHead(404);
513+
res.end();
514+
});
515+
516+
const transport = new TriggerChatTransport({
517+
task: "chat-task",
518+
stream: "chat-stream",
519+
accessToken: "pk_trigger",
520+
baseURL: server.url,
521+
triggerOptions: {
522+
queue: "static-queue",
523+
concurrencyKey: "chat-static",
524+
idempotencyKey: "static-idempotency",
525+
metadata: {
526+
mode: "static",
527+
},
528+
maxAttempts: 2,
529+
},
530+
});
531+
532+
const stream = await transport.sendMessages({
533+
trigger: "submit-message",
534+
chatId: "chat-static-options",
535+
messageId: undefined,
536+
messages: [],
537+
abortSignal: undefined,
538+
});
539+
540+
const chunks = await readChunks(stream);
541+
expect(chunks).toHaveLength(2);
542+
543+
const options = (receivedTriggerBody?.options ?? {}) as Record<string, unknown>;
544+
expect(options.queue).toEqual({ name: "static-queue" });
545+
expect(options.concurrencyKey).toBe("chat-static");
546+
expect(options.metadata).toEqual({ mode: "static" });
547+
expect(options.maxAttempts).toBe(2);
548+
expect(typeof options.idempotencyKey).toBe("string");
549+
expect((options.idempotencyKey as string).length).toBe(64);
550+
});
551+
478552
it("supports creating transport with factory function", async function () {
479553
let observedRunId: string | undefined;
480554

0 commit comments

Comments
 (0)