Skip to content

Commit 5eeafc2

Browse files
Cover trailing slash normalization for transport baseURL
Co-authored-by: Eric Allam <eric@trigger.dev>
1 parent 82f8950 commit 5eeafc2

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

packages/ai/src/chatTransport.test.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,65 @@ describe("TriggerChatTransport", function () {
214214
expect(observedStreamPath).toBe("/realtime/v1/streams/run%2Fwith%20space/chat-stream");
215215
});
216216

217+
it("normalizes trailing slash in baseURL for stream URLs", async function () {
218+
let observedStreamPath: string | undefined;
219+
220+
const server = await startServer(function (req, res) {
221+
if (req.method === "POST" && req.url === "/api/v1/tasks/chat-task/trigger") {
222+
res.writeHead(200, {
223+
"content-type": "application/json",
224+
"x-trigger-jwt": "pk_run_trailing_baseurl",
225+
});
226+
res.end(JSON.stringify({ id: "run_trailing_baseurl" }));
227+
return;
228+
}
229+
230+
if (req.method === "GET") {
231+
observedStreamPath = req.url ?? "";
232+
}
233+
234+
if (req.method === "GET" && req.url === "/realtime/v1/streams/run_trailing_baseurl/chat-stream") {
235+
res.writeHead(200, {
236+
"content-type": "text/event-stream",
237+
});
238+
writeSSE(
239+
res,
240+
"1-0",
241+
JSON.stringify({ type: "text-start", id: "trailing_1" })
242+
);
243+
writeSSE(
244+
res,
245+
"2-0",
246+
JSON.stringify({ type: "text-end", id: "trailing_1" })
247+
);
248+
res.end();
249+
return;
250+
}
251+
252+
res.writeHead(404);
253+
res.end();
254+
});
255+
256+
const transport = new TriggerChatTransport({
257+
task: "chat-task",
258+
accessToken: "pk_trigger",
259+
baseURL: `${server.url}/`,
260+
stream: "chat-stream",
261+
});
262+
263+
const stream = await transport.sendMessages({
264+
trigger: "submit-message",
265+
chatId: "chat-trailing-baseurl",
266+
messageId: undefined,
267+
messages: [],
268+
abortSignal: undefined,
269+
});
270+
271+
const chunks = await readChunks(stream);
272+
expect(chunks).toHaveLength(2);
273+
expect(observedStreamPath).toBe("/realtime/v1/streams/run_trailing_baseurl/chat-stream");
274+
});
275+
217276
it("uses defined stream object id when provided", async function () {
218277
let observedStreamPath: string | undefined;
219278

0 commit comments

Comments
 (0)