Skip to content

Commit 55d2f11

Browse files
committed
fix(mobile): preserve explicit worktree base choices
1 parent bed31ca commit 55d2f11

7 files changed

Lines changed: 57 additions & 23 deletions

‎apps/mobile/src/features/settings/settings-scoped-server.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ describe("mobile project settings scope", () => {
8484
null,
8585
);
8686
expect(mobileSettingsAreMixed(targets, "defaultWorktreeBaseRef")).toBe(mixed);
87+
expect(uniformMobileSetting(targets, "defaultWorktreeBaseRef")).toEqual(mixed ? null : first);
8788
});
8889

8990
it("has no uniform value when no environments are selected", () => {

‎apps/mobile/src/features/settings/settings-scoped-server.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export function uniformMobileSetting<K extends keyof ServerSettings>(
114114
const reference = targets[0];
115115
if (!reference) return null;
116116
const value = reference.settings[key];
117-
return targets.every((target) => target.settings[key] === value) ? value : null;
117+
return targets.every((target) => Equal.equals(target.settings[key], value)) ? value : null;
118118
}
119119

120120
export function planMobileScopedSettingsClear(

‎apps/mobile/src/features/threads/new-task-context-presentation.test.ts‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,34 +56,37 @@ describe("resolveNewTaskLocalWorkspaceSelection", () => {
5656
});
5757

5858
describe("resolveNewTaskBranchAfterWorkspaceModeChange", () => {
59-
const localSelection = {
60-
branch: "feature/current",
61-
worktreePath: null,
62-
awaitsCurrentBranch: false,
63-
};
64-
6559
it("applies the configured base after leaving the current checkout", () => {
6660
expect(
6761
resolveNewTaskBranchAfterWorkspaceModeChange({
6862
mode: "worktree",
6963
previousMode: "local",
7064
branch: "feature/current",
71-
worktreePath: null,
72-
localSelection,
65+
branchSelection: "auto",
7366
}),
7467
).toBeNull();
7568
});
7669

77-
it("keeps a distinct branch chosen for the draft", () => {
70+
it("keeps an explicit branch choice even when it matches the checkout", () => {
71+
expect(
72+
resolveNewTaskBranchAfterWorkspaceModeChange({
73+
mode: "worktree",
74+
previousMode: "local",
75+
branch: "feature/current",
76+
branchSelection: "manual",
77+
}),
78+
).toBe("feature/current");
79+
});
80+
81+
it("keeps a legacy draft branch whose source is unknown", () => {
7882
expect(
7983
resolveNewTaskBranchAfterWorkspaceModeChange({
8084
mode: "worktree",
8185
previousMode: "local",
82-
branch: "feature/chosen",
83-
worktreePath: null,
84-
localSelection,
86+
branch: "feature/current",
87+
branchSelection: undefined,
8588
}),
86-
).toBe("feature/chosen");
89+
).toBe("feature/current");
8790
});
8891
});
8992

‎apps/mobile/src/features/threads/new-task-context-presentation.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,12 @@ export function resolveNewTaskBranchAfterWorkspaceModeChange(input: {
6363
readonly mode: WorkspaceMode;
6464
readonly previousMode: WorkspaceMode;
6565
readonly branch: string | null;
66-
readonly worktreePath: string | null;
67-
readonly localSelection: ReturnType<typeof resolveNewTaskLocalWorkspaceSelection>;
66+
readonly branchSelection: "auto" | "manual" | undefined;
6867
}): string | null {
6968
if (
7069
input.previousMode === "local" &&
7170
input.mode === "worktree" &&
72-
input.branch === input.localSelection.branch &&
73-
input.worktreePath === input.localSelection.worktreePath
71+
input.branchSelection === "auto"
7472
) {
7573
return null;
7674
}

‎apps/mobile/src/features/threads/new-task-flow-provider.tsx‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
538538
: "local";
539539
const selectedBranchName = selectedProjectDraft.workspaceSelection?.branch ?? null;
540540
const selectedWorktreePath = selectedProjectDraft.workspaceSelection?.worktreePath ?? null;
541+
const selectedBranchSelection = selectedProjectDraft.workspaceSelection?.branchSelection;
541542
const preferencesResult = useAtomValue(mobilePreferencesAtom);
542543
const preferencesLoaded = AsyncResult.isSuccess(preferencesResult);
543544
const savePreferences = useAtomSet(updateMobilePreferencesAtom);
@@ -954,10 +955,10 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
954955
mode,
955956
previousMode: workspaceMode,
956957
branch: selectedBranchName,
957-
worktreePath: selectedWorktreePath,
958-
localSelection,
958+
branchSelection: selectedBranchSelection,
959959
}),
960-
worktreePath: mode === "local" ? localSelection.worktreePath : selectedWorktreePath,
960+
worktreePath: mode === "local" ? localSelection.worktreePath : null,
961+
branchSelection: mode === "local" ? "auto" : (selectedBranchSelection ?? "manual"),
961962
...(draftStartFromOrigin !== undefined ? { startFromOrigin: draftStartFromOrigin } : {}),
962963
},
963964
});
@@ -966,9 +967,9 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
966967
availableBranches,
967968
draftStartFromOrigin,
968969
selectedBranchName,
970+
selectedBranchSelection,
969971
selectedProject,
970972
selectedProjectDraftKey,
971-
selectedWorktreePath,
972973
workspaceMode,
973974
],
974975
);
@@ -996,6 +997,7 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
996997
mode: "local",
997998
branch: localSelection.branch,
998999
worktreePath: localSelection.worktreePath,
1000+
branchSelection: "auto",
9991001
...(draftStartFromOrigin !== undefined ? { startFromOrigin: draftStartFromOrigin } : {}),
10001002
},
10011003
});
@@ -1027,6 +1029,7 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
10271029
workspaceSelection: {
10281030
mode: workspaceMode,
10291031
branch: branch.name,
1032+
branchSelection: "manual",
10301033
worktreePath: resolveNewTaskBranchWorktreePath({
10311034
workspaceMode,
10321035
projectCwd: selectedProject.workspaceRoot,
@@ -1055,11 +1058,18 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
10551058
mode: workspaceMode,
10561059
branch: selectedBranchName,
10571060
worktreePath: selectedWorktreePath,
1061+
...(selectedBranchSelection ? { branchSelection: selectedBranchSelection } : {}),
10581062
startFromOrigin: value,
10591063
},
10601064
});
10611065
},
1062-
[selectedBranchName, selectedProjectDraftKey, selectedWorktreePath, workspaceMode],
1066+
[
1067+
selectedBranchName,
1068+
selectedBranchSelection,
1069+
selectedProjectDraftKey,
1070+
selectedWorktreePath,
1071+
workspaceMode,
1072+
],
10631073
);
10641074

