@@ -549,6 +549,83 @@ describe("TriggerChatTransport", function () {
549549 expect ( ( options . idempotencyKey as string ) . length ) . toBe ( 64 ) ;
550550 } ) ;
551551
552+ it ( "surfaces payload mapper errors and does not trigger runs" , async function ( ) {
553+ let triggerCalls = 0 ;
554+
555+ const server = await startServer ( function ( req , res ) {
556+ if ( req . method === "POST" && req . url === "/api/v1/tasks/chat-task/trigger" ) {
557+ triggerCalls ++ ;
558+ }
559+
560+ res . writeHead ( 500 , {
561+ "content-type" : "application/json" ,
562+ } ) ;
563+ res . end ( JSON . stringify ( { error : "unexpected" } ) ) ;
564+ } ) ;
565+
566+ const transport = new TriggerChatTransport <
567+ UIMessage ,
568+ { prompt : string }
569+ > ( {
570+ task : "chat-task" ,
571+ stream : "chat-stream" ,
572+ accessToken : "pk_trigger" ,
573+ baseURL : server . url ,
574+ payloadMapper : async function payloadMapper ( ) {
575+ throw new Error ( "mapper failed" ) ;
576+ } ,
577+ } ) ;
578+
579+ await expect (
580+ transport . sendMessages ( {
581+ trigger : "submit-message" ,
582+ chatId : "chat-mapper-failure" ,
583+ messageId : undefined ,
584+ messages : [ ] ,
585+ abortSignal : undefined ,
586+ } )
587+ ) . rejects . toThrowError ( "mapper failed" ) ;
588+
589+ expect ( triggerCalls ) . toBe ( 0 ) ;
590+ } ) ;
591+
592+ it ( "surfaces trigger options resolver errors and does not trigger runs" , async function ( ) {
593+ let triggerCalls = 0 ;
594+
595+ const server = await startServer ( function ( req , res ) {
596+ if ( req . method === "POST" && req . url === "/api/v1/tasks/chat-task/trigger" ) {
597+ triggerCalls ++ ;
598+ }
599+
600+ res . writeHead ( 500 , {
601+ "content-type" : "application/json" ,
602+ } ) ;
603+ res . end ( JSON . stringify ( { error : "unexpected" } ) ) ;
604+ } ) ;
605+
606+ const transport = new TriggerChatTransport ( {
607+ task : "chat-task" ,
608+ stream : "chat-stream" ,
609+ accessToken : "pk_trigger" ,
610+ baseURL : server . url ,
611+ triggerOptions : async function triggerOptions ( ) {
612+ throw new Error ( "trigger options failed" ) ;
613+ } ,
614+ } ) ;
615+
616+ await expect (
617+ transport . sendMessages ( {
618+ trigger : "submit-message" ,
619+ chatId : "chat-trigger-failure" ,
620+ messageId : undefined ,
621+ messages : [ ] ,
622+ abortSignal : undefined ,
623+ } )
624+ ) . rejects . toThrowError ( "trigger options failed" ) ;
625+
626+ expect ( triggerCalls ) . toBe ( 0 ) ;
627+ } ) ;
628+
552629 it ( "supports creating transport with factory function" , async function ( ) {
553630 let observedRunId : string | undefined ;
554631
0 commit comments