FN-5827: derive per-subtask working branches in shared planning mode

Ensure planning subtask creation always assigns distinct per-task working branches while preserving shared merge-target grouping.

- route planning subtask branch assignment through resolveEntryPointBranchAssignment for both direct and merged subtask creation paths
- keep shared assignment mode grouped by branch context while deriving unique working branches from the planning branch
- update modal copy to clarify shared mode semantics (shared merge target + per-task branches)
- adjust planning/tasks route tests to assert derived per-task branch names and shared branch-context metadata

Files changed:
 .../app/components/SubtaskBreakdownModal.tsx       |  4 +-
 .../src/__tests__/routes-planning.test.ts          | 51 ++++++++++++++++++----
 .../dashboard/src/__tests__/routes-tasks.test.ts   |  2 +-
 .../src/routes/register-planning-subtask-routes.ts | 18 +++++---
 4 files changed, 57 insertions(+), 18 deletions(-)

Fusion-Task-Id: FN-5827

Fusion-Task-Lineage: 5d6d162f-b89f-49c5-b962-be41332547fe
This commit is contained in:
gsxdsm
2026-06-01 03:12:57 -07:00
parent 2546065674
commit 3f75f55707
4 changed files with 57 additions and 18 deletions

View File

@@ -731,8 +731,8 @@ export function SubtaskBreakdownModal({ isOpen, onClose, initialDescription, onT
<div className="form-group">
<label>Planning branch mode</label>
<select value={branchAssignmentMode} onChange={(event) => setBranchAssignmentMode(event.target.value as typeof branchAssignmentMode)} disabled={view.type === "creating"}>
<option value="shared">Shared branch for all subtasks</option>
<option value="per-task-derived">Per-task branch derived from planning branch</option>
<option value="shared">Shared merge target subtasks run on their own branches</option>
<option value="per-task-derived">Per-task branches derived from planning branch</option>
</select>
</div>
</div>

View File

@@ -2257,14 +2257,32 @@ describe("Planning Mode Routes", () => {
expect.objectContaining({ branchName: "feature/auth-slice", autoMerge: false }),
);
expect(store.getBranchGroupBySource).toHaveBeenCalledWith("planning", planningSessionId);
expect(store.createTask).toHaveBeenNthCalledWith(
1,
expect.objectContaining({ branch: "feature/auth-slice", baseBranch: "main" }),
);
expect(store.createTask).toHaveBeenNthCalledWith(
2,
expect.objectContaining({ branch: "feature/auth-slice", baseBranch: "main" }),
);
const firstCreateCall = (store.createTask as ReturnType<typeof vi.fn>).mock.calls[0]?.[0];
const secondCreateCall = (store.createTask as ReturnType<typeof vi.fn>).mock.calls[1]?.[0];
expect(firstCreateCall).toMatchObject({
branch: "feature/auth-slice/auth-backend",
baseBranch: "main",
branchContext: {
groupId: `planning:${planningSessionId}`,
source: "planning",
assignmentMode: "shared",
inheritedBaseBranch: "main",
},
});
expect(secondCreateCall).toMatchObject({
branch: "feature/auth-slice/auth-ui",
baseBranch: "main",
branchContext: {
groupId: `planning:${planningSessionId}`,
source: "planning",
assignmentMode: "shared",
inheritedBaseBranch: "main",
},
});
expect(firstCreateCall?.branch).not.toBe("feature/auth-slice");
expect(secondCreateCall?.branch).not.toBe("feature/auth-slice");
expect(firstCreateCall?.branch).not.toBe(secondCreateCall?.branch);
});
it("ensures shared branch groups when creating subtask breakdown tasks", async () => {
@@ -2319,6 +2337,23 @@ describe("Planning Mode Routes", () => {
expect.objectContaining({ branchName: "feature/auth-breakdown", autoMerge: false }),
);
expect(store.getBranchGroupBySource).toHaveBeenCalledWith("planning", sessionId);
const firstCreateCall = (store.createTask as ReturnType<typeof vi.fn>).mock.calls[0]?.[0];
const secondCreateCall = (store.createTask as ReturnType<typeof vi.fn>).mock.calls[1]?.[0];
expect(firstCreateCall?.branch).toBe("feature/auth-breakdown/auth-backend");
expect(secondCreateCall?.branch).toBe("feature/auth-breakdown/auth-ui");
expect(firstCreateCall?.branch).not.toBe("feature/auth-breakdown");
expect(secondCreateCall?.branch).not.toBe("feature/auth-breakdown");
expect(firstCreateCall?.branch).not.toBe(secondCreateCall?.branch);
expect(firstCreateCall?.branchContext).toMatchObject({
groupId: `planning:${sessionId}`,
source: "planning",
assignmentMode: "shared",
});
expect(secondCreateCall?.branchContext).toMatchObject({
groupId: `planning:${sessionId}`,
source: "planning",
assignmentMode: "shared",
});
});
it("prefers session autoMerge override when creating shared planning subtasks", async () => {

View File

@@ -2204,7 +2204,7 @@ describe("POST /subtasks/*", () => {
expect(createRes.status).toBe(201);
expect(store.createTask).toHaveBeenCalledWith(expect.objectContaining({
branch: "feature/planning",
branch: "feature/planning/first",
baseBranch: "main",
branchContext: {
groupId: `planning:${start.body.sessionId}`,

View File

@@ -10,7 +10,7 @@ import { ApiError, badRequest, conflict, notFound, rateLimited } from "../api-er
import { writeSSEEvent, type SessionBufferedEvent } from "../sse-buffer.js";
import type { AiSessionStore } from "../ai-session-store.js";
import type { ApiRoutesContext } from "./types.js";
import { derivePerTaskBranch, resolveBranchAssignmentContext, resolveBranchSelection } from "./branch-selection.js";
import { resolveBranchAssignmentContext, resolveBranchSelection, resolveEntryPointBranchAssignment } from "./branch-selection.js";
interface PlanningSubtaskRouteDeps {
store: TaskStore;
@@ -239,9 +239,11 @@ export function registerPlanningSubtaskRoutes(ctx: ApiRoutesContext, deps: Plann
throw badRequest("Each subtask must include tempId and title");
}
const taskBranch = branchMode === "per-task-derived"
? derivePerTaskBranch(resolvedBranch, item.title || item.tempId)
: resolvedBranch;
const { workingBranch: taskBranch } = resolveEntryPointBranchAssignment({
assignmentMode: branchMode,
resolvedBranch,
taskSegment: item.title || item.tempId,
});
const task = await scopedStore.createTask({
title: item.title.trim(),
@@ -1294,9 +1296,11 @@ export function registerPlanningSubtaskRoutes(ctx: ApiRoutesContext, deps: Plann
const tempIdToTaskId = new Map<string, string>();
for (const item of mergedSubtasks) {
const taskBranch = branchMode === "per-task-derived"
? derivePerTaskBranch(resolvedBranch, item.title || item.id)
: resolvedBranch;
const { workingBranch: taskBranch } = resolveEntryPointBranchAssignment({
assignmentMode: branchMode,
resolvedBranch,
taskSegment: item.title || item.id,
});
const task = await scopedStore.createTask({
title: item.title.trim(),