Skip to content

Commit 71e1f2a

Browse files
fix(server): threads launched in the project folder record its branch (pingdotgg#34812)
1 parent dbfbe39 commit 71e1f2a

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

‎apps/server/src/orchestration-v2/ThreadLaunchService.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ function makeHarness(options: HarnessOptions = {}) {
210210
options.fetchWorktreeBaseCommit ??
211211
(() => Effect.succeed({ commitSha: "remote-main-sha", remoteRefName: "origin/main" })),
212212
hasCommit: options.hasCommit ?? (() => Effect.succeed(false)),
213+
currentBranch: () => Effect.succeed(null),
213214
resolveWorktreeBaseRemote: () => Effect.succeed({ remoteName: "origin", branchName: "main" }),
214215
remoteExists: options.remoteExists ?? (() => Effect.succeed(true)),
215216
remoteBranchExists: () => Effect.succeed(true),
@@ -981,6 +982,21 @@ function scheduledTaskInput(id: string, targetProjectId: ProjectId) {
981982
};
982983
}
983984

985+
it.effect("records the checkout's branch on a root launch that names none", () => {
986+
const harness = makeHarness({
987+
git: { currentBranch: () => Effect.succeed("fix/checkout-total") },
988+
});
989+
return Effect.gen(function* () {
990+
const launches = yield* ThreadLaunch.ThreadLaunchService;
991+
const launched = yield* launches.launch(
992+
launchInput({ command: "command:launch:root-branch", thread: "thread:launch:root-branch" }),
993+
);
994+
const threads = yield* ThreadManagement.ThreadManagementService;
995+
const { thread } = yield* threads.getThreadProjection(launched.threadId);
996+
assert.equal(thread.branch, "fix/checkout-total");
997+
}).pipe(Effect.provide(harness.layer));
998+
});
999+
9841000
it.effect("launches a worktree request for Scratch at the root, in its own folder", () => {
9851001
const harness = scratchHarness();
9861002
return Effect.gen(function* () {

‎apps/server/src/orchestration-v2/ThreadLaunchService.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ const make = Effect.gen(function* () {
248248
const ids = yield* IdAllocator.IdAllocatorV2;
249249
const threads = yield* ThreadManagement.ThreadManagementService;
250250
const managedFolders = yield* ManagedProjectFolders.ManagedProjectFolders;
251+
// A project-folder launch that names no branch records the folder's checkout, as the composer does.
252+
const launchBranch = (strategy: ThreadLaunchWorkspaceStrategy, workspaceRoot: string) =>
253+
strategy.type === "root" && strategy.branch === undefined
254+
? git.currentBranch(workspaceRoot).pipe(Effect.orElseSucceed(() => null))
255+
: Effect.succeed(strategy.branch ?? null);
251256
const preparationScope = yield* Scope.make("sequential");
252257
const scheduledLaunches = yield* Ref.make<ReadonlySet<CommandId>>(new Set());
253258
yield* Effect.addFinalizer(() => Scope.close(preparationScope, Exit.void));
@@ -446,7 +451,7 @@ const make = Effect.gen(function* () {
446451
const uuid = yield* randomUuidV4;
447452
branch = buildTemporaryWorktreeBranchName(() => uuid.replaceAll("-", ""));
448453
} else {
449-
branch = requestedBranch ?? null;
454+
branch = yield* launchBranch(input.workspaceStrategy, project.workspaceRoot);
450455
}
451456
let worktreePath =
452457
input.workspaceStrategy.type === "existing_worktree"
@@ -990,7 +995,7 @@ const make = Effect.gen(function* () {
990995
},
991996
)
992997
: input.workspaceStrategy;
993-
const initialBranch = workspaceStrategy.branch ?? null;
998+
const initialBranch = yield* launchBranch(workspaceStrategy, project.workspaceRoot);
994999
const initialWorktreePath =
9951000
workspaceStrategy.type === "existing_worktree" ? workspaceStrategy.worktreePath : null;
9961001
const claimDispatch =

0 commit comments

Comments
 (0)