Skip to content
Open
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
28 changes: 25 additions & 3 deletions apps/web/src/components/Sidebar.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ describe("resolveSidebarNewThreadEnvMode", () => {
});

describe("resolveSidebarNewThreadSeedContext", () => {
it("prefers the default worktree mode over active thread context", () => {
it("preserves active draft context over the default worktree mode", () => {
expect(
resolveSidebarNewThreadSeedContext({
projectId: "project-1",
Expand All @@ -281,15 +281,18 @@ describe("resolveSidebarNewThreadSeedContext", () => {
},
}),
).toEqual({
branch: "feature/draft",
worktreePath: "/repo/.t3/worktrees/draft",
envMode: "worktree",
startFromOrigin: true,
});
});

it("inherits the active server thread context when creating a new thread in the same project", () => {
it("preserves the active branch over the default worktree mode", () => {
expect(
resolveSidebarNewThreadSeedContext({
projectId: "project-1",
defaultEnvMode: "local",
defaultEnvMode: "worktree",
activeThread: {
projectId: "project-1",
branch: "effect-atom",
Expand All @@ -304,6 +307,25 @@ describe("resolveSidebarNewThreadSeedContext", () => {
});
});

it("preserves the active worktree over the default worktree mode", () => {
expect(
resolveSidebarNewThreadSeedContext({
projectId: "project-1",
defaultEnvMode: "worktree",
activeThread: {
projectId: "project-1",
branch: "feature/existing",
worktreePath: "/repo/.t3/worktrees/existing",
},
activeDraftThread: null,
}),
).toEqual({
branch: "feature/existing",
worktreePath: "/repo/.t3/worktrees/existing",
envMode: "worktree",
});
});

it("prefers the active draft thread context when it matches the target project", () => {
expect(
resolveSidebarNewThreadSeedContext({
Expand Down
6 changes: 0 additions & 6 deletions apps/web/src/components/Sidebar.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,6 @@ export function resolveSidebarNewThreadSeedContext(input: {
envMode: SidebarNewThreadEnvMode;
startFromOrigin?: boolean;
} {
if (input.defaultEnvMode === "worktree") {
return {
envMode: "worktree",
};
}

if (input.activeDraftThread?.projectId === input.projectId) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Scope inherited checkout context by environment

When the target environment's default mode is worktree, this new precedence now accepts an active draft/thread based only on projectId; the sidebar caller also filters with currentActiveDraftThread.projectId === member.id / currentActiveThread.projectId === member.id and does not compare member.environmentId. Project ids are only unique within an environment in this codebase, so with two environments containing the same project id, clicking the other environment's project can seed its draft with a branch/worktree path from the currently viewed environment. That path is persisted into the created thread and later used as the provider cwd via resolveThreadWorkspaceCwd, so the turn can fail or run against the wrong checkout instead of falling back to the target environment's new-worktree default.

Useful? React with 👍 / 👎.

return {
branch: input.activeDraftThread.branch,
Expand Down
Loading