@@ -561,13 +561,7 @@ describe("subagent worktree ownership", () => {
561561 root ,
562562 ] ) ;
563563 const report = yield * fixture . service . runNow ;
564- const removed = [
565- "idle" ,
566- "grandchild" ,
567- "null-branch" ,
568- "isolated-owner" ,
569- "fork-owner" ,
570- ] . includes ( scenario ) ;
564+ const removed = [ "idle" , "grandchild" , "isolated-owner" , "fork-owner" ] . includes ( scenario ) ;
571565 const shared = [
572566 "unrelated" ,
573567 "fork" ,
@@ -586,58 +580,67 @@ describe("subagent worktree ownership", () => {
586580 ? "Thread is running or has pending work"
587581 : shared
588582 ? "Shared by 2 threads"
589- : scenario === "recent-activity"
590- ? "Settled for 2 of 8 days"
591- : scenario === "recent-inactive"
592- ? "Inactive for 2 of 8 days"
593- : [ "recent-grace" , "recent-settle" , "child-settled-now" ] . includes ( scenario )
594- ? "Settled moments ago"
595- : "Not settled" ,
583+ : scenario === "null-branch"
584+ ? "A subagent thread has no branch to restore it from"
585+ : scenario === "recent-activity"
586+ ? "Settled for 2 of 8 days"
587+ : scenario === "recent-inactive"
588+ ? "Inactive for 2 of 8 days"
589+ : [ "recent-grace" , "recent-settle" , "child-settled-now" ] . includes ( scenario )
590+ ? "Settled moments ago"
591+ : "Not settled" ,
596592 } ) ;
597593 } ) . pipe ( Effect . provide ( cleanupTestLayer ) , Effect . scoped ) ,
598594 ) ;
599595
600- it . live . each ( [ "running" , "pending" , "activity" , "unrelated" , "settled" , "resettled" ] as const ) (
601- "cancels removal when a child changes during measurement (%s)" ,
602- ( change ) =>
603- runCleanupTest (
604- Effect . gen ( function * ( ) {
605- const fixture = yield * pausedMeasurementFixture ( ) ;
606- const root = shell ( { branch : "feature" , worktreePath : fixture . worktree } ) ;
607- const child = {
608- ...root ,
609- id : ThreadId . make ( "child" ) ,
610- settledAt : change === "resettled" ? at ( - 20 * DAY_MS ) : null ,
611- lineage : {
612- parentThreadId : root . id ,
613- rootThreadId : root . id ,
614- relationshipToParent : "subagent" as const ,
615- } ,
616- } ;
617- fixture . setThreads ( [ child , root ] ) ;
618- const run = yield * fixture . service . runNow . pipe ( Effect . forkChild ) ;
619- yield * Deferred . await ( fixture . measuring ) ;
620- fixture . setThreads ( [
621- root ,
622- {
623- ...child ,
624- settledAt : change === "settled" ? at ( - 20 * DAY_MS ) : child . settledAt ,
625- updatedAt : change === "settled" || change === "resettled" ? at ( 0 ) : child . updatedAt ,
626- status : change === "running" ? "running" : "idle" ,
627- pendingBackgroundTasks :
628- change === "pending" ? [ { taskId : "task" , kind : "command" } ] : [ ] ,
629- latestRunCompletedAt : change === "activity" ? at ( - DAY_MS ) : null ,
630- } ,
631- ...( change === "unrelated" ? [ shell ( { ...root , id : ThreadId . make ( "other" ) } ) ] : [ ] ) ,
632- ] ) ;
633- yield * Deferred . succeed ( fixture . resume , undefined ) ;
634- expect ( ( yield * Fiber . join ( run ) ) . entries [ 0 ] ) . toMatchObject ( {
635- outcome : "kept" ,
636- reason : "Thread activity or shared worktree changed since check" ,
637- } ) ;
638- expect ( yield * fixture . fs . exists ( fixture . worktree ) ) . toBe ( true ) ;
639- } ) ,
640- ) ,
596+ it . live . each ( [
597+ "running" ,
598+ "pending" ,
599+ "activity" ,
600+ "unrelated" ,
601+ "settled" ,
602+ "resettled" ,
603+ "null-branch" ,
604+ ] as const ) ( "cancels removal when a child changes during measurement (%s)" , ( change ) =>
605+ runCleanupTest (
606+ Effect . gen ( function * ( ) {
607+ const fixture = yield * pausedMeasurementFixture ( ) ;
608+ const root = shell ( { branch : "feature" , worktreePath : fixture . worktree } ) ;
609+ const child = {
610+ ...root ,
611+ id : ThreadId . make ( "child" ) ,
612+ settledAt : change === "resettled" ? at ( - 20 * DAY_MS ) : null ,
613+ lineage : {
614+ parentThreadId : root . id ,
615+ rootThreadId : root . id ,
616+ relationshipToParent : "subagent" as const ,
617+ } ,
618+ } ;
619+ fixture . setThreads ( [ child , root ] ) ;
620+ const run = yield * fixture . service . runNow . pipe ( Effect . forkChild ) ;
621+ yield * Deferred . await ( fixture . measuring ) ;
622+ fixture . setThreads ( [
623+ root ,
624+ {
625+ ...child ,
626+ branch : change === "null-branch" ? null : child . branch ,
627+ settledAt : change === "settled" ? at ( - 20 * DAY_MS ) : child . settledAt ,
628+ updatedAt : change === "settled" || change === "resettled" ? at ( 0 ) : child . updatedAt ,
629+ status : change === "running" ? "running" : "idle" ,
630+ pendingBackgroundTasks :
631+ change === "pending" ? [ { taskId : "task" , kind : "command" } ] : [ ] ,
632+ latestRunCompletedAt : change === "activity" ? at ( - DAY_MS ) : null ,
633+ } ,
634+ ...( change === "unrelated" ? [ shell ( { ...root , id : ThreadId . make ( "other" ) } ) ] : [ ] ) ,
635+ ] ) ;
636+ yield * Deferred . succeed ( fixture . resume , undefined ) ;
637+ expect ( ( yield * Fiber . join ( run ) ) . entries [ 0 ] ) . toMatchObject ( {
638+ outcome : "kept" ,
639+ reason : "Thread activity or shared worktree changed since check" ,
640+ } ) ;
641+ expect ( yield * fixture . fs . exists ( fixture . worktree ) ) . toBe ( true ) ;
642+ } ) ,
643+ ) ,
641644 ) ;
642645} ) ;
643646
0 commit comments