Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions apps/web/src/composerDraftStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1458,17 +1458,18 @@ describe("composerDraftStore project draft thread mapping", () => {
expect(draftFor(threadId, TEST_ENVIRONMENT_ID)?.prompt).toBe("keep me");
});

it("finalizes a promoted draft after the canonical thread route is active", () => {
it("moves composer edits made during promotion to the canonical thread", () => {
const store = useComposerDraftStore.getState();
store.setProjectDraftThreadId(projectRef, draftId, { threadId });
store.setPrompt(draftId, "promote me");
markPromotedDraftThread(threadId);
store.setPrompt(draftId, "typed during setup");

finalizePromotedDraftThreadByRef(scopeThreadRef(TEST_ENVIRONMENT_ID, threadId));

expect(useComposerDraftStore.getState().getDraftThreadByProjectRef(projectRef)).toBeNull();
expect(useComposerDraftStore.getState().getDraftThread(draftId)).toBeNull();
expect(draftByKey(draftId)).toBeUndefined();
expect(draftFor(threadId, TEST_ENVIRONMENT_ID)?.prompt).toBe("typed during setup");
});

it("finalizes a matching materialized draft even when promotion was not pre-marked", () => {
Expand All @@ -1481,6 +1482,7 @@ describe("composerDraftStore project draft thread mapping", () => {
expect(useComposerDraftStore.getState().getDraftThreadByProjectRef(projectRef)).toBeNull();
expect(useComposerDraftStore.getState().getDraftThread(draftId)).toBeNull();
expect(draftByKey(draftId)).toBeUndefined();
expect(draftFor(threadId, TEST_ENVIRONMENT_ID)?.prompt).toBe("promote me");
});

it("updates branch context on an existing draft thread", () => {
Expand Down
11 changes: 8 additions & 3 deletions apps/web/src/composerDraftStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1583,6 +1583,7 @@ function removeDraftThreadReferences(
| "logicalProjectDraftThreadKeyByLogicalProjectKey"
>,
threadKey: string,
composerDestination?: ScopedThreadRef,
): Pick<
ComposerDraftStoreState,
| "draftThreadsByThreadKey"
Expand All @@ -1597,7 +1598,11 @@ function removeDraftThreadReferences(
const { [threadKey]: _removedDraftThread, ...restDraftThreadsByThreadKey } =
state.draftThreadsByThreadKey;
const { [threadKey]: removedComposerDraft, ...restDraftsByThreadKey } = state.draftsByThreadKey;
revokeDraftThreadPreviewUrls(removedComposerDraft);
if (composerDestination && removedComposerDraft) {
restDraftsByThreadKey[composerTargetKey(composerDestination)] = removedComposerDraft;
} else {
revokeDraftThreadPreviewUrls(removedComposerDraft);
}
return {
draftsByThreadKey: restDraftsByThreadKey,
draftThreadsByThreadKey: restDraftThreadsByThreadKey,
Expand Down Expand Up @@ -2785,10 +2790,10 @@ const composerDraftStore = create<ComposerDraftStoreState>()(
}
set((state) => {
const existing = state.draftThreadsByThreadKey[threadKey];
if (!isDraftThreadPromoting(existing)) {
if (!existing || !isDraftThreadPromoting(existing)) {
return state;
}
return removeDraftThreadReferences(state, threadKey);
return removeDraftThreadReferences(state, threadKey, existing.promotedTo ?? undefined);
});
},
clearDraftThread: (threadRef) => {
Expand Down
Loading