@@ -1123,9 +1123,63 @@ describe("TriggerChatTransport", function () {
11231123 chatId : "chat-stream-subscribe-error" ,
11241124 runId : "run_stream_subscribe_error" ,
11251125 } ) ;
1126+ expect ( errors [ 0 ] ?. error . message ) . toBe ( "stream subscribe failed root" ) ;
11261127 expect ( runStore . get ( "chat-stream-subscribe-error" ) ) . toBeUndefined ( ) ;
11271128 } ) ;
11281129
1130+ it ( "normalizes non-Error stream subscription failures before reporting onError" , async function ( ) {
1131+ const errors : TriggerChatTransportError [ ] = [ ] ;
1132+ const runStore = new InMemoryTriggerChatRunStore ( ) ;
1133+
1134+ const server = await startServer ( function ( req , res ) {
1135+ if ( req . method === "POST" && req . url === "/api/v1/tasks/chat-task/trigger" ) {
1136+ res . writeHead ( 200 , {
1137+ "content-type" : "application/json" ,
1138+ "x-trigger-jwt" : "pk_stream_subscribe_string_error" ,
1139+ } ) ;
1140+ res . end ( JSON . stringify ( { id : "run_stream_subscribe_string_error" } ) ) ;
1141+ return ;
1142+ }
1143+
1144+ res . writeHead ( 404 ) ;
1145+ res . end ( ) ;
1146+ } ) ;
1147+
1148+ const transport = new TriggerChatTransport ( {
1149+ task : "chat-task" ,
1150+ stream : "chat-stream" ,
1151+ accessToken : "pk_trigger" ,
1152+ baseURL : server . url ,
1153+ runStore,
1154+ onError : function onError ( error ) {
1155+ errors . push ( error ) ;
1156+ } ,
1157+ } ) ;
1158+
1159+ ( transport as any ) . fetchRunStream = async function fetchRunStream ( ) {
1160+ throw "stream subscribe string failure" ;
1161+ } ;
1162+
1163+ await expect (
1164+ transport . sendMessages ( {
1165+ trigger : "submit-message" ,
1166+ chatId : "chat-stream-subscribe-string-error" ,
1167+ messageId : undefined ,
1168+ messages : [ ] ,
1169+ abortSignal : undefined ,
1170+ } )
1171+ ) . rejects . toBe ( "stream subscribe string failure" ) ;
1172+
1173+ expect ( errors ) . toHaveLength ( 1 ) ;
1174+ expect ( errors [ 0 ] ) . toMatchObject ( {
1175+ phase : "streamSubscribe" ,
1176+ chatId : "chat-stream-subscribe-string-error" ,
1177+ runId : "run_stream_subscribe_string_error" ,
1178+ } ) ;
1179+ expect ( errors [ 0 ] ?. error . message ) . toBe ( "stream subscribe string failure" ) ;
1180+ expect ( runStore . get ( "chat-stream-subscribe-string-error" ) ) . toBeUndefined ( ) ;
1181+ } ) ;
1182+
11291183 it ( "keeps original stream subscription failure when onError callback also fails" , async function ( ) {
11301184 const runStore = new InMemoryTriggerChatRunStore ( ) ;
11311185
0 commit comments