@@ -461,6 +461,22 @@ const cleanupFixture = (
461461 setOpenSessionCwd : ( cwd : string | null ) => {
462462 openSessionCwd = cwd ;
463463 } ,
464+ openTerminal : ( paths : { cwd : string ; worktreePath : string | null } ) =>
465+ terminalListener ?.( {
466+ type : "upsert" ,
467+ terminal : {
468+ threadId : "thread-1" ,
469+ terminalId : "terminal-1" ,
470+ status : "running" ,
471+ pid : 1 ,
472+ exitCode : null ,
473+ exitSignal : null ,
474+ hasRunningSubprocess : false ,
475+ label : "Terminal" ,
476+ updatedAt : "2026-06-10T12:00:00.000Z" ,
477+ ...paths ,
478+ } ,
479+ } ) ?? Effect . void ,
464480 fullStatusCalls : ( ) => fullStatusCalls ,
465481 snapshotReads : ( ) => snapshotReads ,
466482 activate : ( domainEvents : Stream . Stream < OrchestrationV2DomainEvent > ) => {
@@ -1594,6 +1610,54 @@ describe("orphan worktree reports", () => {
15941610 } ) ,
15951611 ) ,
15961612 ) ;
1613+
1614+ it . live . each ( [
1615+ [ "win32" , "cwd" ] ,
1616+ [ "win32" , "worktreePath" ] ,
1617+ [ "linux" , "cwd" ] ,
1618+ [ "linux" , "worktreePath" ] ,
1619+ ] as const ) (
1620+ "matches a terminal at the worktree root with host casing rules (%s, %s)" ,
1621+ ( [ platform , field ] ) =>
1622+ runCleanupTest (
1623+ Effect . gen ( function * ( ) {
1624+ const fixture = yield * cleanupFixture ( ) . pipe (
1625+ Effect . provideService ( HostProcess . Platform , platform ) ,
1626+ ) ;
1627+ const upper = fixture . worktree . toUpperCase ( ) ;
1628+ yield * fixture . openTerminal (
1629+ field === "cwd"
1630+ ? { cwd : upper , worktreePath : null }
1631+ : { cwd : fixture . repo , worktreePath : upper } ,
1632+ ) ;
1633+ const report = yield * fixture . service . runNow ;
1634+ expect ( report . entries [ 0 ] ) . toMatchObject (
1635+ platform === "win32"
1636+ ? { outcome : "kept" , reason : "Open terminal" }
1637+ : { outcome : "removed" } ,
1638+ ) ;
1639+ } ) ,
1640+ ) ,
1641+ ) ;
1642+
1643+ it . live . each ( [ "win32" , "linux" ] as const ) (
1644+ "matches a provider session at the worktree root with host casing rules (%s)" ,
1645+ ( platform ) =>
1646+ runCleanupTest (
1647+ Effect . gen ( function * ( ) {
1648+ const fixture = yield * cleanupFixture ( ) . pipe (
1649+ Effect . provideService ( HostProcess . Platform , platform ) ,
1650+ ) ;
1651+ fixture . setOpenSessionCwd ( fixture . worktree . toUpperCase ( ) ) ;
1652+ const report = yield * fixture . service . runNow ;
1653+ expect ( report . entries [ 0 ] ) . toMatchObject (
1654+ platform === "win32"
1655+ ? { outcome : "kept" , reason : "Provider session is still open" }
1656+ : { outcome : "removed" } ,
1657+ ) ;
1658+ } ) ,
1659+ ) ,
1660+ ) ;
15971661} ) ;
15981662
15991663describe ( "storage cleanup reports and local file policies" , ( ) => {
0 commit comments