@@ -273,6 +273,68 @@ describe("TriggerChatTransport", function () {
273273 expect ( observedStreamPath ) . toBe ( "/realtime/v1/streams/run_trailing_baseurl/chat-stream" ) ;
274274 } ) ;
275275
276+ it ( "normalizes repeated trailing slashes in baseURL for stream URLs" , async function ( ) {
277+ let observedStreamPath : string | undefined ;
278+
279+ const server = await startServer ( function ( req , res ) {
280+ if ( req . method === "POST" && req . url === "/api/v1/tasks/chat-task/trigger" ) {
281+ res . writeHead ( 200 , {
282+ "content-type" : "application/json" ,
283+ "x-trigger-jwt" : "pk_run_multi_trailing_baseurl" ,
284+ } ) ;
285+ res . end ( JSON . stringify ( { id : "run_multi_trailing_baseurl" } ) ) ;
286+ return ;
287+ }
288+
289+ if ( req . method === "GET" ) {
290+ observedStreamPath = req . url ?? "" ;
291+ }
292+
293+ if (
294+ req . method === "GET" &&
295+ req . url === "/realtime/v1/streams/run_multi_trailing_baseurl/chat-stream"
296+ ) {
297+ res . writeHead ( 200 , {
298+ "content-type" : "text/event-stream" ,
299+ } ) ;
300+ writeSSE (
301+ res ,
302+ "1-0" ,
303+ JSON . stringify ( { type : "text-start" , id : "multi_trailing_1" } )
304+ ) ;
305+ writeSSE (
306+ res ,
307+ "2-0" ,
308+ JSON . stringify ( { type : "text-end" , id : "multi_trailing_1" } )
309+ ) ;
310+ res . end ( ) ;
311+ return ;
312+ }
313+
314+ res . writeHead ( 404 ) ;
315+ res . end ( ) ;
316+ } ) ;
317+
318+ const transport = new TriggerChatTransport ( {
319+ task : "chat-task" ,
320+ accessToken : "pk_trigger" ,
321+ baseURL : `${ server . url } ///` ,
322+ stream : "chat-stream" ,
323+ } ) ;
324+
325+ const stream = await transport . sendMessages ( {
326+ trigger : "submit-message" ,
327+ chatId : "chat-multi-trailing-baseurl" ,
328+ messageId : undefined ,
329+ messages : [ ] ,
330+ abortSignal : undefined ,
331+ } ) ;
332+
333+ const chunks = await readChunks ( stream ) ;
334+ expect ( chunks ) . toHaveLength ( 2 ) ;
335+ expect ( observedStreamPath ) . toBe ( "/realtime/v1/streams/run_multi_trailing_baseurl/chat-stream" ) ;
336+ } ) ;
337+
276338 it ( "supports baseURL path prefixes for trigger and stream routes" , async function ( ) {
277339 let observedTriggerPath : string | undefined ;
278340 let observedStreamPath : string | undefined ;
0 commit comments