From 6efece99a4d4356907bb71e447733d800a6375d4 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Wed, 18 Nov 2026 19:00:24 +0800 Subject: [PATCH] fix(project): ask about trust before leaving the current project (#4253) Opening a folder in this window confirmed leaving the current project (which stops its running processes) before the trust prompt, so Don't Open left the original project without its processes. Trust is now asked first; the fallback open path follows the same order. Fixes #4160. --- src/features/app/__tests__/windows.test.ts | 21 +++++++++++++++++++-- src/features/app/windows.ts | 7 +++++++ src/workbench/shellActions.ts | 7 +++++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/features/app/__tests__/windows.test.ts b/src/features/app/__tests__/windows.test.ts index a7c8d1085..260777237 100644 --- a/src/features/app/__tests__/windows.test.ts +++ b/src/features/app/__tests__/windows.test.ts @@ -192,6 +192,20 @@ describe("replacing a project in this window", () => { expect(useProject.getState().project?.root).toBe("/local"); }); + it("asks about trust before leaving, so Don't Open keeps the current project running", async () => { + useProject.setState({ + ...projectState("/a"), + settings: { general: { openProjectIn: "same" } }, + } as never); + windowOpenProject.mockResolvedValue(ok({ kind: "current" })); + vi.mocked(confirmProjectTrust).mockRejectedValueOnce(new IpcError({ kind: "cancelled", message: "Cancelled" })); + await openProjectWithPolicy("/b"); + expect(confirmProjectTrust).toHaveBeenCalledWith("/b", "local"); + expect(confirmLeaveProject).not.toHaveBeenCalled(); + expect(openProject).not.toHaveBeenCalled(); + expect(notify).not.toHaveBeenCalled(); + }); + it("opens the local project when its path matches the remote root", async () => { useProject.setState({ ...projectState("/same"), @@ -792,11 +806,14 @@ describe("trust is asked before a new project window opens", () => { expect(windowOpenProject).toHaveBeenCalled(); }); - it("asks only once, from openProject, when the project opens in this window", async () => { + it("asks once this window takes the project, before leaving its current one", async () => { windowOpenProject.mockResolvedValue(ok({ kind: "current" })); await openProjectInWindow("/p/b", false); expect(windowOpenProject).toHaveBeenCalledWith("/p/b", false, []); - expect(confirmProjectTrust).not.toHaveBeenCalled(); + expect(confirmProjectTrust).toHaveBeenCalledOnce(); + expect(vi.mocked(confirmProjectTrust).mock.invocationCallOrder[0]).toBeLessThan( + vi.mocked(confirmLeaveProject).mock.invocationCallOrder[0]!, + ); expect(openProject).toHaveBeenCalledWith("/p/b"); }); }); diff --git a/src/features/app/windows.ts b/src/features/app/windows.ts index eff7843c8..7df38084d 100644 --- a/src/features/app/windows.ts +++ b/src/features/app/windows.ts @@ -57,6 +57,13 @@ async function openHere(path: string): Promise { if (!isRemoteWindow() && useProject.getState().project?.root === path) return true; // A folder of a WSL distro runs there, not as a network folder; the window then drops untitled buffers. const wsl = await commands.wslResolve(path).catch(() => null); + try { + // Asked before leaving, so Don't Open keeps the current project and its processes running. + if (!wsl) await confirmProjectTrust(path, "local"); + } catch (e) { + openFailed(path, e); + return false; + } if (!(await confirmLeaveProject(!wsl))) return false; try { if (wsl) await connectRemote(wsl.target, wsl.path); diff --git a/src/workbench/shellActions.ts b/src/workbench/shellActions.ts index 097555bd0..b2c9c9a87 100644 --- a/src/workbench/shellActions.ts +++ b/src/workbench/shellActions.ts @@ -1,6 +1,7 @@ import { showBackgroundTasks } from "./StatusBar"; import { executeAction, getAction, registerActions } from "@/platform/actions"; -import { isTauri } from "@/platform/ipc"; +import { isCancelled, isTauri } from "@/platform/ipc"; +import { confirmProjectTrust } from "@/platform/projectTrust"; import { closeProject, confirmLeaveProject, openProject, useProject } from "@/platform/project"; import { runSearchFieldCommand, showContextMenu } from "@/ui"; import { showCustomizeToolbar } from "./MainToolbarDialog"; @@ -32,10 +33,12 @@ export async function openProjectDialog() { await executeAction("file.openProjectPath", path); return; } - if (!(await confirmLeaveProject())) return; try { + await confirmProjectTrust(path, "local"); + if (!(await confirmLeaveProject())) return; await openProject(path); } catch (e) { + if (isCancelled(e)) return; notify({ level: "error", title: "Could not open project", body: e instanceof Error ? e.message : String(e) }); } }