Skip to content

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

fix(web): 删除手册文档的确认框被拒时留着,原因也留在框里(7.41)

lmliheng3859ef58769d
diff --git a/changelog/unreleased/2026-10-25-handbook-delete-refusal.md b/changelog/unreleased/2026-10-25-handbook-delete-refusal.md
new file mode 100644
index 00000000..f7078e47
--- /dev/null
+++ b/changelog/unreleased/2026-10-25-handbook-delete-refusal.md
@@ -0,0 +1,37 @@
+# Organization handbook: a refused deletion keeps its question — and the reason
+
+- **Date:** 2026-10-25
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[中文](2026-10-25-handbook-delete-refusal.zh.md)
+
+The Delete button over a handbook document asks in the shared confirmation card before the file
+leaves `handbook/`. That card used to stay open when the delete was refused, but the reason only
+fell into a toast that dismissed itself after a few seconds and floated above the card — the card
+itself said nothing, so all the reader saw was the buttons coming alive again with the document
+still there.
+
+The card now closes only on the path where its delete landed; a refusal draws the server's words
+inside the card, right above the retry button (`ConfirmModal`'s `refusal` slot, the app's existing
+"Refused:" lead-in). Opening the card again drops the previous reason, which belonged to the
+attempt it named; a write in flight takes one press only, and cancelling decides nothing.
+
+## Details
+
+- `features/company/handbook-page.tsx`: `remove()` keeps the server's words in `deleteRefusal`
+ instead of only toasting them, and both `setDeleteOpen(false)` and the success notice sit on the
+ path after the `await` succeeded. The document header's Delete button clears the previous reason
+ before it opens the card; the card's `onClose` already stopped answering while a delete was out
+ (`busy`), and the card now renders `refusal`.
+- New browser test `e2e/handbook-delete-refusal.spec.mjs`: with `DELETE …/handbook/files/<path>`
+ refused at `page.route` 500, the card, its sentence and the document on the server all stay
+ (nothing in the notification region carries the words); cancelling and reopening shows no stale
+ reason; the retry on the same card really deletes — the card closes, the row leaves the tree, the
+ document reads 404 and the pane falls back to the index.
+
+## Compatibility
+
+- No interface, wire-format, stored-data or dependency change: only *when* this card closes and
+ *where* the reason is drawn. No new copy beyond the existing `S.common.refused` lead-in.
diff --git a/changelog/unreleased/2026-10-25-handbook-delete-refusal.zh.md b/changelog/unreleased/2026-10-25-handbook-delete-refusal.zh.md
new file mode 100644
index 00000000..40ad9109
--- /dev/null
+++ b/changelog/unreleased/2026-10-25-handbook-delete-refusal.zh.md
@@ -0,0 +1,31 @@
+# 组织手册:删除文档被拒时,确认框留着,原因也留在框里
+
+- **Date:** 2026-10-25
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[English](2026-10-25-handbook-delete-refusal.md)
+
+组织手册里文档上方那枚「删除」会在真的删之前用共享的确认框问一句。过去这张框被拒时框是留着的,可原因
+只落进一条几秒后自己消失、还浮在框上方的通知里 —— 框本身一个字都没有,读者只看到按钮又亮了,文档却
+还在。
+
+现在关框只发生在删除落地那条路径上;被拒时服务端原话画进框里、重试按钮正上方(`ConfirmModal` 的
+`refusal` 槽,用的是应用既有的「操作被拒绝:」前缀)。重开这张框会先清掉上一次的原因 —— 那句话属于上次
+那次尝试;一个写入在途时只认一次点击,取消不决定任何事。
+
+## 细节
+
+- `features/company/handbook-page.tsx`:`remove()` 把服务端原话留在 `deleteRefusal` 里,不再只弹通知;
+ `setDeleteOpen(false)` 与那段成功通知都在 `await` 成功之后。文档头部那枚「删除」在开框前先清掉旧原因;
+ 框的 `onClose` 本来就在删除在途时不再响应(`busy`),框现在把 `refusal` 画出来。
+- 新增浏览器用例 `e2e/handbook-delete-refusal.spec.mjs`:用 `page.route` 把
+ `DELETE …/handbook/files/<路径>` 拒成 500 之后,框、框里那句话与服务端上的文档都不变(通知区里没有
+ 那句原话),取消后重开不带旧原因;在同一张框上重试才真正删除 —— 框关掉、行从树里消失、单读 404,
+ 文档面板回到索引。
+
+## 兼容性
+
+- 没有接口、传输格式、已存数据或依赖变化:只改了这张框「什么时候关」与「原因画在哪」。除既有的
+ `S.common.refused` 前缀外没有新文案。
diff --git a/packages/web/e2e/handbook-delete-refusal.spec.mjs b/packages/web/e2e/handbook-delete-refusal.spec.mjs
new file mode 100644
index 00000000..878dd7db
--- /dev/null
+++ b/packages/web/e2e/handbook-delete-refusal.spec.mjs
@@ -0,0 +1,165 @@
+/**
+ * Regression: deleting a handbook document is asked in a confirmation card, and a refused
+ * delete keeps that question — with the server's words inside it — instead of leaving only a
+ * toast behind.
+ *
+ * The card in `features/company/handbook-page.tsx` (the selected document's own Delete button)
+ * already stayed open on a refusal, but its reason fell into a toast that dismissed itself after
+ * a few seconds and sat over the card rather than in it. It now closes only once its delete
+ * landed; a refusal leaves the card standing with the reason drawn under its sentence
+ * (`ConfirmModal`'s `refusal` slot), so the retry is the button that was pressed and cancelling
+ * decides nothing.
+ *
+ * The organization and the document are made through the API rather than through the dialogs:
+ * this spec is about the confirmation, not about creation. Company mode is off on a fresh
+ * server, so the test turns the admin master switch on first (idempotent), and the Project gets
+ * the mock as its model so the onboarding overlay stays off the page.
+ */
+import { test, expect, request } from "@playwright/test";
+import { ADMIN_ID, ADMIN_PASSWORD, login, provisionAndLogin } from "./auth.mjs";
+
+const BASE = process.env.BASE_URL;
+const MOCK = process.env.MOCK_URL;
+const P = "password123";
+const ORG = "orgdelrefuse";
+const MISSION = "把插件市场上线,做到搜索前三。";
+/** The document the flow deletes; the index (README.md) is the one the server never lets go. */
+const DOC = "decisions/2026-10-25-hire-plan.md";
+const DOC_BODY = "# 招聘计划\n\n先招两名工程师。\n";
+
+/** The refusal the page paints; a 500 with its own words proves those words came back. */
+const REFUSAL = {
+ code: "org_store_locked",
+ message: "the organization store is mid-rewrite",
+};
+
+/** The admin master switch, off by default: turned on server-wide before the flow starts. */
+async function enableCompanyMode() {
+ const adminCtx = await request.newContext();
+ try {
+ await login(adminCtx, ADMIN_ID, ADMIN_PASSWORD);
+ const res = await adminCtx.put(`${BASE}/api/admin/settings`, { data: { companyMode: true } });
+ if (!res.ok()) {
+ throw new Error(`enable company mode failed: ${res.status()} ${await res.text()}`);
+ }
+ } finally {
+ await adminCtx.dispose();
+ }
+}
+
+/**
+ * A fresh user with mock-model credentials, an organization whose CEO the server makes on
+ * creation, and one handbook document written straight through the API.
+ */
+async function setUp(page, tag) {
+ await enableCompanyMode();
+ const user = `${tag}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 6)}`;
+ await provisionAndLogin(page.request, user, P);
+ const project = (await (await page.request.get(`${BASE}/api/projects`)).json()).projects[0];
+ const projectId = project.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 ${projectId}`).toBeTruthy();
+
+ const orgBase = `${BASE}/api/projects/${projectId}/organizations`;
+ const created = await page.request.post(orgBase, { data: { orgId: ORG, mission: MISSION } });
+ expect(created.ok(), "create organization").toBeTruthy();
+ const docUrl = `${orgBase}/${ORG}/handbook/files/${DOC}`;
+ const written = await page.request.put(docUrl, { data: { content: DOC_BODY } });
+ expect(written.ok(), "write the handbook document").toBeTruthy();
+
+ /** The document as the server has it: null once it is really gone. */
+ const read = async () => {
+ const res = await page.request.get(docUrl);
+ return res.ok() ? (await res.json()).content : null;
+ };
+ return { projectId, docUrl, read };
+}
+
+/** The selected document's Delete button → the confirmation card (a dialog of its own). */
+async function openDeleteCard(page, projectId) {
+ await page.goto(`/org/${projectId}/${ORG}/handbook`);
+ // Folders start closed: the document's own folder is opened by hand, as a reader would.
+ await page.locator('[data-tree-path="decisions"]').click();
+ const row = page.locator(`[data-tree-path="${DOC}"]`);
+ await expect(row).toBeVisible();
+ await row.click();
+ // The document's path heads its pane once the row is the selection.
+ await expect(page.getByRole("region", { name: DOC })).toBeVisible();
+ await page.getByRole("button", { name: "删除", exact: true }).click();
+ const card = page.getByRole("dialog", { name: "删除文档" });
+ await expect(card).toBeVisible();
+ return card;
+}
+
+/**
+ * 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 handbook deletion keeps the card, its sentence and the document", async ({
+ page,
+}) => {
+ const { projectId, docUrl, read } = await setUp(page, "r126hbdel");
+ expect(await read()).toBe(DOC_BODY);
+
+ const card = await openDeleteCard(page, projectId);
+ const sentence = await cardText(card);
+ expect(sentence).toContain(DOC);
+
+ const deletes = [];
+ await page.route(docUrl, async (route) => {
+ if (route.request().method() !== "DELETE") return route.fallback();
+ deletes.push(route.request().url());
+ await route.fulfill({
+ status: 500,
+ contentType: "application/json",
+ body: JSON.stringify({ error: REFUSAL }),
+ });
+ });
+
+ await card.getByRole("button", { name: "删除", exact: true }).click();
+
+ // The reason is in the card that asked, and it is not a toast: the notification region (which
+ // may still hold the company beta's own notice) never carries the server's words, and the card
+ // reads exactly as before plus the one line.
+ await expect(card.getByText(REFUSAL.message)).toBeVisible();
+ await expect(page.getByRole("region", { name: "通知" })).not.toContainText(REFUSAL.message);
+ expect(deletes).toHaveLength(1);
+ await expect(card).toBeVisible();
+ expect(await cardText(card)).toBe(sentence);
+
+ // Nothing was written: the document still reads, and its row is still in the tree.
+ expect(await read()).toBe(DOC_BODY);
+ await expect(page.locator(`[data-tree-path="${DOC}"]`)).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(page, projectId);
+ await expect(again.getByText(REFUSAL.message)).toHaveCount(0);
+ expect(await again.innerText()).toBe(sentence);
+
+ // The retry lands: the card goes, the document is gone, and the pane falls back to the index.
+ await page.unroute(docUrl);
+ await again.getByRole("button", { name: "删除", exact: true }).click();
+ await expect(again).toHaveCount(0);
+ await expect(page.locator(`[data-tree-path="${DOC}"]`)).toHaveCount(0);
+ expect(await read()).toBeNull();
+ await expect(page.getByRole("region", { name: "README.md" })).toBeVisible();
+});
diff --git a/packages/web/src/features/company/handbook-page.tsx b/packages/web/src/features/company/handbook-page.tsx
index 0b3adbc7..610744ff 100644
--- a/packages/web/src/features/company/handbook-page.tsx
+++ b/packages/web/src/features/company/handbook-page.tsx
@@ -6,11 +6,12 @@
* then folders and documents nested as they are on disk, with one button that collapses them
* all. Right, the selected document rendered as Markdown (anything else preformatted),
* edited in place through a monospace textarea with save and cancel, and — for every document
- * but the index — deleted behind the shared confirmation. The new-document dialog refuses a
- * path the server would, starts from the selected document's own folder so a document lands
- * beside its siblings, then creates the file with a one-line title and selects it. A relative
- * link inside a document opens the document it names in the same pane, so the index works as
- * the handbook's own navigation.
+ * but the index — deleted behind the shared confirmation, which closes only once its own delete
+ * landed: a refusal keeps the card standing with the server's words inside it, where the button
+ * that retries them is. The new-document dialog refuses a path the server would, starts from
+ * the selected document's own folder so a document lands beside its siblings, then creates the
+ * file with a one-line title and selects it. A relative link inside a document opens the
+ * document it names in the same pane, so the index works as the handbook's own navigation.
*
* Loading discipline: the skeleton stands only until the first listing or its failure; a
* failed refresh keeps the list on screen under one error line with its retry; a document
@@ -90,6 +91,8 @@ export function HandbookPage() {
const [createOpen, setCreateOpen] = useState(false);
const [deleteOpen, setDeleteOpen] = useState(false);
const [deleting, setDeleting] = useState(false);
+ /** The words of a delete the server refused, kept in the card that asked for it. */
+ const [deleteRefusal, setDeleteRefusal] = useState<string | null>(null);
// Another organization's handbook must not linger while this one loads.
useEffect(() => {
@@ -223,13 +226,16 @@ export function HandbookPage() {
setDeleting(true);
try {
await api.deleteOrgHandbookFile(projectId, orgId, path);
+ // The card goes with its own delete landing, never before: a refusal has to stay readable
+ // next to the button that retries it.
setDeleteOpen(false);
+ setDeleteRefusal(null);
setFiles((prev) => (prev === null ? prev : prev.filter((f) => f.path !== path)));
setSelected(HANDBOOK_INDEX);
toastSuccess(S.company.handbook.documentDeleted);
void loadList();
} catch (e) {
- toastError(apiErrorText(e));
+ setDeleteRefusal(apiErrorText(e));
} finally {
setDeleting(false);
}
@@ -392,7 +398,11 @@ export function HandbookPage() {
size="sm"
variant="danger"
disabled={doc === null}
- onClick={() => setDeleteOpen(true)}
+ onClick={() => {
+ // A new question, not the last one: the previous refusal is not its answer.
+ setDeleteRefusal(null);
+ setDeleteOpen(true);
+ }}
>
{S.common.delete}
</Button>
@@ -455,6 +465,7 @@ export function HandbookPage() {
busy={deleting}
onClose={() => (deleting ? undefined : setDeleteOpen(false))}
onConfirm={() => void remove()}
+ refusal={deleteRefusal === null ? undefined : S.common.refused(deleteRefusal)}
>
<p className="text-sm text-gray-600 dark:text-gray-300">
{S.company.handbook.deleteConfirm(selected)}