@@ -2474,6 +2474,58 @@ describe("TriggerChatTransport", function () {
24742474 }
24752475 ) ;
24762476
2477+ it (
2478+ "preserves consumeTracking root failures when cleanup set/delete and onError callbacks all fail" ,
2479+ async function ( ) {
2480+ const runStore = new FailingCleanupSetAndDeleteRunStore ( ) ;
2481+
2482+ const server = await startServer ( function ( req , res ) {
2483+ if ( req . method === "POST" && req . url === "/api/v1/tasks/chat-task/trigger" ) {
2484+ res . writeHead ( 200 , {
2485+ "content-type" : "application/json" ,
2486+ "x-trigger-jwt" : "pk_run_tracking_cleanup_all_failure" ,
2487+ } ) ;
2488+ res . end ( JSON . stringify ( { id : "run_tracking_cleanup_all_failure" } ) ) ;
2489+ return ;
2490+ }
2491+
2492+ res . writeHead ( 404 ) ;
2493+ res . end ( ) ;
2494+ } ) ;
2495+
2496+ const transport = new TriggerChatTransport ( {
2497+ task : "chat-task" ,
2498+ stream : "chat-stream" ,
2499+ accessToken : "pk_trigger" ,
2500+ baseURL : server . url ,
2501+ runStore,
2502+ onError : async function onError ( ) {
2503+ throw new Error ( "onError failed" ) ;
2504+ } ,
2505+ } ) ;
2506+
2507+ ( transport as any ) . fetchRunStream = async function fetchRunStream ( ) {
2508+ return new ReadableStream ( {
2509+ start ( controller ) {
2510+ controller . error ( new Error ( "tracking failed root cause" ) ) ;
2511+ } ,
2512+ } ) ;
2513+ } ;
2514+
2515+ const stream = await transport . sendMessages ( {
2516+ trigger : "submit-message" ,
2517+ chatId : "chat-tracking-cleanup-all-failure" ,
2518+ messageId : undefined ,
2519+ messages : [ ] ,
2520+ abortSignal : undefined ,
2521+ } ) ;
2522+
2523+ await expect ( readChunks ( stream ) ) . rejects . toThrowError ( "tracking failed root cause" ) ;
2524+ expect ( runStore . setCalls ) . toContain ( "chat-tracking-cleanup-all-failure" ) ;
2525+ expect ( runStore . deleteCalls ) . toContain ( "chat-tracking-cleanup-all-failure" ) ;
2526+ }
2527+ ) ;
2528+
24772529 it ( "reports reconnect failures through onError" , async function ( ) {
24782530 const errors : TriggerChatTransportError [ ] = [ ] ;
24792531 const runStore = new InMemoryTriggerChatRunStore ( ) ;
0 commit comments