@@ -2799,15 +2799,55 @@ describe("storage cleanup reports and local file policies", () => {
27992799 } ) ,
28002800 ) ,
28012801 ) ;
2802+ it . live ( "keeps an unsettled new thread's unchanged worktree after its first turn" , ( ) =>
2803+ runCleanupTest (
2804+ Effect . gen ( function * ( ) {
2805+ const { service, fs, worktree, setThreads } = yield * cleanupFixture ( {
2806+ ...DEFAULT_SERVER_SETTINGS . storageCleanup ,
2807+ worktreeSettledAfterDays : 11 ,
2808+ worktreeOnMerge : true ,
2809+ worktreeUnchanged : true ,
2810+ } ) ;
2811+ const now = yield * DateTime . now ;
2812+ const minutesAgo = ( minutes : number ) => DateTime . subtract ( now , { minutes } ) ;
2813+ const thread = shell ( {
2814+ branch : "feature" ,
2815+ worktreePath : worktree ,
2816+ status : "completed" ,
2817+ createdAt : minutesAgo ( 40 ) ,
2818+ latestUserMessageAt : minutesAgo ( 40 ) ,
2819+ latestRunRequestedAt : minutesAgo ( 40 ) ,
2820+ latestRunStartedAt : minutesAgo ( 40 ) ,
2821+ latestRunCompletedAt : minutesAgo ( 20 ) ,
2822+ updatedAt : minutesAgo ( 20 ) ,
2823+ } ) ;
2824+ setThreads ( [ thread ] ) ;
2825+
2826+ const report = yield * service . runNow ;
2827+ expect ( report . entries [ 0 ] ) . toMatchObject ( { outcome : "kept" } ) ;
2828+ expect ( yield * fs . exists ( worktree ) ) . toBe ( true ) ;
2829+
2830+ setThreads ( [ { ...thread , settledAt : minutesAgo ( 10 ) , updatedAt : minutesAgo ( 10 ) } ] ) ;
2831+ const settled = yield * service . runNow ;
2832+ expect ( settled . entries [ 0 ] ) . toMatchObject ( {
2833+ outcome : "removed" ,
2834+ reason : "No commits beyond the project branch" ,
2835+ } ) ;
2836+ } ) ,
2837+ ) ,
2838+ ) ;
28022839 it . live (
28032840 "discovers trunk without a remote HEAD or tracking ref and removes an integrated worktree" ,
28042841 ( ) =>
28052842 runCleanupTest (
28062843 Effect . gen ( function * ( ) {
2807- const { service, fs, repo, worktree, command } = yield * cleanupFixture ( {
2844+ const { service, fs, repo, worktree, command, setThreads } = yield * cleanupFixture ( {
28082845 ...DEFAULT_SERVER_SETTINGS . storageCleanup ,
28092846 worktreeUnchanged : true ,
28102847 } ) ;
2848+ setThreads ( [
2849+ shell ( { branch : "feature" , worktreePath : worktree , archivedAt : at ( - DAY_MS ) } ) ,
2850+ ] ) ;
28112851 const remote = yield * fs . makeTempDirectoryScoped ( { prefix : "cleanup-remote-" } ) ;
28122852 yield * command ( remote , [ "init" , "--bare" , "-b" , "trunk" ] ) ;
28132853 yield * command ( repo , [ "remote" , "add" , "origin" , remote ] ) ;
@@ -2829,10 +2869,13 @@ describe("storage cleanup reports and local file policies", () => {
28292869 ( ) =>
28302870 runCleanupTest (
28312871 Effect . gen ( function * ( ) {
2832- const { service, fs, repo, worktree, command } = yield * cleanupFixture ( {
2872+ const { service, fs, repo, worktree, command, setThreads } = yield * cleanupFixture ( {
28332873 ...DEFAULT_SERVER_SETTINGS . storageCleanup ,
28342874 worktreeUnchanged : true ,
28352875 } ) ;
2876+ setThreads ( [
2877+ shell ( { branch : "feature" , worktreePath : worktree , archivedAt : at ( - DAY_MS ) } ) ,
2878+ ] ) ;
28362879 const remote = yield * fs . makeTempDirectoryScoped ( { prefix : "cleanup-remote-" } ) ;
28372880 yield * command ( remote , [ "init" , "--bare" , "-b" , "trunk" ] ) ;
28382881 yield * command ( repo , [ "remote" , "add" , "origin" , remote ] ) ;
@@ -2857,10 +2900,11 @@ describe("storage cleanup reports and local file policies", () => {
28572900 it . live ( "keeps the worktree when the remote default is unavailable even if main exists" , ( ) =>
28582901 runCleanupTest (
28592902 Effect . gen ( function * ( ) {
2860- const { service, fs, repo, worktree, command } = yield * cleanupFixture ( {
2903+ const { service, fs, repo, worktree, command, setThreads } = yield * cleanupFixture ( {
28612904 ...DEFAULT_SERVER_SETTINGS . storageCleanup ,
28622905 worktreeUnchanged : true ,
28632906 } ) ;
2907+ setThreads ( [ shell ( { branch : "feature" , worktreePath : worktree , archivedAt : at ( - DAY_MS ) } ) ] ) ;
28642908 const remote = yield * fs . makeTempDirectoryScoped ( { prefix : "cleanup-remote-" } ) ;
28652909 yield * command ( remote , [ "init" , "--bare" , "-b" , "trunk" ] ) ;
28662910 yield * command ( repo , [ "remote" , "add" , "origin" , remote ] ) ;
0 commit comments