@@ -179,7 +179,10 @@ describe("ConfigReload", () => {
179179 ] )
180180 yield * withReload ( ctx , ( reload ) => reload . releaseBlocker ( "tui-bootstrap" ) )
181181
182- expect ( reloads ) . toEqual ( [ { directory : ctx . directory , worktree : ctx . worktree } ] )
182+ expect ( reloads ) . toEqual ( [
183+ { directory : ctx . directory , worktree : ctx . worktree } ,
184+ { directory : ctx . directory , worktree : ctx . worktree } ,
185+ ] )
183186 expect ( events . map ( ( event ) => event . type ) ) . toEqual ( [
184187 "config.reload.pending" ,
185188 "config.reload.executing" ,
@@ -362,4 +365,104 @@ describe("ConfigReload", () => {
362365 expect ( resumeCalls ) . toEqual ( [ ] )
363366 } ) ,
364367 )
368+
369+ it . effect ( "clears resumeSessionID after auto-resume so a second reload without sessionID does not reuse it" , ( ) =>
370+ Effect . gen ( function * ( ) {
371+ events . length = 0
372+ reloads . length = 0
373+ resumeCalls . length = 0
374+ const ctx = instance ( "/tmp/reload-resume-clear" )
375+
376+ yield * withReload ( ctx , ( reload ) => reload . request ( "session-first" ) )
377+ yield * withReload ( ctx , ( reload ) => reload . releaseBlocker ( "tui-bootstrap" ) )
378+
379+ expect ( resumeCalls ) . toEqual ( [ { sessionID : "session-first" } ] )
380+
381+ resumeCalls . length = 0
382+ yield * withReload ( ctx , ( reload ) => reload . request ( ) )
383+ yield * withReload ( ctx , ( reload ) => reload . releaseBlocker ( "tui-bootstrap" ) )
384+
385+ expect ( resumeCalls ) . toEqual ( [ ] )
386+ } ) ,
387+ )
388+
389+ it . effect ( "does not clear active sessions when preparing execution" , ( ) =>
390+ Effect . gen ( function * ( ) {
391+ events . length = 0
392+ reloads . length = 0
393+ const ctx = instance ( "/tmp/reload-preserve-active" )
394+
395+ yield * withReload ( ctx , ( reload ) => reload . start ( "session-active" ) )
396+ yield * withReload ( ctx , ( reload ) => reload . finish ( "session-active" ) )
397+ yield * withReload ( ctx , ( reload ) => reload . request ( "session-preserve" ) )
398+ yield * withReload ( ctx , ( reload ) => reload . releaseBlocker ( "tui-bootstrap" ) )
399+
400+ expect ( reloads ) . toHaveLength ( 1 )
401+ } ) ,
402+ )
403+
404+ it . effect ( "prunes completed state entries from the states map" , ( ) =>
405+ Effect . gen ( function * ( ) {
406+ events . length = 0
407+ reloads . length = 0
408+ const ctx = instance ( "/tmp/reload-prune" )
409+
410+ yield * withReload ( ctx , ( reload ) => reload . request ( "session-prune" ) )
411+ yield * withReload ( ctx , ( reload ) => reload . releaseBlocker ( "tui-bootstrap" ) )
412+
413+ const status = yield * withReload ( ctx , ( reload ) => reload . status ( ) )
414+ expect ( status . pending ) . toBe ( false )
415+ expect ( status . executing ) . toBe ( false )
416+ } ) ,
417+ )
418+ } )
419+
420+ describe ( "ConfigReload store failure" , ( ) => {
421+ const failEvents : PublishedEvent [ ] = [ ]
422+ const failReloads : ReloadCall [ ] = [ ]
423+ const failResumeCalls : ResumeCall [ ] = [ ]
424+
425+ const failingLayer = ConfigReload . layer . pipe (
426+ Layer . provide (
427+ Layer . mergeAll (
428+ Layer . mock ( EventV2Bridge . Service ) ( {
429+ publish : ( definition , data ) =>
430+ Effect . sync ( ( ) => {
431+ failEvents . push ( { type : definition . type , data } )
432+ return {
433+ id : EventV2 . ID . create ( ) ,
434+ type : definition . type ,
435+ data,
436+ } as EventV2 . Payload < typeof definition >
437+ } ) ,
438+ subscribe : ( ) => Stream . empty ,
439+ all : ( ) => Stream . empty ,
440+ listen : ( ) => Effect . succeed ( Effect . void ) ,
441+ } ) ,
442+ Layer . mock ( InstanceStore . Service ) ( {
443+ reload : ( ) => Effect . fail ( new Error ( "store reload failed" ) ) ,
444+ } ) ,
445+ Layer . mock ( SessionPrompt . Service ) ( {
446+ loop : ( input ) =>
447+ Effect . sync ( ( ) => {
448+ failResumeCalls . push ( { sessionID : input . sessionID } )
449+ } ) ,
450+ } ) ,
451+ ) ,
452+ ) ,
453+ )
454+
455+ const it = testEffect ( failingLayer )
456+
457+ it . effect ( "clears reloadInFlight and blockers when store.reload fails" , ( ) =>
458+ Effect . gen ( function * ( ) {
459+ const reload = yield * ConfigReload . Service
460+ const ctx = instance ( "/tmp/reload-store-failure" )
461+ yield * withInstance ( ctx , reload . request ( "session-fail" ) )
462+ yield * withInstance ( ctx , reload . releaseBlocker ( "tui-bootstrap" ) )
463+
464+ const status = yield * withInstance ( ctx , reload . status ( ) )
465+ expect ( status . executing ) . toBe ( false )
466+ } ) ,
467+ )
365468} )
0 commit comments