@@ -99,6 +99,7 @@ interface HarnessOptions {
9999 readonly managedFolders ?: Layer . Layer < ManagedProjectFolders . ManagedProjectFolders > ;
100100 readonly createWorktree ?: GitWorkflow . GitWorkflowService [ "Service" ] [ "createWorktree" ] ;
101101 readonly fetchRemote ?: GitWorkflow . GitWorkflowService [ "Service" ] [ "fetchRemote" ] ;
102+ readonly hasCommit ?: GitWorkflow . GitWorkflowService [ "Service" ] [ "hasCommit" ] ;
102103 readonly renameBranch ?: GitWorkflow . GitWorkflowService [ "Service" ] [ "renameBranch" ] ;
103104 readonly runSetup ?: ProjectSetupScriptRunner . ProjectSetupScriptRunner [ "Service" ] [ "runForThread" ] ;
104105 readonly generateTitle ?: TextGeneration . TextGeneration [ "Service" ] [ "generateThreadTitle" ] ;
@@ -167,6 +168,7 @@ function makeHarness(options: HarnessOptions = {}) {
167168 createWorktree,
168169 renameBranch,
169170 fetchRemote : options . fetchRemote ?? ( ( ) => Effect . void ) ,
171+ hasCommit : options . hasCommit ?? ( ( ) => Effect . succeed ( true ) ) ,
170172 remoteExists : ( ) => Effect . succeed ( true ) ,
171173 remoteBranchExists : ( ) => Effect . succeed ( true ) ,
172174 removeWorktree,
@@ -1110,6 +1112,53 @@ it.effect("names the worktree itself when the client provides no branch", () =>
11101112 } ) ,
11111113) ;
11121114
1115+ it . effect ( "runs in the project folder when the repository has no commits" , ( ) =>
1116+ Effect . gen ( function * ( ) {
1117+ const harness = makeHarness ( { hasCommit : ( ) => Effect . succeed ( false ) } ) ;
1118+ yield * Effect . gen ( function * ( ) {
1119+ const launches = yield * ThreadLaunch . ThreadLaunchService ;
1120+ const threads = yield * ThreadManagement . ThreadManagementService ;
1121+ const launched = yield * launches . launch (
1122+ launchInput ( {
1123+ command : "command:launch:empty-repo" ,
1124+ thread : "thread:launch:empty-repo" ,
1125+ message : "Build the feature" ,
1126+ workspace : { type : "worktree" , baseRef : "main" } ,
1127+ } ) ,
1128+ ) ;
1129+ yield * waitUntil ( ( ) =>
1130+ threads
1131+ . getThreadProjection ( launched . threadId )
1132+ . pipe ( Effect . map ( ( projection ) => projection . runs [ 0 ] ?. status === "starting" ) ) ,
1133+ ) ;
1134+ const { thread } = yield * threads . getThreadProjection ( launched . threadId ) ;
1135+ assert . isNull ( thread . worktreePath ) ;
1136+ assert . isNull ( thread . branch ) ;
1137+ assert . equal ( harness . createWorktree . mock . calls . length , 0 ) ;
1138+ assert . equal ( harness . runSetup . mock . calls [ 0 ] ?. [ 0 ] ?. worktreePath , project . workspaceRoot ) ;
1139+ } ) . pipe ( Effect . provide ( harness . layer ) ) ;
1140+ } ) ,
1141+ ) ;
1142+
1143+ it . effect ( "still checks out from origin when only the local repository has no commits" , ( ) =>
1144+ Effect . gen ( function * ( ) {
1145+ const harness = makeHarness ( { hasCommit : ( ) => Effect . succeed ( false ) } ) ;
1146+ yield * Effect . gen ( function * ( ) {
1147+ const launches = yield * ThreadLaunch . ThreadLaunchService ;
1148+ yield * launches . launch (
1149+ launchInput ( {
1150+ command : "command:launch:empty-repo-origin" ,
1151+ thread : "thread:launch:empty-repo-origin" ,
1152+ message : "Build the feature" ,
1153+ workspace : { type : "worktree" , baseRef : "main" , startFromOrigin : true } ,
1154+ } ) ,
1155+ ) ;
1156+ yield * waitUntil ( ( ) => Effect . sync ( ( ) => harness . createWorktree . mock . calls . length === 1 ) ) ;
1157+ assert . equal ( harness . createWorktree . mock . calls [ 0 ] ?. [ 0 ] ?. refName , "remote-main-sha" ) ;
1158+ } ) . pipe ( Effect . provide ( harness . layer ) ) ;
1159+ } ) ,
1160+ ) ;
1161+
11131162it . effect ( "renames a temporary t3code/<hash> branch off the provisioning critical path" , ( ) =>
11141163 Effect . gen ( function * ( ) {
11151164 const branchNameStarted = yield * Deferred . make < void > ( ) ;
0 commit comments