Preserve draft branch/worktree when update options are undefined
- Keep existing `branch` and `worktreePath` values when `setProjectDraftThreadId` receives `undefined` - Add a regression test covering the undefined-update case
This commit is contained in:
1 parent
bd43372053
commit
39fd14b73e
2 files changed
+24
-6
No files matched your search
@@ -275,6 +275,24 @@ describe("composerDraftStore project draft thread mapping", () => {
|
||||
worktreePath: "/tmp/feature-next",
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves existing branch and worktree when setProjectDraftThreadId receives undefined", () => {
|
||||
const store = useComposerDraftStore.getState();
|
||||
store.setProjectDraftThreadId(projectId, threadId, {
|
||||
branch: "main",
|
||||
worktreePath: "/tmp/main-worktree",
|
||||
});
|
||||
store.setProjectDraftThreadId(projectId, threadId, {
|
||||
branch: undefined,
|
||||
worktreePath: undefined,
|
||||
});
|
||||
|
||||
expect(useComposerDraftStore.getState().getDraftThread(threadId)).toMatchObject({
|
||||
projectId,
|
||||
branch: "main",
|
||||
worktreePath: "/tmp/main-worktree",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("composerDraftStore setModel", () => {
|
||||
|
||||
@@ -460,13 +460,13 @@ export const useComposerDraftStore = create<ComposerDraftStoreState>()(
|
||||
projectId,
|
||||
createdAt: options?.createdAt ?? existingThread?.createdAt ?? new Date().toISOString(),
|
||||
branch:
|
||||
options && "branch" in options
|
||||
? (options.branch ?? null)
|
||||
: (existingThread?.branch ?? null),
|
||||
options?.branch === undefined
|
||||
? (existingThread?.branch ?? null)
|
||||
: (options.branch ?? null),
|
||||
worktreePath:
|
||||
options && "worktreePath" in options
|
||||
? (options.worktreePath ?? null)
|
||||
: (existingThread?.worktreePath ?? null),
|
||||
options?.worktreePath === undefined
|
||||
? (existingThread?.worktreePath ?? null)
|
||||
: (options.worktreePath ?? null),
|
||||
};
|
||||
const hasSameProjectMapping = previousThreadIdForProject === threadId;
|
||||
const hasSameDraftThread =
|
||||
|
||||
Reference in new issue
Block a user