@@ -1567,6 +1567,83 @@ describe("storage cleanup reports and local file policies", () => {
15671567 } ) ,
15681568 ) ,
15691569 ) ;
1570+ it . live (
1571+ "discovers trunk without a remote HEAD or tracking ref and removes an integrated worktree" ,
1572+ ( ) =>
1573+ runCleanupTest (
1574+ Effect . gen ( function * ( ) {
1575+ const { service, fs, repo, worktree, command } = yield * cleanupFixture ( {
1576+ ...DEFAULT_SERVER_SETTINGS . storageCleanup ,
1577+ worktreeUnchanged : true ,
1578+ } ) ;
1579+ const remote = yield * fs . makeTempDirectoryScoped ( { prefix : "cleanup-remote-" } ) ;
1580+ yield * command ( remote , [ "init" , "--bare" , "-b" , "trunk" ] ) ;
1581+ yield * command ( repo , [ "remote" , "add" , "origin" , remote ] ) ;
1582+ yield * command ( repo , [ "push" , "origin" , "main:trunk" ] ) ;
1583+ yield * command ( repo , [ "update-ref" , "-d" , "refs/remotes/origin/trunk" ] ) ;
1584+ expect ( ( yield * command ( repo , [ "for-each-ref" , "refs/remotes/origin" ] ) ) . stdout ) . toBe ( "" ) ;
1585+
1586+ const report = yield * service . runNow ;
1587+ expect ( report . entries [ 0 ] ) . toMatchObject ( {
1588+ outcome : "removed" ,
1589+ reason : "No commits beyond the default branch" ,
1590+ } ) ;
1591+ expect ( yield * fs . exists ( worktree ) ) . toBe ( false ) ;
1592+ } ) ,
1593+ ) ,
1594+ ) ;
1595+ it . live (
1596+ "keeps worktree commits present on nondefault main but absent from advertised trunk" ,
1597+ ( ) =>
1598+ runCleanupTest (
1599+ Effect . gen ( function * ( ) {
1600+ const { service, fs, repo, worktree, command } = yield * cleanupFixture ( {
1601+ ...DEFAULT_SERVER_SETTINGS . storageCleanup ,
1602+ worktreeUnchanged : true ,
1603+ } ) ;
1604+ const remote = yield * fs . makeTempDirectoryScoped ( { prefix : "cleanup-remote-" } ) ;
1605+ yield * command ( remote , [ "init" , "--bare" , "-b" , "trunk" ] ) ;
1606+ yield * command ( repo , [ "remote" , "add" , "origin" , remote ] ) ;
1607+ yield * command ( repo , [ "push" , "origin" , "main:trunk" ] ) ;
1608+ yield * fs . writeFileString ( `${ worktree } /tracked.txt` , "unmerged work\n" ) ;
1609+ yield * command ( worktree , [ "commit" , "-am" , "unmerged work" ] ) ;
1610+ yield * command ( repo , [ "push" , "origin" , "feature:main" ] ) ;
1611+ expect (
1612+ ( yield * command ( repo , [ "symbolic-ref" , "refs/remotes/origin/HEAD" ] ) . pipe ( Effect . exit ) )
1613+ . _tag ,
1614+ ) . toBe ( "Failure" ) ;
1615+
1616+ const report = yield * service . runNow ;
1617+ expect ( report . entries [ 0 ] ) . toMatchObject ( {
1618+ outcome : "kept" ,
1619+ reason : "Has commits beyond the default branch" ,
1620+ } ) ;
1621+ expect ( yield * fs . readFileString ( `${ worktree } /tracked.txt` ) ) . toBe ( "unmerged work\n" ) ;
1622+ } ) ,
1623+ ) ,
1624+ ) ;
1625+ it . live ( "keeps the worktree when the remote default is unavailable even if main exists" , ( ) =>
1626+ runCleanupTest (
1627+ Effect . gen ( function * ( ) {
1628+ const { service, fs, repo, worktree, command } = yield * cleanupFixture ( {
1629+ ...DEFAULT_SERVER_SETTINGS . storageCleanup ,
1630+ worktreeUnchanged : true ,
1631+ } ) ;
1632+ const remote = yield * fs . makeTempDirectoryScoped ( { prefix : "cleanup-remote-" } ) ;
1633+ yield * command ( remote , [ "init" , "--bare" , "-b" , "trunk" ] ) ;
1634+ yield * command ( repo , [ "remote" , "add" , "origin" , remote ] ) ;
1635+ // The remote HEAD names an unborn trunk; main exists but is not its default.
1636+ yield * command ( repo , [ "push" , "origin" , "main" ] ) ;
1637+
1638+ const report = yield * service . runNow ;
1639+ expect ( report . entries [ 0 ] ) . toMatchObject ( {
1640+ outcome : "kept" ,
1641+ reason : "Default branch is unavailable" ,
1642+ } ) ;
1643+ expect ( yield * fs . exists ( worktree ) ) . toBe ( true ) ;
1644+ } ) ,
1645+ ) ,
1646+ ) ;
15701647 it . live ( "preserves tracked edits written after the final status check" , ( ) =>
15711648 runCleanupTest (
15721649 Effect . gen ( function * ( ) {
0 commit comments