@@ -1178,6 +1178,87 @@ describe('HatchboxManager', () => {
11781178 expect ( mockGitWorktree . createWorktree ) . not . toHaveBeenCalled ( )
11791179 } )
11801180
1181+ it ( 'should NOT copy .env file or set PORT when reusing existing worktree for issue' , async ( ) => {
1182+ const input : CreateHatchboxInput = {
1183+ type : 'issue' ,
1184+ identifier : 39 ,
1185+ originalInput : '39' ,
1186+ }
1187+
1188+ const existingWorktree = {
1189+ path : '/test/worktree-issue-39' ,
1190+ branch : 'issue-39-test' ,
1191+ commit : 'abc123' ,
1192+ bare : false ,
1193+ detached : false ,
1194+ locked : false ,
1195+ }
1196+
1197+ vi . mocked ( mockGitHub . fetchIssue ) . mockResolvedValue ( {
1198+ number : 39 ,
1199+ title : 'Test Issue' ,
1200+ body : 'Test description' ,
1201+ state : 'open' ,
1202+ labels : [ ] ,
1203+ assignees : [ ] ,
1204+ url : 'https://github.com/test/repo/issues/39' ,
1205+ } )
1206+ vi . mocked ( mockGitWorktree . findWorktreeForIssue ) . mockResolvedValue ( existingWorktree )
1207+ vi . mocked ( mockCapabilityDetector . detectCapabilities ) . mockResolvedValue ( {
1208+ capabilities : [ 'web' ] ,
1209+ binEntries : { } ,
1210+ } )
1211+
1212+ await manager . createHatchbox ( input )
1213+
1214+ // BUG: These operations should NOT be called when reusing an existing worktree
1215+ // The .env file was already set up during initial worktree creation
1216+ expect ( mockEnvironment . copyEnvFile ) . not . toHaveBeenCalled ( )
1217+ expect ( mockEnvironment . setPortForWorkspace ) . not . toHaveBeenCalled ( )
1218+ expect ( mockEnvironment . setEnvVar ) . not . toHaveBeenCalled ( )
1219+ } )
1220+
1221+ it ( 'should NOT copy .env file or set PORT when reusing existing worktree for PR' , async ( ) => {
1222+ const input : CreateHatchboxInput = {
1223+ type : 'pr' ,
1224+ identifier : 42 ,
1225+ originalInput : 'pr/42' ,
1226+ }
1227+
1228+ const existingWorktree = {
1229+ path : '/test/worktree-feat-test_pr_42' ,
1230+ branch : 'feat/test-feature' ,
1231+ commit : 'def456' ,
1232+ bare : false ,
1233+ detached : false ,
1234+ locked : false ,
1235+ }
1236+
1237+ vi . mocked ( mockGitHub . fetchPR ) . mockResolvedValue ( {
1238+ number : 42 ,
1239+ title : 'Test PR' ,
1240+ body : 'Test description' ,
1241+ state : 'open' ,
1242+ branch : 'feat/test-feature' ,
1243+ baseBranch : 'main' ,
1244+ url : 'https://github.com/test/repo/pull/42' ,
1245+ isDraft : false ,
1246+ } )
1247+ vi . mocked ( mockGitWorktree . findWorktreeForPR ) . mockResolvedValue ( existingWorktree )
1248+ vi . mocked ( mockCapabilityDetector . detectCapabilities ) . mockResolvedValue ( {
1249+ capabilities : [ 'web' ] ,
1250+ binEntries : { } ,
1251+ } )
1252+
1253+ await manager . createHatchbox ( input )
1254+
1255+ // BUG: These operations should NOT be called when reusing an existing worktree
1256+ // The .env file was already set up during initial worktree creation
1257+ expect ( mockEnvironment . copyEnvFile ) . not . toHaveBeenCalled ( )
1258+ expect ( mockEnvironment . setPortForWorkspace ) . not . toHaveBeenCalled ( )
1259+ expect ( mockEnvironment . setEnvVar ) . not . toHaveBeenCalled ( )
1260+ } )
1261+
11811262 it ( 'should still call moveIssueToInProgress for issue reuse' , async ( ) => {
11821263 const input : CreateHatchboxInput = {
11831264 type : 'issue' ,
0 commit comments