@@ -107,7 +107,7 @@ test("real git worktree isolates a fix, verifies, commits and pushes to a local
107107 assert . equal ( await git . hasBranch ( repo , "release/next" ) , true ) ;
108108 assert . equal ( await git . hasBranch ( repo , "release" ) , false ) ;
109109 assert . equal ( await git . hasBranch ( repo , "missing" ) , false ) ;
110- const t = task ( ) ; Object . assign ( t , await git . prepare ( t , repo ) ) ;
110+ const t : Task = { ... task ( ) , worktree : undefined } ; Object . assign ( t , await git . prepare ( t , repo ) ) ;
111111 assert . equal ( t . baseSha , selectedBase ) ;
112112 assert . match ( await readFile ( join ( t . worktree ! , "release.txt" ) , "utf8" ) , / r e l e a s e - o n l y / ) ;
113113 await installWorkerPlugin ( t . worktree ! , options , run ) ;
@@ -124,10 +124,30 @@ test("real git worktree isolates a fix, verifies, commits and pushes to a local
124124 const withoutTests = await git . verify ( t , { ...repo , checks : [ ] } ) ;
125125 assert . deepEqual ( withoutTests . checks , [ ] ) ;
126126 assert . equal ( withoutTests . commit , t . commit ) ;
127+ // Recovery can rename a published branch without moving its worktree.
128+ // Follow-up prepare, verification, and push must all honor the checkpoint.
129+ const savedPath = t . worktree ! , savedBase = t . baseSha ;
130+ await run ( savedPath , [ "git" , "branch" , "-m" , "recovered-feature" ] ) ;
131+ t . branch = "recovered-feature" ;
132+ await writeFile ( join ( savedPath , "followup.txt" ) , "preserve this uncommitted work\n" ) ;
133+ Object . assign ( t , await git . prepare ( t , repo ) ) ;
134+ assert . equal ( t . worktree , savedPath ) ;
135+ assert . equal ( t . baseSha , savedBase ) ;
136+ assert . equal ( await readFile ( join ( savedPath , "followup.txt" ) , "utf8" ) , "preserve this uncommitted work\n" ) ;
137+ Object . assign ( t , await git . verify ( t , repo ) ) ;
138+ await git . push ( t , repo ) ;
139+ assert . equal ( await run ( dir , [ "git" , "--git-dir" , remote , "rev-parse" , "refs/heads/recovered-feature" ] ) , t . commit ) ;
140+ await assert . rejects ( git . prepare ( { ...t , worktree : join ( state , "worktrees" , "missing-checkpoint" ) } , repo ) , / S a v e d t a s k w o r k t r e e i s m i s s i n g / ) ;
141+ await assert . rejects ( git . prepare ( { ...t , worktree : checkout } , repo ) , / U n e x p e c t e d w o r k t r e e p a t h / ) ;
142+ await assert . rejects ( git . prepare ( { ...t , branch : "wrong-branch" } , repo ) , / W o r k t r e e b r a n c h c h a n g e d / ) ;
143+ const foreign = join ( savedPath , ".." , "foreign" ) ;
144+ await mkdir ( foreign ) ;
145+ await run ( foreign , [ "git" , "init" , "-b" , t . branch ] ) ;
146+ await assert . rejects ( git . prepare ( { ...t , worktree : foreign } , repo ) , / a n o t h e r r e p o s i t o r y / ) ;
127147 assert . equal ( await run ( t . worktree ! , [ "git" , "ls-files" , "--" , ".opencode/plugins/automation-runtime/index.js" ] ) , "" ) ;
128148 await writeFile ( runtimePath , "// User customization\n" ) ;
129149 await assert . rejects ( installWorkerPlugin ( t . worktree ! , options , run ) , / c u s t o m i z e d / ) ;
130- await assert . rejects ( git . prepare ( { ...task ( ) , branch : "automation/missing-base" } , { ...repo , baseBranch : "missing" } ) , / C o u l d n o t f e t c h b a s e b r a n c h m i s s i n g / ) ;
150+ await assert . rejects ( git . prepare ( { ...task ( ) , worktree : undefined , branch : "automation/missing-base" } , { ...repo , baseBranch : "missing" } ) , / C o u l d n o t f e t c h b a s e b r a n c h m i s s i n g / ) ;
131151 await writeFile ( join ( t . worktree ! , "counter.txt" ) , "changed after verification\n" ) ;
132152 await assert . rejects ( git . push ( t , repo ) , / c h a n g e d a f t e r v e r i f i c a t i o n / ) ;
133153 } finally { await rm ( dir , { recursive : true , force : true } ) ; }
0 commit comments