@@ -732,6 +732,7 @@ describe("TriggerChatTransport", function () {
732732
733733 it ( "surfaces payload mapper errors and does not trigger runs" , async function ( ) {
734734 let triggerCalls = 0 ;
735+ const errors : TriggerChatTransportError [ ] = [ ] ;
735736
736737 const server = await startServer ( function ( req , res ) {
737738 if ( req . method === "POST" && req . url === "/api/v1/tasks/chat-task/trigger" ) {
@@ -755,6 +756,9 @@ describe("TriggerChatTransport", function () {
755756 payloadMapper : async function payloadMapper ( ) {
756757 throw new Error ( "mapper failed" ) ;
757758 } ,
759+ onError : function onError ( error ) {
760+ errors . push ( error ) ;
761+ } ,
758762 } ) ;
759763
760764 await expect (
@@ -768,10 +772,18 @@ describe("TriggerChatTransport", function () {
768772 ) . rejects . toThrowError ( "mapper failed" ) ;
769773
770774 expect ( triggerCalls ) . toBe ( 0 ) ;
775+ expect ( errors ) . toHaveLength ( 1 ) ;
776+ expect ( errors [ 0 ] ) . toMatchObject ( {
777+ phase : "payloadMapper" ,
778+ chatId : "chat-mapper-failure" ,
779+ runId : undefined ,
780+ } ) ;
781+ expect ( errors [ 0 ] ?. error . message ) . toBe ( "mapper failed" ) ;
771782 } ) ;
772783
773784 it ( "surfaces trigger options resolver errors and does not trigger runs" , async function ( ) {
774785 let triggerCalls = 0 ;
786+ const errors : TriggerChatTransportError [ ] = [ ] ;
775787
776788 const server = await startServer ( function ( req , res ) {
777789 if ( req . method === "POST" && req . url === "/api/v1/tasks/chat-task/trigger" ) {
@@ -792,6 +804,9 @@ describe("TriggerChatTransport", function () {
792804 triggerOptions : async function triggerOptions ( ) {
793805 throw new Error ( "trigger options failed" ) ;
794806 } ,
807+ onError : function onError ( error ) {
808+ errors . push ( error ) ;
809+ } ,
795810 } ) ;
796811
797812 await expect (
@@ -805,6 +820,59 @@ describe("TriggerChatTransport", function () {
805820 ) . rejects . toThrowError ( "trigger options failed" ) ;
806821
807822 expect ( triggerCalls ) . toBe ( 0 ) ;
823+ expect ( errors ) . toHaveLength ( 1 ) ;
824+ expect ( errors [ 0 ] ) . toMatchObject ( {
825+ phase : "triggerOptions" ,
826+ chatId : "chat-trigger-failure" ,
827+ runId : undefined ,
828+ } ) ;
829+ expect ( errors [ 0 ] ?. error . message ) . toBe ( "trigger options failed" ) ;
830+ } ) ;
831+
832+ it ( "reports trigger task request failures through onError" , async function ( ) {
833+ const errors : TriggerChatTransportError [ ] = [ ] ;
834+ const server = await startServer ( function ( _req , res ) {
835+ res . writeHead ( 500 , {
836+ "content-type" : "application/json" ,
837+ } ) ;
838+ res . end ( JSON . stringify ( { error : "task trigger failed" } ) ) ;
839+ } ) ;
840+
841+ const transport = new TriggerChatTransport ( {
842+ task : "chat-task" ,
843+ stream : "chat-stream" ,
844+ accessToken : "pk_trigger" ,
845+ baseURL : server . url ,
846+ requestOptions : {
847+ retry : {
848+ maxAttempts : 1 ,
849+ minTimeoutInMs : 1 ,
850+ maxTimeoutInMs : 1 ,
851+ factor : 1 ,
852+ randomize : false ,
853+ } ,
854+ } ,
855+ onError : function onError ( error ) {
856+ errors . push ( error ) ;
857+ } ,
858+ } ) ;
859+
860+ await expect (
861+ transport . sendMessages ( {
862+ trigger : "submit-message" ,
863+ chatId : "chat-trigger-request-failure" ,
864+ messageId : undefined ,
865+ messages : [ ] ,
866+ abortSignal : undefined ,
867+ } )
868+ ) . rejects . toThrowError ( "task trigger failed" ) ;
869+
870+ expect ( errors ) . toHaveLength ( 1 ) ;
871+ expect ( errors [ 0 ] ) . toMatchObject ( {
872+ phase : "triggerTask" ,
873+ chatId : "chat-trigger-request-failure" ,
874+ runId : undefined ,
875+ } ) ;
808876 } ) ;
809877
810878 it ( "supports creating transport with factory function" , async function ( ) {
0 commit comments