10651075
const refreshBranches = branchState.refresh;
@@ -1104,6 +1114,7 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
11041114
mode: "worktree",
11051115
branch: preferredBranch,
11061116
worktreePath: null,
1117+
branchSelection: "auto",
11071118
...(draftStartFromOrigin !== undefined ? { startFromOrigin: draftStartFromOrigin } : {}),
11081119
},
11091120
});

‎apps/mobile/src/state/use-composer-drafts.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,6 +1713,25 @@ describe("mobile composer drafts", () => {
17131713
},
17141714
});
17151715
});
1716+
1717+
it("retains an explicit branch choice across draft hydration", () => {
1718+
const decoded = decodePersistedComposerState({
1719+
schemaVersion: 1,
1720+
drafts: {
1721+
"new-task:environment-1:project-1": {
1722+
text: "",
1723+
attachments: [],
1724+
workspaceSelection: {
1725+
mode: "local",
1726+
branch: "main",
1727+
worktreePath: null,
1728+
branchSelection: "manual",
1729+
},
1730+
},
1731+
},
1732+
});
1733+
expect(Object.values(decoded.drafts)[0]?.workspaceSelection?.branchSelection).toBe("manual");
1734+
});
17161735
it("keeps legacy content-only drafts and rejects invalid selector state", () => {
17171736
expect(
17181737
decodePersistedComposerState({

‎apps/mobile/src/state/use-composer-drafts.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ export interface ComposerDraftWorkspaceSelection {
358358
readonly mode: "local" | "worktree";
359359
readonly branch: string | null;
360360
readonly worktreePath: string | null;
361+
readonly branchSelection?: "auto" | "manual";
361362
readonly startFromOrigin?: boolean;
362363
}
363364

@@ -370,6 +371,7 @@ const ComposerDraftWorkspaceSelectionSchema = Schema.Struct({
370371
mode: Schema.Literals(["local", "worktree"]),
371372
branch: Schema.NullOr(Schema.String),
372373
worktreePath: Schema.NullOr(Schema.String),
374+
branchSelection: Schema.optional(Schema.Literals(["auto", "manual"])),
373375
startFromOrigin: Schema.optional(Schema.Boolean),
374376
});
375377

0 commit comments

Comments
 (0)