@@ -300,6 +300,40 @@ describe("server-channels auto restart", () => {
300300 expect ( account ?. lastError ) . toBeNull ( ) ;
301301 } ) ;
302302
303+ it ( "lets stop hooks update status after aborting the running task" , async ( ) => {
304+ const startAccount = vi . fn ( async ( ctx : ChannelGatewayContext < TestAccount > ) => {
305+ ctx . setStatus ( {
306+ accountId : DEFAULT_ACCOUNT_ID ,
307+ running : true ,
308+ connected : true ,
309+ lastError : "startup warning" ,
310+ } ) ;
311+ await new Promise < void > ( ( resolve ) => {
312+ ctx . abortSignal . addEventListener ( "abort" , ( ) => resolve ( ) , { once : true } ) ;
313+ } ) ;
314+ } ) ;
315+ const stopAccount = vi . fn ( async ( ctx : ChannelGatewayContext < TestAccount > ) => {
316+ ctx . setStatus ( {
317+ accountId : DEFAULT_ACCOUNT_ID ,
318+ connected : false ,
319+ lastError : null ,
320+ } ) ;
321+ } ) ;
322+ installTestRegistry ( createTestPlugin ( { startAccount, stopAccount } ) ) ;
323+ const manager = createManager ( ) ;
324+
325+ await manager . startChannels ( ) ;
326+ await flushMicrotasks ( ) ;
327+ await manager . stopChannel ( "discord" , DEFAULT_ACCOUNT_ID ) ;
328+
329+ const snapshot = manager . getRuntimeSnapshot ( ) ;
330+ const account = snapshot . channelAccounts . discord ?. [ DEFAULT_ACCOUNT_ID ] ;
331+ expect ( stopAccount ) . toHaveBeenCalledTimes ( 1 ) ;
332+ expect ( account ?. running ) . toBe ( false ) ;
333+ expect ( account ?. connected ) . toBe ( false ) ;
334+ expect ( account ?. lastError ) . toBeNull ( ) ;
335+ } ) ;
336+
303337 it ( "does not enumerate configured accounts when stopping a never-started channel" , async ( ) => {
304338 const listAccountIds = vi . fn ( ( ) => [ DEFAULT_ACCOUNT_ID ] ) ;
305339 const resolveAccount = vi . fn ( ( ) => ( { enabled : true , configured : true } ) ) ;
0 commit comments