fix(web): keep worktree default when switching a draft's machine (#4964)
Co-authored-by: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
90f3913a81
commit
f0c6ba9946
3 files changed
+20
-24
No files matched your search
@@ -1103,13 +1103,14 @@ describe("composerDraftStore project draft thread mapping", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("clears branch and worktree context when remapping a draft to another environment", () => {
|
||||
it("clears branch and worktree but keeps env mode when remapping a draft to another environment", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
store.setProjectDraftThreadId(projectRef, draftId, {
|
||||
threadId,
|
||||
branch: "feature/local-only",
|
||||
worktreePath: "/tmp/local-worktree",
|
||||
envMode: "worktree",
|
||||
startFromOrigin: true,
|
||||
});
|
||||
|
||||
store.setLogicalProjectDraftThreadId(scopedProjectKey(projectRef), remoteProjectRef, draftId, {
|
||||
@@ -1121,17 +1122,19 @@ describe("composerDraftStore project draft thread mapping", () => {
|
||||
projectId,
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
envMode: "local",
|
||||
envMode: "worktree",
|
||||
startFromOrigin: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("clears branch and worktree context when changing a draft thread project ref", () => {
|
||||
it("clears branch and worktree but keeps env mode when changing a draft thread project ref", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
store.setProjectDraftThreadId(projectRef, draftId, {
|
||||
threadId,
|
||||
branch: "feature/local-only",
|
||||
worktreePath: "/tmp/local-worktree",
|
||||
envMode: "worktree",
|
||||
startFromOrigin: true,
|
||||
});
|
||||
|
||||
store.setDraftThreadContext(draftId, {
|
||||
@@ -1143,7 +1146,8 @@ describe("composerDraftStore project draft thread mapping", () => {
|
||||
projectId,
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
envMode: "local",
|
||||
envMode: "worktree",
|
||||
startFromOrigin: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1340,6 +1340,10 @@ function createDraftThreadState(
|
||||
interactionMode?: ProviderInteractionMode;
|
||||
},
|
||||
): DraftThreadState {
|
||||
// A project change (including switching environments within a logical
|
||||
// project) invalidates machine-specific context: the branch may not exist
|
||||
// there and the worktree path certainly doesn't. The user's *intent* —
|
||||
// env mode and start-from-origin — is machine-independent and carries.
|
||||
const projectChanged =
|
||||
existingThread !== undefined &&
|
||||
(existingThread.environmentId !== projectRef.environmentId ||
|
||||
@@ -1358,9 +1362,7 @@ function createDraftThreadState(
|
||||
: (options.branch ?? null);
|
||||
const nextStartFromOrigin =
|
||||
options?.startFromOrigin === undefined
|
||||
? projectChanged
|
||||
? false
|
||||
: (existingThread?.startFromOrigin ?? false)
|
||||
? (existingThread?.startFromOrigin ?? false)
|
||||
: options.startFromOrigin;
|
||||
return {
|
||||
threadId,
|
||||
@@ -1374,12 +1376,7 @@ function createDraftThreadState(
|
||||
branch: nextBranch,
|
||||
worktreePath: nextWorktreePath,
|
||||
envMode:
|
||||
options?.envMode ??
|
||||
(nextWorktreePath
|
||||
? "worktree"
|
||||
: projectChanged
|
||||
? "local"
|
||||
: (existingThread?.envMode ?? "local")),
|
||||
options?.envMode ?? (nextWorktreePath ? "worktree" : (existingThread?.envMode ?? "local")),
|
||||
startFromOrigin: nextStartFromOrigin,
|
||||
promotedTo: null,
|
||||
};
|
||||
@@ -2343,6 +2340,9 @@ const composerDraftStore = create<ComposerDraftStoreState>()(
|
||||
) {
|
||||
return state;
|
||||
}
|
||||
// Mirrors createDraftThreadState: a project/environment change
|
||||
// drops machine-specific context (branch, worktree path) but
|
||||
// keeps the user's env mode and start-from-origin intent.
|
||||
const projectChanged =
|
||||
nextProjectRef.environmentId !== existing.environmentId ||
|
||||
nextProjectRef.projectId !== existing.projectId;
|
||||
@@ -2360,9 +2360,7 @@ const composerDraftStore = create<ComposerDraftStoreState>()(
|
||||
: (options.branch ?? null);
|
||||
const nextStartFromOrigin =
|
||||
options.startFromOrigin === undefined
|
||||
? projectChanged
|
||||
? false
|
||||
: existing.startFromOrigin
|
||||
? existing.startFromOrigin
|
||||
: options.startFromOrigin;
|
||||
const nextDraftThread: DraftThreadState = {
|
||||
threadId: existing.threadId,
|
||||
@@ -2378,12 +2376,7 @@ const composerDraftStore = create<ComposerDraftStoreState>()(
|
||||
branch: nextBranch,
|
||||
worktreePath: nextWorktreePath,
|
||||
envMode:
|
||||
options.envMode ??
|
||||
(nextWorktreePath
|
||||
? "worktree"
|
||||
: projectChanged
|
||||
? "local"
|
||||
: (existing.envMode ?? "local")),
|
||||
options.envMode ?? (nextWorktreePath ? "worktree" : (existing.envMode ?? "local")),
|
||||
startFromOrigin: nextStartFromOrigin,
|
||||
promotedTo: existing.promotedTo ?? null,
|
||||
};
|
||||
|
||||
@@ -183,8 +183,7 @@ export function useNewThreadHandler() {
|
||||
// The workspace context must also ride along here: when projectRef
|
||||
// targets a different physical member of the logical project,
|
||||
// createDraftThreadState treats the remap as a project change and
|
||||
// would otherwise wipe branch/worktree and force "local" mode,
|
||||
// undoing the write above.
|
||||
// would otherwise wipe branch/worktree, undoing the write above.
|
||||
setLogicalProjectDraftThreadId(
|
||||
logicalProjectKey,
|
||||
projectRef,
|
||||
|
||||
Reference in new issue
Block a user