Cover trailing slash normalization for transport baseURL

Co-authored-by: Eric Allam <eric@trigger.dev>
This commit is contained in:
Cursor Agent
2026-02-15 03:36:23 +00:00
parent 82f89508ca
commit 5eeafc2e4f
+59
View File
@@ -214,6 +214,65 @@ describe("TriggerChatTransport", function () {
expect(observedStreamPath).toBe("/realtime/v1/streams/run%2Fwith%20space/chat-stream");
});
it("normalizes trailing slash in baseURL for stream URLs", async function () {
let observedStreamPath: string | undefined;
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_trailing_baseurl",
});
res.end(JSON.stringify({ id: "run_trailing_baseurl" }));
return;
}
if (req.method === "GET") {
observedStreamPath = req.url ?? "";
}
if (req.method === "GET" && req.url === "/realtime/v1/streams/run_trailing_baseurl/chat-stream") {
res.writeHead(200, {
"content-type": "text/event-stream",
});
writeSSE(
res,
"1-0",
JSON.stringify({ type: "text-start", id: "trailing_1" })
);
writeSSE(
res,
"2-0",
JSON.stringify({ type: "text-end", id: "trailing_1" })
);
res.end();
return;
}
res.writeHead(404);
res.end();
});
const transport = new TriggerChatTransport({
task: "chat-task",
accessToken: "pk_trigger",
baseURL: `${server.url}/`,
stream: "chat-stream",
});
const stream = await transport.sendMessages({
trigger: "submit-message",
chatId: "chat-trailing-baseurl",
messageId: undefined,
messages: [],
abortSignal: undefined,
});
const chunks = await readChunks(stream);
expect(chunks).toHaveLength(2);
expect(observedStreamPath).toBe("/realtime/v1/streams/run_trailing_baseurl/chat-stream");
});
it("uses defined stream object id when provided", async function () {
let observedStreamPath: string | undefined;