Fix new-thread draft reuse for worktree defaults (#2003)
This commit is contained in:
1 parent
569fea87a9
commit
5f7ec73a22
5 files changed
+128
-2
No files matched your search
@@ -3581,6 +3581,98 @@ describe("ChatView timeline estimator parity (full app)", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("creates a fresh worktree draft from an existing worktree thread when the default mode is worktree", async () => {
|
||||
const mounted = await mountChatView({
|
||||
viewport: DEFAULT_VIEWPORT,
|
||||
snapshot: {
|
||||
...createSnapshotForTargetUser({
|
||||
targetMessageId: "msg-user-new-thread-worktree-default-test" as MessageId,
|
||||
targetText: "new thread worktree default test",
|
||||
}),
|
||||
threads: createSnapshotForTargetUser({
|
||||
targetMessageId: "msg-user-new-thread-worktree-default-test" as MessageId,
|
||||
targetText: "new thread worktree default test",
|
||||
}).threads.map((thread) =>
|
||||
thread.id === THREAD_ID
|
||||
? Object.assign({}, thread, {
|
||||
branch: "feature/existing",
|
||||
worktreePath: "/repo/.t3/worktrees/existing",
|
||||
})
|
||||
: thread,
|
||||
),
|
||||
},
|
||||
configureFixture: (nextFixture) => {
|
||||
nextFixture.serverConfig = {
|
||||
...nextFixture.serverConfig,
|
||||
settings: {
|
||||
...nextFixture.serverConfig.settings,
|
||||
defaultThreadEnvMode: "worktree",
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
try {
|
||||
const newThreadButton = page.getByTestId("new-thread-button");
|
||||
await expect.element(newThreadButton).toBeInTheDocument();
|
||||
|
||||
await newThreadButton.click();
|
||||
|
||||
const newThreadPath = await waitForURL(
|
||||
mounted.router,
|
||||
(path) => UUID_ROUTE_RE.test(path),
|
||||
"Route should change to a new draft thread.",
|
||||
);
|
||||
const newDraftId = draftIdFromPath(newThreadPath);
|
||||
|
||||
expect(useComposerDraftStore.getState().getDraftSession(newDraftId)).toMatchObject({
|
||||
envMode: "worktree",
|
||||
worktreePath: null,
|
||||
});
|
||||
} finally {
|
||||
await mounted.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
it("creates a new draft instead of reusing a promoting draft thread", async () => {
|
||||
const mounted = await mountChatView({
|
||||
viewport: DEFAULT_VIEWPORT,
|
||||
snapshot: createSnapshotForTargetUser({
|
||||
targetMessageId: "msg-user-promoting-draft-new-thread-test" as MessageId,
|
||||
targetText: "promoting draft new thread test",
|
||||
}),
|
||||
});
|
||||
|
||||
try {
|
||||
const newThreadButton = page.getByTestId("new-thread-button");
|
||||
await expect.element(newThreadButton).toBeInTheDocument();
|
||||
|
||||
await newThreadButton.click();
|
||||
|
||||
const firstDraftPath = await waitForURL(
|
||||
mounted.router,
|
||||
(path) => UUID_ROUTE_RE.test(path),
|
||||
"Route should change to the first draft thread.",
|
||||
);
|
||||
const firstDraftId = draftIdFromPath(firstDraftPath);
|
||||
const firstThreadId = draftThreadIdFor(firstDraftId);
|
||||
|
||||
await materializePromotedDraftThreadViaDomainEvent(firstThreadId);
|
||||
expect(mounted.router.state.location.pathname).toBe(firstDraftPath);
|
||||
|
||||
await newThreadButton.click();
|
||||
|
||||
const secondDraftPath = await waitForURL(
|
||||
mounted.router,
|
||||
(path) => UUID_ROUTE_RE.test(path) && path !== firstDraftPath,
|
||||
"Route should change to a second draft thread instead of reusing the promoting draft.",
|
||||
);
|
||||
expect(draftIdFromPath(secondDraftPath)).not.toBe(firstDraftId);
|
||||
} finally {
|
||||
await mounted.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
it("snapshots sticky codex settings into a new draft thread", async () => {
|
||||
useComposerDraftStore.setState({
|
||||
stickyModelSelectionByProvider: {
|
||||
|
||||
@@ -184,6 +184,28 @@ describe("resolveSidebarNewThreadEnvMode", () => {
|
||||
});
|
||||
|
||||
describe("resolveSidebarNewThreadSeedContext", () => {
|
||||
it("prefers the default worktree mode over active thread context", () => {
|
||||
expect(
|
||||
resolveSidebarNewThreadSeedContext({
|
||||
projectId: "project-1",
|
||||
defaultEnvMode: "worktree",
|
||||
activeThread: {
|
||||
projectId: "project-1",
|
||||
branch: "feature/existing",
|
||||
worktreePath: "/repo/.t3/worktrees/existing",
|
||||
},
|
||||
activeDraftThread: {
|
||||
projectId: "project-1",
|
||||
branch: "feature/draft",
|
||||
worktreePath: "/repo/.t3/worktrees/draft",
|
||||
envMode: "worktree",
|
||||
},
|
||||
}),
|
||||
).toEqual({
|
||||
envMode: "worktree",
|
||||
});
|
||||
});
|
||||
|
||||
it("inherits the active server thread context when creating a new thread in the same project", () => {
|
||||
expect(
|
||||
resolveSidebarNewThreadSeedContext({
|
||||
|
||||
@@ -186,6 +186,12 @@ export function resolveSidebarNewThreadSeedContext(input: {
|
||||
worktreePath?: string | null;
|
||||
envMode: SidebarNewThreadEnvMode;
|
||||
} {
|
||||
if (input.defaultEnvMode === "worktree") {
|
||||
return {
|
||||
envMode: "worktree",
|
||||
};
|
||||
}
|
||||
|
||||
if (input.activeDraftThread?.projectId === input.projectId) {
|
||||
return {
|
||||
branch: input.activeDraftThread.branch,
|
||||
|
||||
@@ -1881,13 +1881,18 @@ const composerDraftStore = create<ComposerDraftStoreState>()(
|
||||
[draftId]: nextDraftThread,
|
||||
};
|
||||
let nextDraftsByThreadKey = state.draftsByThreadKey;
|
||||
const previousDraftThread =
|
||||
previousThreadKeyForLogicalProject === undefined
|
||||
? undefined
|
||||
: nextDraftThreadsByThreadKey[previousThreadKeyForLogicalProject];
|
||||
if (
|
||||
previousThreadKeyForLogicalProject &&
|
||||
previousThreadKeyForLogicalProject !== draftId &&
|
||||
!isComposerThreadKeyInUse(
|
||||
nextLogicalProjectDraftThreadKeyByLogicalProjectKey,
|
||||
previousThreadKeyForLogicalProject,
|
||||
)
|
||||
) &&
|
||||
!isDraftThreadPromoting(previousDraftThread)
|
||||
) {
|
||||
delete nextDraftThreadsByThreadKey[previousThreadKeyForLogicalProject];
|
||||
if (state.draftsByThreadKey[previousThreadKeyForLogicalProject] !== undefined) {
|
||||
|
||||
@@ -87,7 +87,8 @@ function useNewThreadState() {
|
||||
if (
|
||||
latestActiveDraftThread &&
|
||||
currentRouteTarget?.kind === "draft" &&
|
||||
latestActiveDraftThread.logicalProjectKey === logicalProjectKey
|
||||
latestActiveDraftThread.logicalProjectKey === logicalProjectKey &&
|
||||
latestActiveDraftThread.promotedTo == null
|
||||
) {
|
||||
if (hasBranchOption || hasWorktreePathOption || hasEnvModeOption) {
|
||||
setDraftThreadContext(currentRouteTarget.draftId, {
|
||||
|
||||
Reference in new issue
Block a user