@@ -2124,7 +2124,6 @@ describe("dispatchTelegramMessage draft streaming", () => {
21242124 secondStarted = resolve ;
21252125 } ) ;
21262126 let firstAbortSignal : AbortSignal | undefined ;
2127- let sideAbortSignal : AbortSignal | undefined ;
21282127 dispatchReplyWithBufferedBlockDispatcher
21292128 . mockImplementationOnce ( async ( { replyOptions } ) => {
21302129 firstAbortSignal = replyOptions ?. abortSignal ;
@@ -2283,6 +2282,70 @@ describe("dispatchTelegramMessage draft streaming", () => {
22832282 await Promise . all ( [ firstPromise , sidePromise ] ) ;
22842283 } ) ;
22852284
2285+ it ( "lets authorized /stop abort active non-interrupting side dispatch" , async ( ) => {
2286+ const historyKey = "telegram:group:-100123" ;
2287+ const groupHistories = new Map ( [ [ historyKey , [ ] ] ] ) ;
2288+ let sideStarted : ( ( ) => void ) | undefined ;
2289+ const sideStartGate = new Promise < void > ( ( resolve ) => {
2290+ sideStarted = resolve ;
2291+ } ) ;
2292+ let releaseSide : ( ( ) => void ) | undefined ;
2293+ const sideGate = new Promise < void > ( ( resolve ) => {
2294+ releaseSide = resolve ;
2295+ } ) ;
2296+ let sideAbortSignal : AbortSignal | undefined ;
2297+ dispatchReplyWithBufferedBlockDispatcher . mockImplementationOnce ( async ( { replyOptions } ) => {
2298+ sideAbortSignal = replyOptions ?. abortSignal ;
2299+ sideStarted ?.( ) ;
2300+ await sideGate ;
2301+ return {
2302+ queuedFinal : false ,
2303+ counts : { block : 0 , final : 0 , tool : 0 } ,
2304+ } ;
2305+ } ) ;
2306+ deliverReplies . mockResolvedValue ( { delivered : true } ) ;
2307+
2308+ const createGroupContext = ( messageId : number , body : string ) =>
2309+ createContext ( {
2310+ ctxPayload : {
2311+ SessionKey : "agent:main:telegram:group:-100123" ,
2312+ ChatType : "group" ,
2313+ MessageSid : String ( messageId ) ,
2314+ RawBody : body ,
2315+ BodyForAgent : body ,
2316+ CommandBody : body ,
2317+ CommandAuthorized : true ,
2318+ } as unknown as TelegramMessageContext [ "ctxPayload" ] ,
2319+ msg : {
2320+ chat : { id : - 100123 , type : "supergroup" } ,
2321+ message_id : messageId ,
2322+ text : body ,
2323+ } as unknown as TelegramMessageContext [ "msg" ] ,
2324+ chatId : - 100123 ,
2325+ isGroup : true ,
2326+ historyKey,
2327+ historyLimit : 10 ,
2328+ groupHistories,
2329+ threadSpec : { id : undefined , scope : "none" } ,
2330+ } ) ;
2331+
2332+ const sidePromise = dispatchWithContext ( {
2333+ context : createGroupContext ( 100 , "/btw what changed?" ) ,
2334+ streamMode : "off" ,
2335+ } ) ;
2336+ await sideStartGate ;
2337+ expect ( sideAbortSignal ?. aborted ) . toBe ( false ) ;
2338+
2339+ await dispatchWithContext ( {
2340+ context : createGroupContext ( 101 , "/stop" ) ,
2341+ streamMode : "off" ,
2342+ } ) ;
2343+
2344+ expect ( sideAbortSignal ?. aborted ) . toBe ( true ) ;
2345+ releaseSide ?.( ) ;
2346+ await sidePromise ;
2347+ } ) ;
2348+
22862349 it ( "keeps queued room events abortable after their source dispatch returns" , async ( ) => {
22872350 const historyKey = "telegram:group:-100123" ;
22882351 const groupHistories = new Map ( [ [ historyKey , [ ] ] ] ) ;
0 commit comments