@@ -1963,6 +1963,56 @@ describe("TriggerChatTransport", function () {
19631963 } ) ;
19641964 } ) ;
19651965
1966+ it (
1967+ "preserves consumeTrackingStream root failures when cleanup and onError callbacks both fail" ,
1968+ async function ( ) {
1969+ const runStore = new FailingCleanupSetRunStore ( 2 ) ;
1970+
1971+ const server = await startServer ( function ( req , res ) {
1972+ if ( req . method === "POST" && req . url === "/api/v1/tasks/chat-task/trigger" ) {
1973+ res . writeHead ( 200 , {
1974+ "content-type" : "application/json" ,
1975+ "x-trigger-jwt" : "pk_run_tracking_cleanup_and_onerror_failure" ,
1976+ } ) ;
1977+ res . end ( JSON . stringify ( { id : "run_tracking_cleanup_and_onerror_failure" } ) ) ;
1978+ return ;
1979+ }
1980+
1981+ res . writeHead ( 404 ) ;
1982+ res . end ( ) ;
1983+ } ) ;
1984+
1985+ const transport = new TriggerChatTransport ( {
1986+ task : "chat-task" ,
1987+ stream : "chat-stream" ,
1988+ accessToken : "pk_trigger" ,
1989+ baseURL : server . url ,
1990+ runStore,
1991+ onError : async function onError ( ) {
1992+ throw new Error ( "onError failed" ) ;
1993+ } ,
1994+ } ) ;
1995+
1996+ ( transport as any ) . fetchRunStream = async function fetchRunStream ( ) {
1997+ return new ReadableStream ( {
1998+ start ( controller ) {
1999+ controller . error ( new Error ( "tracking failed root cause" ) ) ;
2000+ } ,
2001+ } ) ;
2002+ } ;
2003+
2004+ const stream = await transport . sendMessages ( {
2005+ trigger : "submit-message" ,
2006+ chatId : "chat-tracking-cleanup-and-onerror-failure" ,
2007+ messageId : undefined ,
2008+ messages : [ ] ,
2009+ abortSignal : undefined ,
2010+ } ) ;
2011+
2012+ await expect ( readChunks ( stream ) ) . rejects . toThrowError ( "tracking failed root cause" ) ;
2013+ }
2014+ ) ;
2015+
19662016 it ( "preserves consumeTrackingStream failures when cleanup run-store set throws" , async function ( ) {
19672017 const errors : TriggerChatTransportError [ ] = [ ] ;
19682018 const runStore = new FailingCleanupSetRunStore ( 2 ) ;
0 commit comments