fix(app): remember submitted workspace choice (#44620)

Co-authored-by: Brendonovich <Brendonovich@users.noreply.github.com>
This commit is contained in:
opencode-agent[bot] 2026-08-24 07:12:46 +00:00 committed by GitHub
parent 46d1f1fed1
commit 5cd40ad66f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 12 deletions

View file

@ -18,13 +18,23 @@ describe("new session workspace selection", () => {
).toBe("main")
})
test("derives an existing worktree from the current directory", () => {
test("uses the saved destination instead of the current worktree", () => {
expect(
resolveNewSessionWorktree({ enabled: true, directory: "/project/feature", projectWorktree: "/project" }),
).toBe("/project/feature")
expect(resolveNewSessionWorktree({ enabled: true, directory: "/project", projectWorktree: "/project" })).toBe(
"main",
)
resolveNewSessionWorktree({
enabled: true,
directory: "/project/feature",
projectWorktree: "/project",
fallback: "create",
}),
).toBe("create")
expect(
resolveNewSessionWorktree({
enabled: true,
directory: "/project/feature",
projectWorktree: "/project",
fallback: "main",
}),
).toBe("/project")
})
test("normalizes main to the project root outside the main worktree", () => {
@ -33,9 +43,9 @@ describe("new session workspace selection", () => {
})
test("treats equivalent Windows roots as the main worktree", () => {
expect(resolveNewSessionWorktree({ enabled: true, directory: "C:\\Repo\\", projectWorktree: "c:/repo" })).toBe(
"main",
)
expect(
resolveNewSessionWorktree({ enabled: true, directory: "C:\\Repo\\", projectWorktree: "c:/repo" }),
).toBe("main")
expect(normalizeNewSessionWorktree("main", "C:\\Repo\\", "c:/repo")).toBe("main")
})

View file

@ -21,8 +21,7 @@ export function resolveNewSessionWorktree(input: {
}) {
if (!input.enabled) return "main"
if (input.selected) return input.selected
if (input.projectWorktree && !sameDirectory(input.directory, input.projectWorktree)) return input.directory
return input.fallback ?? "main"
return normalizeNewSessionWorktree(input.fallback ?? "main", input.directory, input.projectWorktree)
}
export function normalizeNewSessionWorktree(value: string, directory: string, projectWorktree?: string) {
@ -121,7 +120,6 @@ export function createNewSessionWorkspaceController(input: {
remember,
set: (worktree: string) => {
input.setSelected(normalizeNewSessionWorktree(worktree, sdk().directory, currentProject()?.worktree))
remember(worktree)
},
},
project: {