Add baseURL whitespace trim path-prefix transport test
Co-authored-by: Eric Allam <eric@trigger.dev>
This commit is contained in:
@@ -544,6 +544,71 @@ describe("TriggerChatTransport", function () {
|
||||
expect(observedStreamPath).toBe("/realtime/v1/streams/run_trimmed_baseurl/chat-stream");
|
||||
});
|
||||
|
||||
it("preserves baseURL path prefixes after trimming surrounding whitespace", async function () {
|
||||
let observedTriggerPath: string | undefined;
|
||||
let observedStreamPath: string | undefined;
|
||||
|
||||
const server = await startServer(function (req, res) {
|
||||
if (req.method === "POST") {
|
||||
observedTriggerPath = req.url ?? "";
|
||||
}
|
||||
|
||||
if (req.method === "GET") {
|
||||
observedStreamPath = req.url ?? "";
|
||||
}
|
||||
|
||||
if (req.method === "POST" && req.url === "/trimmed-prefix/api/v1/tasks/chat-task/trigger") {
|
||||
res.writeHead(200, {
|
||||
"content-type": "application/json",
|
||||
"x-trigger-jwt": "pk_run_trimmed_prefix",
|
||||
});
|
||||
res.end(JSON.stringify({ id: "run_trimmed_prefix" }));
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.method === "GET" && req.url === "/trimmed-prefix/realtime/v1/streams/run_trimmed_prefix/chat-stream") {
|
||||
res.writeHead(200, {
|
||||
"content-type": "text/event-stream",
|
||||
});
|
||||
writeSSE(
|
||||
res,
|
||||
"1-0",
|
||||
JSON.stringify({ type: "text-start", id: "trimmed_prefix_1" })
|
||||
);
|
||||
writeSSE(
|
||||
res,
|
||||
"2-0",
|
||||
JSON.stringify({ type: "text-end", id: "trimmed_prefix_1" })
|
||||
);
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
|
||||
res.writeHead(404);
|
||||
res.end();
|
||||
});
|
||||
|
||||
const transport = new TriggerChatTransport({
|
||||
task: "chat-task",
|
||||
accessToken: "pk_trigger",
|
||||
baseURL: ` ${server.url}/trimmed-prefix/// `,
|
||||
stream: "chat-stream",
|
||||
});
|
||||
|
||||
const stream = await transport.sendMessages({
|
||||
trigger: "submit-message",
|
||||
chatId: "chat-trimmed-prefix-baseurl",
|
||||
messageId: undefined,
|
||||
messages: [],
|
||||
abortSignal: undefined,
|
||||
});
|
||||
|
||||
const chunks = await readChunks(stream);
|
||||
expect(chunks).toHaveLength(2);
|
||||
expect(observedTriggerPath).toBe("/trimmed-prefix/api/v1/tasks/chat-task/trigger");
|
||||
expect(observedStreamPath).toBe("/trimmed-prefix/realtime/v1/streams/run_trimmed_prefix/chat-stream");
|
||||
});
|
||||
|
||||
it("combines path prefixes with run and stream URL encoding", async function () {
|
||||
let observedTriggerPath: string | undefined;
|
||||
let observedStreamPath: string | undefined;
|
||||
|
||||
Reference in New Issue
Block a user