@@ -610,6 +610,70 @@ describe("TriggerChatTransport", function () {
610610 expect ( stream ) . toBeNull ( ) ;
611611 } ) ;
612612
613+ it ( "normalizes non-Error inactive reconnect cleanup delete failures through onError" , async function ( ) {
614+ const errors : TriggerChatTransportError [ ] = [ ] ;
615+ const runStore = new FailingCleanupDeleteValueRunStore ( "cleanup delete string failure" ) ;
616+ runStore . set ( {
617+ chatId : "chat-inactive-delete-string-failure" ,
618+ runId : "run_inactive_delete_string_failure" ,
619+ publicAccessToken : "pk_inactive_delete_string_failure" ,
620+ streamKey : "chat-stream" ,
621+ lastEventId : "10-0" ,
622+ isActive : false ,
623+ } ) ;
624+
625+ const transport = new TriggerChatTransport ( {
626+ task : "chat-task" ,
627+ stream : "chat-stream" ,
628+ accessToken : "pk_trigger" ,
629+ runStore,
630+ onError : function onError ( error ) {
631+ errors . push ( error ) ;
632+ } ,
633+ } ) ;
634+
635+ const stream = await transport . reconnectToStream ( {
636+ chatId : "chat-inactive-delete-string-failure" ,
637+ } ) ;
638+
639+ expect ( stream ) . toBeNull ( ) ;
640+ expect ( errors ) . toHaveLength ( 1 ) ;
641+ expect ( errors [ 0 ] ) . toMatchObject ( {
642+ phase : "reconnect" ,
643+ chatId : "chat-inactive-delete-string-failure" ,
644+ runId : "run_inactive_delete_string_failure" ,
645+ } ) ;
646+ expect ( errors [ 0 ] ?. error . message ) . toBe ( "cleanup delete string failure" ) ;
647+ } ) ;
648+
649+ it ( "returns null when inactive reconnect string cleanup delete and onError both fail" , async function ( ) {
650+ const runStore = new FailingCleanupDeleteValueRunStore ( "cleanup delete string failure" ) ;
651+ runStore . set ( {
652+ chatId : "chat-inactive-delete-string-onerror-failure" ,
653+ runId : "run_inactive_delete_string_onerror_failure" ,
654+ publicAccessToken : "pk_inactive_delete_string_onerror_failure" ,
655+ streamKey : "chat-stream" ,
656+ lastEventId : "10-0" ,
657+ isActive : false ,
658+ } ) ;
659+
660+ const transport = new TriggerChatTransport ( {
661+ task : "chat-task" ,
662+ stream : "chat-stream" ,
663+ accessToken : "pk_trigger" ,
664+ runStore,
665+ onError : async function onError ( ) {
666+ throw new Error ( "onError failed" ) ;
667+ } ,
668+ } ) ;
669+
670+ const stream = await transport . reconnectToStream ( {
671+ chatId : "chat-inactive-delete-string-onerror-failure" ,
672+ } ) ;
673+
674+ expect ( stream ) . toBeNull ( ) ;
675+ } ) ;
676+
613677 it ( "supports custom payload mapping and trigger options resolver" , async function ( ) {
614678 let receivedTriggerBody : Record < string , unknown > | undefined ;
615679 let receivedResolverChatId : string | undefined ;
@@ -3318,6 +3382,21 @@ class FailingCleanupDeleteRunStore extends InMemoryTriggerChatRunStore {
33183382 }
33193383}
33203384
3385+ class FailingCleanupDeleteValueRunStore extends InMemoryTriggerChatRunStore {
3386+ private deleteCalls = 0 ;
3387+
3388+ constructor ( private readonly thrownValue : unknown ) {
3389+ super ( ) ;
3390+ }
3391+
3392+ public delete ( _chatId : string ) : void {
3393+ this . deleteCalls += 1 ;
3394+ if ( this . deleteCalls === 1 ) {
3395+ throw this . thrownValue ;
3396+ }
3397+ }
3398+ }
3399+
33213400class FailingCleanupSetAndDeleteRunStore extends InMemoryTriggerChatRunStore {
33223401 private setCallCount = 0 ;
33233402 public readonly setCalls : string [ ] = [ ] ;
0 commit comments