@@ -34,6 +34,76 @@ describe("chat-queued-turns", () => {
3434 expect ( getQueuedChatTurn ( map , "run-a" ) ) . toBeUndefined ( ) ;
3535 } ) ;
3636
37+ it ( "removes the queued entry when its controller aborts" , ( ) => {
38+ const map = emptyMap ( ) ;
39+ const controller = new AbortController ( ) ;
40+ expect (
41+ registerQueuedChatTurn ( {
42+ chatQueuedTurns : map ,
43+ runId : "run-abort" ,
44+ controller,
45+ sessionId : "sess-abort" ,
46+ sessionKey : "main" ,
47+ } ) ,
48+ ) . toBe ( true ) ;
49+
50+ controller . abort ( ) ;
51+
52+ expect ( getQueuedChatTurn ( map , "run-abort" ) ) . toBeUndefined ( ) ;
53+ } ) ;
54+
55+ it ( "does not let a stale abort listener remove a reused run id" , ( ) => {
56+ const map = emptyMap ( ) ;
57+ const first = new AbortController ( ) ;
58+ const second = new AbortController ( ) ;
59+ expect (
60+ registerQueuedChatTurn ( {
61+ chatQueuedTurns : map ,
62+ runId : "run-reused" ,
63+ controller : first ,
64+ sessionId : "sess-a" ,
65+ sessionKey : "main" ,
66+ } ) ,
67+ ) . toBe ( true ) ;
68+ expect ( completeQueuedChatTurn ( map , "run-reused" ) ) . toBe ( true ) ;
69+ expect (
70+ registerQueuedChatTurn ( {
71+ chatQueuedTurns : map ,
72+ runId : "run-reused" ,
73+ controller : second ,
74+ sessionId : "sess-b" ,
75+ sessionKey : "main" ,
76+ } ) ,
77+ ) . toBe ( true ) ;
78+
79+ first . abort ( ) ;
80+
81+ expect ( getQueuedChatTurn ( map , "run-reused" ) ?. controller ) . toBe ( second ) ;
82+ second . abort ( ) ;
83+ expect ( getQueuedChatTurn ( map , "run-reused" ) ) . toBeUndefined ( ) ;
84+ } ) ;
85+
86+ it ( "keeps retired collect identities until completion after abort" , ( ) => {
87+ const map = emptyMap ( ) ;
88+ const controller = new AbortController ( ) ;
89+ expect (
90+ registerQueuedChatTurn ( {
91+ chatQueuedTurns : map ,
92+ runId : "run-retired" ,
93+ controller,
94+ sessionId : "sess-retired" ,
95+ sessionKey : "main" ,
96+ } ) ,
97+ ) . toBe ( true ) ;
98+ expect ( retireQueuedChatTurnCancellation ( map , "run-retired" ) ) . toBe ( true ) ;
99+
100+ controller . abort ( ) ;
101+
102+ expect ( getQueuedChatTurn ( map , "run-retired" ) ?. abortable ) . toBe ( false ) ;
103+ expect ( completeQueuedChatTurn ( map , "run-retired" ) ) . toBe ( true ) ;
104+ expect ( getQueuedChatTurn ( map , "run-retired" ) ) . toBeUndefined ( ) ;
105+ } ) ;
106+
37107 it ( "rejects re-register with a different controller" , ( ) => {
38108 const map = emptyMap ( ) ;
39109 const first = new AbortController ( ) ;
0 commit comments