A local-first multi-agent app development platform, built on PenguinHarness
fix(web): a refused folder removal keeps its reason in the card
lmlihengb177ece94e19
diff --git a/changelog/unreleased/2026-11-13-finder-delete-refusal.md b/changelog/unreleased/2026-11-13-finder-delete-refusal.mdnew file mode 100644index 00000000..510b33bb--- /dev/null+++ b/changelog/unreleased/2026-11-13-finder-delete-refusal.md@@ -0,0 +1,47 @@+# A refused folder removal keeps its reason inside the card that asked++- **Date:** 2026-11-13+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[中文版](2026-11-13-finder-delete-refusal.zh.md)++Removing a folder in the Workspace finder is asked in a confirmation card, and that card states the+rule the server enforces: only an empty folder can be deleted. The card closed on the answer either+way, so a refusal — a folder that has something in it, which is exactly the case the card warns+about — was reported only as a notification that dismissed itself after six seconds. The folder was+still in the list, looking untouched, and the reason it survived was gone.++The card now closes only once its delete landed. A refusal leaves it standing with the server's+words inside it, in the shared card's `refusal` slot — `操作被拒绝:<reason>` under the sentence it+answered, above the same button that sent the request. That button is the retry: a folder emptied+from outside the card can be removed by pressing it again, with no way to lose the question in+between. The reason is cleared at the start of the next attempt and when the card is closed.++## Details++- `packages/web/src/features/chat/workspace-finder.tsx`: a `deleteRefusal` state beside+ `deleteTarget`. `deleteFolder` fills it from `refusalText` on a refusal instead of closing the+ card and toasting; it is cleared when the card is opened and when an attempt starts. The card+ passes the state to `refusal` as `S.common.refused(...)` and clears it in `onClose`.+- The successful path is untouched: the card closes, the finder re-reads the folder (or stands in+ the removed folder's parent when that folder was the one being browsed), and the success toast+ still reports what went.++## Tests++- `packages/web/e2e/finder-delete-folder-refusal.spec.mjs` (new, two cases, real server + the+ repository's mock model + a real browser, folders and files under the system temp dir): a folder+ that holds a file is refused with the app's own words in the card, nothing in the notification+ region, still there after seven seconds and nothing removed on disk — then the file is deleted+ from outside the card, the same button retries and the folder goes from the list and from disk;+ and a card closed with Escape after a refusal leaves the next card clean.+- Run against the page as it was before the change (`HEAD`'s source, rebuilt), both cases fail on+ the card's missing `role="alert"`.++## Compatibility++No wire change, no new dependency, no Project config change, no new copy: the sentence is the+existing app-wide `操作被拒绝:<reason>` and the words for `dir_not_empty` were already in the+dictionary. Deleting an empty folder and every other finder action are untouched.diff --git a/changelog/unreleased/2026-11-13-finder-delete-refusal.zh.md b/changelog/unreleased/2026-11-13-finder-delete-refusal.zh.mdnew file mode 100644index 00000000..2bd73a2b--- /dev/null+++ b/changelog/unreleased/2026-11-13-finder-delete-refusal.zh.md@@ -0,0 +1,37 @@+# 文件夹删不掉时,原因留在发问的那张卡片里++- **日期:** 2026-11-13+- **类型:** 修复+- **范围:** `web`+- **破坏性变更:** 否++[English](2026-11-13-finder-delete-refusal.md)++工作区选择器里删除文件夹是先问再写的:那张卡片自己就写着服务端的规则 —— 只能删除空文件夹。可卡片以前无论答案+是什么都会关掉,于是被拒的回话(文件夹里还有东西,正是卡片警告过的那一种)只落在一条六秒后自己消失的通知里:+文件夹仍在列表里、看起来没被碰过,而它为什么留着的理由已经没了。++现在卡片只在删除落地之后才关。被拒时它留着,原因画在它里面:走共享卡片的 `refusal` 槽,`操作被拒绝:<原因>`+在被它回答的那句话下面、发出这次请求的那个按钮上面。那个按钮就是重试 —— 在卡片外把文件夹清空,再按同一个按钮+就能删掉,中途没有机会把这个问题弄丢。这句话在下次尝试开始与卡片关闭时清掉。++## 细节++- `packages/web/src/features/chat/workspace-finder.tsx`:`deleteTarget` 旁边新增 `deleteRefusal`。+ `deleteFolder` 在被拒时用 `refusalText` 填它、不再关卡片另弹通知;打开卡片时与每次尝试开始时清掉。卡片把这个+ 状态按 `S.common.refused(...)` 交给 `refusal`,并在 `onClose` 里清掉。+- 成功那条路一处未动:卡片关掉、列表重新读一遍(删掉的正是当前浏览的那个文件夹时,选择器站到它的父目录上),+ 成功通知照旧报出删掉了什么。++## 测试++- `packages/web/e2e/finder-delete-folder-refusal.spec.mjs`(新增,两条用例,真服务端 + 仓库自带的 mock 模型 ++ 真浏览器,文件夹与文件都在系统临时目录下):里面有一个文件的文件夹被拒,卡片里是应用自己的说法、通知区没有东西、+ 七秒后仍在、盘上什么都没少 —— 随后在卡片外删掉那个文件,同一个按钮重试,文件夹从列表与盘上同时消失;另一条是+ 被拒之后按 Escape 关掉卡片,下一次打开的是一张干净的卡片。+- 拿改动前的页面(`HEAD` 的源码重新构建)跑同一份用例,两条都死在卡片里找不到 `role="alert"`。++## 兼容性++线上接口没变、没有新依赖、Project 配置没变、没有新文案:那句话就是全应用既有的 `操作被拒绝:<原因>`,+`dir_not_empty` 的词条本来就在词典里。删空文件夹与选择器的其余动作一字未改。diff --git a/packages/web/e2e/finder-delete-folder-refusal.spec.mjs b/packages/web/e2e/finder-delete-folder-refusal.spec.mjsnew file mode 100644index 00000000..6dfe1e5f--- /dev/null+++ b/packages/web/e2e/finder-delete-folder-refusal.spec.mjs@@ -0,0 +1,152 @@+/**+ * Regression: a folder the server REFUSES to delete says why inside the confirmation card that+ * asked, and that card stays standing so its own button is the retry.+ *+ * Removing a folder in the Workspace finder is asked in a confirmation card, and the rule the+ * card warns about — only an empty folder can go — is exactly the answer the server gives with+ * `dir_not_empty`. The card used to close on any outcome, so a refusal left the reason in a+ * notification that dismissed itself after six seconds while the folder it was about was still+ * in the list, looking untouched. Now the card closes only once its delete landed; a refusal is+ * drawn under the card's sentence (`ConfirmModal`'s `refusal` slot), the folder is emptied from+ * outside the card, and pressing the same button again is the retry.+ *+ * The finder is walked to a directory the test made under the system temp dir (its address bar+ * takes an absolute path), so the folders and files it touches are the test's own: `busy` holds+ * a file at first (the refusal), `empty` is there to prove the list still works after one.+ */+import fs from "node:fs";+import os from "node:os";+import path from "node:path";+import { test, expect } from "@playwright/test";+import { ADMIN_ID, ADMIN_PASSWORD, login } from "./auth.mjs";++const BASE = process.env.BASE_URL;+const MOCK = process.env.MOCK_URL;++/** The sentence the card draws: the shared lead-in plus the app's own words for the code. */+const NOT_EMPTY_REFUSED = "操作被拒绝:该文件夹不是空的,只能删除空文件夹。";++/** A directory of the test's own, with `busy` (holding a file) and `empty`. */+function tempDir() {+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "e2e-finder-rm-"));+ fs.mkdirSync(path.join(dir, "busy"));+ fs.writeFileSync(path.join(dir, "busy", "kept.txt"), "still here\n");+ fs.mkdirSync(path.join(dir, "empty"));+ return dir;+}++/**+ * Sign in as the seeded administrator (the finder's delete route asks the Project's access) and+ * give the Project a model — the onboarding card covers the page without one.+ */+async function ready(page) {+ await login(page.request, ADMIN_ID, ADMIN_PASSWORD);+ const projectId = (await (await page.request.get(`${BASE}/api/projects`)).json()).projects[0]+ .projectId;+ const put = await page.request.put(`${BASE}/api/projects/${projectId}/models`, {+ data: {+ defaultModel: { provider: "custom", modelId: "claude-4-8" },+ models: [+ {+ provider: "custom",+ modelId: "claude-4-8",+ apiKey: "sk-mock",+ baseUrl: MOCK,+ contextWindow: 200000,+ },+ ],+ },+ });+ expect(put.ok(), "put models").toBeTruthy();+}++/**+ * The finder, opened the way a person opens it — the sidebar's new-workspace button — then walked+ * to `dir` through its address bar (Ctrl+L, the path, Enter). It opens at this server's home,+ * which is a folder no test may write into.+ */+async function openFinder(page, dir, ...listed) {+ await page.goto("/");+ await page.getByRole("button", { name: "新建工作区" }).click();+ const finder = page.getByRole("dialog", { name: "Workspace" });+ await expect(finder).toBeVisible();+ await expect(finder.getByRole("listbox")).toBeVisible();+ await finder.getByRole("listbox").focus();+ await page.keyboard.press("ControlOrMeta+l");+ await page.keyboard.type(dir);+ await page.keyboard.press("Enter");+ // The folder on screen is the test's own: what it lists is what the test put there.+ for (const name of listed) {+ await expect(finder.getByRole("option", { name })).toBeVisible();+ }+ return finder;+}++/** Picks a row and asks the toolbar to remove it; the card that asks is what comes back. */+async function askToRemove(page, finder, name) {+ await finder.getByRole("option", { name }).click();+ await finder.getByRole("button", { name: "删除文件夹" }).click();+ const card = page.getByRole("dialog", { name: "删除文件夹" });+ await expect(card).toBeVisible();+ return card;+}++/** The finder's delete call, which is what a folder with content in it refuses. */+const isDelete = (res) => res.request().method() === "DELETE";++test("a folder with content keeps its reason in the card, past the toast it used to be", async ({+ page,+}) => {+ const dir = tempDir();+ await ready(page);+ const finder = await openFinder(page, dir, "busy", "empty");+ const notices = page.getByRole("region", { name: "通知" });+ const card = await askToRemove(page, finder, "busy");+ await expect(card).toContainText("删除文件夹「busy」?");++ // The server's own answer: the folder still holds a file.+ const refused = page.waitForResponse(isDelete);+ await card.getByRole("button", { name: "删除" }).click();+ expect((await refused).status(), "folder with content").toBe(409);+ // The card says why, under the sentence that asked, and no notification is left standing.+ await expect(card.getByRole("alert")).toHaveText(NOT_EMPTY_REFUSED);+ await expect(card.getByRole("button", { name: "删除" })).toBeEnabled();+ await expect(notices.getByRole("button")).toHaveCount(0);++ // Six seconds is how long a toast lives; this card and its sentence have to still be there.+ await page.waitForTimeout(7_000);+ await expect(card).toBeVisible();+ await expect(card.getByRole("alert")).toHaveText(NOT_EMPTY_REFUSED);+ await expect(notices.getByRole("button")).toHaveCount(0);+ expect(fs.existsSync(path.join(dir, "busy", "kept.txt")), "nothing was removed").toBe(true);++ // Emptying the folder happens behind the card, without losing it; the same button is the retry.+ fs.rmSync(path.join(dir, "busy", "kept.txt"));+ const landed = page.waitForResponse(isDelete);+ await card.getByRole("button", { name: "删除" }).click();+ expect((await landed).status(), "empty folder").toBe(200);+ await expect(card).toHaveCount(0);+ await expect(finder.getByRole("option", { name: "busy" })).toHaveCount(0);+ await expect(finder.getByRole("option", { name: "empty" })).toBeVisible();+ expect(fs.existsSync(path.join(dir, "busy")), "the folder is gone from disk").toBe(false);+});++test("cancelling after a refusal leaves the next card clean", async ({ page }) => {+ const dir = tempDir();+ await ready(page);+ const finder = await openFinder(page, dir, "busy", "empty");+ const card = await askToRemove(page, finder, "busy");++ const refused = page.waitForResponse(isDelete);+ await card.getByRole("button", { name: "删除" }).click();+ expect((await refused).status(), "folder with content").toBe(409);+ await expect(card.getByRole("alert")).toHaveText(NOT_EMPTY_REFUSED);++ // Escape closes the card; the sentence belonged to that question, so the next one is clean.+ await page.keyboard.press("Escape");+ await expect(card).toHaveCount(0);+ await expect(finder).toBeVisible();+ const again = await askToRemove(page, finder, "busy");+ await expect(again.getByRole("alert")).toHaveCount(0);+ await expect(again).toContainText("删除文件夹「busy」?");+});diff --git a/packages/web/src/features/chat/workspace-finder.tsx b/packages/web/src/features/chat/workspace-finder.tsxindex 17e7d693..05185498 100644--- a/packages/web/src/features/chat/workspace-finder.tsx+++ b/packages/web/src/features/chat/workspace-finder.tsx@@ -277,6 +277,14 @@ export function WorkspaceFinder({*/const [deleteTarget, setDeleteTarget] = useState<string | null>(null);const [deleting, setDeleting] = useState(false);+ /**+ * Why the removal the card asked for was refused, drawn inside that same card until the next+ * attempt or until it is closed. The card's button is the retry: the refusal the server almost+ * always gives here is "not empty", and emptying the folder and pressing the same button again+ * is the whole fix — a toast would take the reason away with the card still standing (7.64's+ * rule for a refused write).+ */+ const [deleteRefusal, setDeleteRefusal] = useState<string | null>(null);/** The address bar is a path field (clicked, or ⌘⇧G) rather than breadcrumbs; the draft is what it holds. */const [addressEditing, setAddressEditing] = useState(false);const [addressDraft, setAddressDraft] = useState("");@@ -626,20 +634,24 @@ export function WorkspaceFinder({*/const askDelete = (path: string, onMachine: string | null) => {if (onMachine !== null) return;+ // A fresh question: whatever the last card was refused for was about that folder.+ setDeleteRefusal(null);setDeleteTarget(path);};/*** Removes the empty folder the card named. A folder that is not empty — the case the card- * warned about — comes back as its own refusal, shown as a toast: unlike a folder name there- * is nothing in the dialog to change, so the card closes on the reason rather than staying- * open on it. Afterwards the list is read again, since a folder that is gone must not stay on- * screen; when the folder removed was the one being browsed, the finder stands in its parent.+ * warned about — comes back as its own refusal, and the card stays open on it: the button that+ * sent it is the retry, and emptying the folder is done outside the card without losing it.+ * Afterwards the list is read again, since a folder that is gone must not stay on screen; when+ * the folder removed was the one being browsed, the finder stands in its parent.*/const deleteFolder = () => {const target = deleteTarget;if (target === null || deleting) return;setDeleting(true);+ // Any attempt makes the sentence about the last one stale, so it goes before this one can fail.+ setDeleteRefusal(null);api.deleteDir(projectId, target).then((res) => {@@ -650,10 +662,7 @@ export function WorkspaceFinder({if (parent !== null) load(parent, { record: false });else refresh();})- .catch((err: unknown) => {- setDeleteTarget(null);- toastError(apiErrorText(err));- })+ .catch((err: unknown) => setDeleteRefusal(refusalText(err))).finally(() => setDeleting(false));};@@ -1832,7 +1841,9 @@ export function WorkspaceFinder({assumed: the card names the folder, says the rule the server enforces (only an emptyfolder can go) and waits. It stacks over this dialog of its own accord — Modals areportaled to body and share one Escape stack — so one Escape closes the card and leaves- the finder where it was browsing. */}+ the finder where it was browsing. The card also keeps the server's words when it+ refuses the removal (`refusal`): "not empty" is something the user fixes in the folder+ behind the card, then presses this same button again. */}<ConfirmModalopen={deleteTarget !== null}title={f.deleteFolderTitle}@@ -1840,8 +1851,12 @@ export function WorkspaceFinder({confirmLabel={S.common.delete}cancelLabel={S.common.cancel}busy={deleting}- onClose={() => setDeleteTarget(null)}+ onClose={() => {+ setDeleteTarget(null);+ setDeleteRefusal(null);+ }}onConfirm={deleteFolder}+ {...(deleteRefusal !== null ? { refusal: S.common.refused(deleteRefusal) } : {})}><p className="break-all text-sm text-gray-600 dark:text-gray-300">{deleteTarget !== null ? f.deleteFolderConfirm(baseName(deleteTarget)) : ""}