Skip to content

Commit 78f12a7

Browse files
StiensWoutclaude
andcommitted
test(mobile): fold stale current-branch cases into the switch test
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent d0215d1 commit 78f12a7

1 file changed

Lines changed: 4 additions & 39 deletions

File tree

‎apps/mobile/src/features/threads/checkout-new-task-branch.test.ts‎

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ const refuseSwitch: CheckoutInput["switchRef"] = () => {
9797
throw new Error("An occupied branch must not trigger checkout");
9898
};
9999

100-
function selectBranch(switchRef: CheckoutInput["switchRef"], picked = branch) {
100+
function selectBranch(switchRef: CheckoutInput["switchRef"]) {
101101
return checkoutNewTaskBranch({
102-
branch: picked,
102+
branch,
103103
project: { environmentId, workspaceRoot: cwd },
104104
workspaceMode: "local",
105105
readRefs,
@@ -135,47 +135,12 @@ async function addRemote(remoteName: string, sourceRef = branch.name) {
135135
}
136136

137137
describe("new-task branch checkout", () => {
138-
// The picker's list can say the branch is checked out after Git moved on.
139-
async function pickWhileCurrent() {
140-
await git("checkout", branch.name);
141-
const listed = await readRefs({ environmentId, input: { cwd, query: branch.name } });
142-
if (listed._tag !== "Success") throw new Error("List failed");
143-
const picked = listed.value.refs.find((ref) => ref.name === branch.name);
144-
if (!picked?.current) throw new Error("The branch was not listed as current");
145-
await git("checkout", "main");
146-
return picked;
147-
}
148-
149-
it("checks out a branch listed as current after the project switched away", async () => {
150-
const picked = await pickWhileCurrent();
151-
expect((await selectBranch(switchRef, picked))._tag).toBe("Success");
152-
expect((await git("branch", "--show-current")).stdout.trim()).toBe(branch.name);
153-
expect(await NodeFSP.readFile(NodePath.join(cwd, "file.txt"), "utf8")).toBe("feature\n");
154-
});
155-
156-
it("reuses the worktree a branch listed as current has since moved to", async () => {
157-
const picked = await pickWhileCurrent();
158-
const worktreePath = NodePath.join(directory, "moved-worktree");
159-
await git("worktree", "add", worktreePath, branch.name);
160-
const result = await selectBranch(refuseSwitch, picked);
161-
if (result._tag !== "Success") throw new Error("Checkout failed");
162-
expect(result.value.worktreePath).toBe(worktreePath);
163-
expect((await git("branch", "--show-current")).stdout.trim()).toBe("main");
164-
});
165-
166-
it("fails for a branch listed as current that has since been deleted", async () => {
167-
const picked = await pickWhileCurrent();
168-
await git("branch", "-D", branch.name);
169-
expect((await selectBranch(switchRef, picked))._tag).toBe("Failure");
170-
expect((await git("branch", "--show-current")).stdout.trim()).toBe("main");
171-
});
172-
173-
it("switches to a free branch and clears its historical worktree path", async () => {
138+
it("switches to a free branch despite stale current and worktree metadata", async () => {
174139
const previousWorktree = NodePath.join(directory, "previous-worktree");
175140
await git("worktree", "add", previousWorktree, branch.name);
176141
await exec("git", ["-C", previousWorktree, "checkout", "-b", "other-branch"]);
177142
const result = await checkoutNewTaskBranch({
178-
branch: { ...branch, worktreePath: previousWorktree },
143+
branch: { ...branch, current: true, worktreePath: previousWorktree },
179144
project: { environmentId, workspaceRoot: cwd },
180145
workspaceMode: "local",
181146
readRefs,

0 commit comments

Comments
 (0)