fix(FN-4476): handle fully-subsumed branch conflicts across reclaim paths

Fusion-Task-Id: FN-4476
Fusion-Task-Lineage: 8673c1d9-f47e-4d02-89e6-646040b9be32
This commit is contained in:
Fusion
2026-05-14 08:21:15 -07:00
committed by gsxdsm
parent ab4729099c
commit d8255c2bb0
4 changed files with 116 additions and 4 deletions

View File

@@ -341,6 +341,19 @@ describe("WorktreePool", () => {
return Buffer.from("");
});
vi.spyOn(branchConflictModule, "inspectBranchConflict").mockResolvedValueOnce({
kind: "live-foreign",
livePath: "/other/wt",
error: new BranchConflictError({
branchName: "fusion/fn-042",
conflictingWorktreePath: "/other/wt",
existingTipSha: "abc123def456",
strandedCommits: [{ sha: "aaa111", subject: "Foreign fix" }],
startPoint: "main",
recommendedAction: "Run branch recovery",
}),
});
await expect(pool.prepareForTask("/tmp/wt", "fusion/fn-042", undefined, {
repoDir: "/tmp/repo",
requestingTaskId: "FN-042",
@@ -371,6 +384,19 @@ describe("WorktreePool", () => {
return Buffer.from("");
});
vi.spyOn(branchConflictModule, "inspectBranchConflict").mockResolvedValueOnce({
kind: "live-foreign",
livePath: "/other/wt",
error: new BranchConflictError({
branchName: "fusion/fn-042",
conflictingWorktreePath: "/other/wt",
existingTipSha: "abc123def456",
strandedCommits: [{ sha: "aaa111", subject: "Foreign fix" }],
startPoint: "fusion/fn-041",
recommendedAction: "Run branch recovery",
}),
});
const result = await pool.prepareForTask("/tmp/wt", "fusion/fn-042", "fusion/fn-041", { allowSiblingBranchRename: true, repoDir: "/tmp/repo" });
expect(result.branch).toBe("fusion/fn-042-2");
});
@@ -394,6 +420,19 @@ describe("WorktreePool", () => {
return Buffer.from("");
});
vi.spyOn(branchConflictModule, "inspectBranchConflict").mockResolvedValueOnce({
kind: "live-foreign",
livePath: "/other/wt",
error: new BranchConflictError({
branchName: "fusion/fn-042",
conflictingWorktreePath: "/other/wt",
existingTipSha: "abc123def456",
strandedCommits: [{ sha: "aaa111", subject: "Foreign fix" }],
startPoint: "main",
recommendedAction: "Run branch recovery",
}),
});
const result = await pool.prepareForTask("/tmp/wt", "fusion/fn-042", undefined, { allowSiblingBranchRename: true, repoDir: "/tmp/repo" });
expect(result.branch).toBe("fusion/fn-042-3");
});
@@ -460,6 +499,19 @@ describe("WorktreePool", () => {
return Buffer.from("");
});
vi.spyOn(branchConflictModule, "inspectBranchConflict").mockResolvedValue({
kind: "live-foreign",
livePath: "/other/wt",
error: new BranchConflictError({
branchName: "fusion/fn-042",
conflictingWorktreePath: "/other/wt",
existingTipSha: "abc123def456",
strandedCommits: [{ sha: "aaa111", subject: "Foreign fix" }],
startPoint: "main",
recommendedAction: "Run branch recovery",
}),
});
await expect(pool.prepareForTask("/tmp/wt", "fusion/fn-042", undefined, { allowSiblingBranchRename: true, repoDir: "/tmp/repo" })).rejects.toThrow(/suffixes -2 through -6 are all in use/);
});
});