authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-03-01 19:16:26-08:00
committergravatar for jmarminge@gmail.comJulius Marminge <jmarminge@gmail.com> 2026-03-01 22:36:35-08:00
log005e13089a4a8f44cb25452cb4b8d9b18184a1b7
tree1d6ce8720a00f255ab05b2ac4008ed33cd2fcc89
parentd9cce6402ae875b24d9ddbe73866eee94ec16ddb

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

2 files changed, 24 insertions(+), 6 deletions(-)

apps/web/src/composerDraftStore.test.ts+18
......@@ -275,6 +275,24 @@ describe("composerDraftStore project draft thread mapping", () => {
275275 worktreePath: "/tmp/feature-next",
276276 });
277277 });
278
279 it("preserves existing branch and worktree when setProjectDraftThreadId receives undefined", () => {
280 const store = useComposerDraftStore.getState();
281 store.setProjectDraftThreadId(projectId, threadId, {
282 branch: "main",
283 worktreePath: "/tmp/main-worktree",
284 });
285 store.setProjectDraftThreadId(projectId, threadId, {
286 branch: undefined,
287 worktreePath: undefined,
288 });
289
290 expect(useComposerDraftStore.getState().getDraftThread(threadId)).toMatchObject({
291 projectId,
292 branch: "main",
293 worktreePath: "/tmp/main-worktree",
294 });
295 });
278296});
279297
280298describe("composerDraftStore setModel", () => {
apps/web/src/composerDraftStore.ts+6-6
......@@ -460,13 +460,13 @@ export const useComposerDraftStore = create<ComposerDraftStoreState>()(
460460 projectId,
461461 createdAt: options?.createdAt ?? existingThread?.createdAt ?? new Date().toISOString(),
462462 branch:
463 options && "branch" in options
464 ? (options.branch ?? null)
465 : (existingThread?.branch ?? null),
463 options?.branch === undefined
464 ? (existingThread?.branch ?? null)
465 : (options.branch ?? null),
466466 worktreePath:
467 options && "worktreePath" in options
468 ? (options.worktreePath ?? null)
469 : (existingThread?.worktreePath ?? null),
467 options?.worktreePath === undefined
468 ? (existingThread?.worktreePath ?? null)
469 : (options.worktreePath ?? null),
470470 };
471471 const hasSameProjectMapping = previousThreadIdForProject === threadId;
472472 const hasSameDraftThread =