Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

fix(web): 项目设置的删除项目被拒时,框留着、原因也留在框里

lmliheng0267e0fe32cd
diff --git a/changelog/unreleased/2026-10-23-project-delete-refusal.md b/changelog/unreleased/2026-10-23-project-delete-refusal.md
new file mode 100644
index 00000000..093a95a8
--- /dev/null
+++ b/changelog/unreleased/2026-10-23-project-delete-refusal.md
@@ -0,0 +1,40 @@
+# Project settings: a refused delete keeps its question — and the reason — instead of toasting
+
+- **Date:** 2026-10-23
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[中文](2026-10-23-project-delete-refusal.zh.md)
+
+Deleting a Project from Project settings asks first. A refusal used to arrive as a toast only: the
+card did stay open (nothing had been deleted, and the Project was still on the server), but the
+reason landed in a notification that dismissed itself after six seconds and sat above the card,
+outside it. After those six seconds the user was left looking at the same question, with no
+reason on screen for why the delete had not happened.
+
+Now the card closes only once the delete landed. A refusal leaves it open with the server's words
+drawn under its sentence (`ConfirmModal`'s `refusal` slot, same "Refused:" lead-in as the other
+cards in the app), so the retry is the same button; opening the card again drops the previous
+reason, which belonged to the attempt it named.
+
+## Details
+
+- `components/layout/project-dialogs.tsx` (`GeneralSection`): `doDelete` no longer toasts and
+ returns — it hands the failure to `deleteRefusal`, which the confirmation renders through
+ `S.common.refused`. `setConfirmDelete(false)` moved to after the write landed, and a `deleteBusy`
+ guard keeps a double click from sending a second DELETE (the second one would have earned a 404
+ toast over a card that was already closing).
+- The delete row's button clears `deleteRefusal` as it opens the card.
+- New browser test `e2e/project-delete-refusal.spec.mjs` (two): a delete refused with `page.route`
+ 500 keeps the card, its sentence and the Project (nothing to dismiss in the notification region),
+ and reopening shows no stale reason; the retry after the refusal writes it — card gone, settings
+ dialog gone with it, Project gone from the server and from the switcher. The probe Project is
+ created through the API because the delete row is hidden for `default_project` and for an
+ account's last Project.
+
+## Compatibility
+
+- No interface, wire-format, stored-data or dependency change: only *when* the card closes, *where*
+ the reason is drawn, and that a second click while the delete is in flight is ignored. No new
+ copy beyond the existing `S.common.refused` lead-in.
diff --git a/changelog/unreleased/2026-10-23-project-delete-refusal.zh.md b/changelog/unreleased/2026-10-23-project-delete-refusal.zh.md
new file mode 100644
index 00000000..0dfb587c
--- /dev/null
+++ b/changelog/unreleased/2026-10-23-project-delete-refusal.zh.md
@@ -0,0 +1,32 @@
+# 项目设置的删除项目确认框:被拒时框留着,原因也留在框里
+
+- **Date:** 2026-10-23
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[English](2026-10-23-project-delete-refusal.md)
+
+项目设置 › 通用里的「删除项目」先问一句。被拒的时候,那张框确实还开着(什么都没删掉,项目在服务端也还在),
+但原因只落在一条六秒后自己消失、而且浮在框外面顶部的通知里 —— 六秒之后,用户面对的仍是同一个问题,屏幕上却
+没有任何一句说明它为什么没删成。
+
+现在这张框只在**删除真的落地之后**才关。被拒时框留着,服务端的原话画在它自己那句话下面(`ConfirmModal` 的
+`refusal` 槽,用的是应用既有的「操作被拒绝:」前缀),重试就是同一个按钮;重新打开这张框会先清掉上一次的原因,
+那句话属于上次尝试点名的那个项目。
+
+## 细节
+
+- `components/layout/project-dialogs.tsx`(`GeneralSection`):`doDelete` 不再把失败弹成 toast 就返回,
+ 而是交给 `deleteRefusal`,由确认框用 `S.common.refused` 画出来;`setConfirmDelete(false)` 挪到写入落地
+ 之后,另加一个 `deleteBusy` 挡住连点两下(第二下会换回一个 404,落在正在关的框上方的通知里)。
+- 删除那一行的按钮在打开框时清掉 `deleteRefusal`。
+- 新增浏览器用例 `e2e/project-delete-refusal.spec.mjs`(两条):用 `page.route` 把删除拒成 500 之后,
+ 框、框里那句话与项目都还在(通知区没有可点的按钮),重新打开不带旧原因;放行重试那次才关框 —— 框没了、
+ 设置对话框跟着没了,项目在服务端与切换器里都没了。探针项目由接口创建,因为删除那一行对 `default_project`
+ 与账号最后一个项目是藏起来的。
+
+## 兼容性
+
+- 没有接口、传输格式、已存数据或依赖变化:只改了「框什么时候关」「原因画在哪」,以及删除在途时第二下点击被
+ 忽略。除既有的 `S.common.refused` 前缀外没有新文案。
diff --git a/packages/web/e2e/project-delete-refusal.spec.mjs b/packages/web/e2e/project-delete-refusal.spec.mjs
new file mode 100644
index 00000000..5f192992
--- /dev/null
+++ b/packages/web/e2e/project-delete-refusal.spec.mjs
@@ -0,0 +1,185 @@
+/**
+ * Regression: deleting a Project from its settings dialog asks first, and a refused delete
+ * keeps that question — with the server's words inside it — instead of leaving only a toast.
+ *
+ * The delete used to close on the way out of the request's `catch`: the Project was still
+ * there (nothing was deleted), but the reason arrived as a toast that dismissed itself after
+ * six seconds and sat over the card rather than in it. The card now closes only once the
+ * delete landed; a refusal leaves it open with the refusal drawn under its sentence
+ * (`ConfirmModal`'s `refusal` slot), so the retry is the same button.
+ *
+ * Both tests work on a Project created through the API: the delete row is hidden for
+ * `default_project` and for an account's last Project, so the probe account needs a second
+ * one. The seed tolerates a leftover probe Project from an earlier run of this same file.
+ */
+import { test, expect } from "@playwright/test";
+import { provisionAndLogin } from "./auth.mjs";
+
+const BASE = process.env.BASE_URL;
+const MOCK = process.env.MOCK_URL;
+const P = "password123";
+const PROJ = "删除探针";
+
+/** The delete call the page makes; a 500 with its own words proves the reason came back. */
+const REFUSAL = { code: "project_store_locked", message: "project store is locked" };
+
+/**
+ * Provision the user, make sure a second Project exists (so the delete row is offered) with
+ * model credentials on both (otherwise the onboarding overlay covers the page), and land on
+ * that Project with its settings dialog open.
+ *
+ * Returns the probe Project's id and a reader for the Projects the server holds.
+ */
+async function openSettingsOnProbe(page, user) {
+ await provisionAndLogin(page.request, user, P);
+ const projects = (await (await page.request.get(`${BASE}/api/projects`)).json()).projects;
+ const initial = projects[0];
+ const projectId = `${user}-probe`;
+ if (!projects.some((p) => p.projectId === projectId)) {
+ const created = await page.request.post(`${BASE}/api/projects`, {
+ data: { projectId, name: PROJ },
+ });
+ expect(created.status(), "create probe project").toBe(201);
+ }
+ for (const id of [initial.projectId, projectId]) {
+ const put = await page.request.put(`${BASE}/api/projects/${id}/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 ${id}`).toBeTruthy();
+ }
+
+ await page.goto("/");
+ // Wait for the initial Project's sidebar to settle before touching the switcher: it is
+ // fetching the Agent list, and a re-render midway would close the dropdown.
+ const draftTitle = page.getByRole("heading", { name: "Adelie" });
+ await expect(page.getByText("General Agent").first()).toBeVisible();
+ await expect(draftTitle).toBeVisible();
+
+ // Switch to the probe Project through the switcher (its own id, so the normal switch path).
+ await page.getByRole("button", { name: user }).first().click();
+ await page.getByRole("button", { name: PROJ }).first().click();
+ await expect(draftTitle).toBeVisible();
+
+ // Then its settings: the switcher's trigger now shows the probe Project's name, and the
+ // gear row behind it opens the dialog on the General tab. The switcher's rows are plain
+ // buttons, not `role="menu"` items (they are named like its trigger), so the gear row is
+ // reached as a button too.
+ await page.getByRole("button", { name: PROJ }).first().click();
+ await page.getByRole("button", { name: "项目设置", exact: true }).click();
+ const settings = page.getByRole("dialog", { name: "项目设置" });
+ await expect(settings).toBeVisible();
+
+ const listed = async () =>
+ (await (await page.request.get(`${BASE}/api/projects`)).json()).projects;
+ return { projectId, settings, listed };
+}
+
+/** The delete row's button → the confirmation card (a second dialog, stacked above settings). */
+async function openDeleteCard(settings) {
+ await settings.getByRole("button", { name: "删除", exact: true }).click();
+ const card = settings.page().getByRole("dialog", { name: "删除项目" });
+ await expect(card).toBeVisible();
+ return card;
+}
+
+/** Refuse every Delete of the probe Project with a code the app has no local copy for. */
+async function refuseDelete(page, projectId, seen) {
+ await page.route(`**/api/projects/${projectId}`, async (route) => {
+ if (route.request().method() !== "DELETE") return route.fallback();
+ seen.push(route.request().url());
+ await route.fulfill({
+ status: 500,
+ contentType: "application/json",
+ body: JSON.stringify({ error: REFUSAL }),
+ });
+ });
+}
+
+/**
+ * The card's own text with the refusal line dropped: a refused write adds one line under the
+ * sentence ("操作被拒绝:…"), and that line is the only thing the refusal may change.
+ */
+async function cardText(card) {
+ return (await card.innerText()).replace(/\n操作被拒绝:[^\n]*/, "");
+}
+
+test("a refused delete keeps the card, its sentence and the Project", async ({ page }) => {
+ const { projectId, settings, listed } = await openSettingsOnProbe(page, "r119del1");
+ const before = await listed();
+
+ const card = await openDeleteCard(settings);
+ const sentence = await card.innerText();
+ expect(sentence).toContain("确认删除该项目");
+
+ const deletes = [];
+ await refuseDelete(page, projectId, deletes);
+ await card.getByRole("button", { name: "确认" }).click();
+
+ // The reason is in the card that asked, and it is not a toast: the notification region
+ // holds no dismissible button, and the card reads exactly as before plus the one line.
+ await expect(card.getByText(REFUSAL.message)).toBeVisible();
+ await expect(page.getByRole("region", { name: "通知" }).getByRole("button")).toHaveCount(0);
+ expect(deletes).toHaveLength(1);
+ await expect(card).toBeVisible();
+ expect(await cardText(card)).toBe(sentence);
+
+ // Nothing was deleted: the Project is still on the server, and the settings dialog behind
+ // the card still describes it.
+ expect((await listed()).some((p) => p.projectId === projectId)).toBe(true);
+ expect((await listed()).length).toBe(before.length);
+ await expect(settings).toBeVisible();
+
+ // Closing the card decides nothing, and reopening it does not carry the old reason.
+ await card.getByRole("button", { name: "取消" }).click();
+ await expect(card).toHaveCount(0);
+ const again = await openDeleteCard(settings);
+ await expect(again.getByText(REFUSAL.message)).toHaveCount(0);
+ expect(await again.innerText()).toBe(sentence);
+});
+
+test("the retry after a refused delete writes it, and only a written one closes the card", async ({
+ page,
+}) => {
+ const { projectId, settings, listed } = await openSettingsOnProbe(page, "r119del2");
+
+ const deletes = [];
+ let refuse = true;
+ await page.route(`**/api/projects/${projectId}`, async (route) => {
+ if (route.request().method() !== "DELETE") return route.fallback();
+ deletes.push(route.request().url());
+ if (!refuse) return route.fallback();
+ await route.fulfill({
+ status: 500,
+ contentType: "application/json",
+ body: JSON.stringify({ error: REFUSAL }),
+ });
+ });
+
+ const card = await openDeleteCard(settings);
+ await card.getByRole("button", { name: "确认" }).click();
+ await expect(card.getByText(REFUSAL.message)).toBeVisible();
+ await expect(card).toBeVisible();
+ expect(deletes).toHaveLength(1);
+ expect((await listed()).some((p) => p.projectId === projectId)).toBe(true);
+
+ // The retry is the same card, and this time the write lands: card gone, settings dialog
+ // gone with it, Project gone from the server and from the switcher.
+ refuse = false;
+ await card.getByRole("button", { name: "确认" }).click();
+ await expect(card).toHaveCount(0);
+ expect(deletes).toHaveLength(2);
+ await expect(settings).toHaveCount(0);
+ expect((await listed()).some((p) => p.projectId === projectId)).toBe(false);
+ await expect(page.getByRole("button", { name: PROJ })).toHaveCount(0);
+});
diff --git a/packages/web/src/components/layout/project-dialogs.tsx b/packages/web/src/components/layout/project-dialogs.tsx
index 55120a58..6bac622a 100644
--- a/packages/web/src/components/layout/project-dialogs.tsx
+++ b/packages/web/src/components/layout/project-dialogs.tsx
@@ -281,6 +281,9 @@ function GeneralSection({
const [nameBusy, setNameBusy] = useState(false);
const [nameError, setNameError] = useState<string | undefined>(undefined);
const [confirmDelete, setConfirmDelete] = useState(false);
+ /** The reason the last delete was refused (drawn inside the card that asked, see doDelete). */
+ const [deleteRefusal, setDeleteRefusal] = useState<string | null>(null);
+ const [deleteBusy, setDeleteBusy] = useState(false);
const saveName = async () => {
const next = name.trim();
@@ -297,15 +300,26 @@ function GeneralSection({
}
};
+ /**
+ * The delete card closes only once the delete landed. A refusal leaves it standing with the
+ * server's words under its sentence (`ConfirmModal`'s `refusal` slot): the toast that used to
+ * carry them dismissed itself after a few seconds, out of the card the user was still looking
+ * at — and the Project is, after all, still there. The retry is the same button.
+ */
const doDelete = async () => {
+ if (deleteBusy) return;
+ setDeleteBusy(true);
try {
await api.deleteProject(projectId);
+ setConfirmDelete(false);
onClose();
const next = projects.find((p) => p.projectId !== projectId);
await reloadProjects();
if (next) setCurrentProjectId(next.projectId);
} catch (e) {
- toastError(apiErrorText(e));
+ setDeleteRefusal(apiErrorText(e));
+ } finally {
+ setDeleteBusy(false);
}
};
@@ -359,7 +373,16 @@ function GeneralSection({
<SettingRow title={S.project.deleteProject} description={S.project.deleteLastForbidden} />
) : (
<SettingRow title={S.project.deleteProject} description={S.project.deleteProjectDesc}>
- <Button size="sm" variant="danger" onClick={() => setConfirmDelete(true)}>
+ <Button
+ size="sm"
+ variant="danger"
+ // The reason from the last attempt belongs to that attempt: reopening the card
+ // starts a new question, one the user has not been refused yet.
+ onClick={() => {
+ setDeleteRefusal(null);
+ setConfirmDelete(true);
+ }}
+ >
{S.common.delete}
</Button>
</SettingRow>
@@ -373,6 +396,8 @@ function GeneralSection({
onConfirm={() => void doDelete()}
confirmLabel={S.common.confirm}
cancelLabel={S.common.cancel}
+ busy={deleteBusy}
+ refusal={deleteRefusal === null ? undefined : S.common.refused(deleteRefusal)}
>
<p className="text-sm text-gray-600 dark:text-gray-300">{S.project.deleteConfirm}</p>
</ConfirmModal>