A local-first multi-agent app development platform, built on PenguinHarness
fix(web): 插件设置里的操作被拒时,确认框留着,原因也留在框里(7.24)
lmlihenge4ec28b82719
diff --git a/changelog/unreleased/2026-10-22-plugin-action-refusal.md b/changelog/unreleased/2026-10-22-plugin-action-refusal.mdnew file mode 100644index 00000000..7af162e5--- /dev/null+++ b/changelog/unreleased/2026-10-22-plugin-action-refusal.md@@ -0,0 +1,35 @@+# A refused settings action keeps its confirmation and the reason in it++- **Date:** 2026-10-22+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[中文版](2026-10-22-plugin-action-refusal.zh.md)++A settings card's action (what the deployment must do once on the machine — the Windows sandbox's+"initialize", say) asks before it runs, and that card used to close the moment Run was pressed. When the+machine refused the request, or when the group answered that it did not run the action at all ("another task+is still running on this card"), the machine was exactly as it was, yet the reason arrived as a toast: six+seconds, floating above the card, and the only thing to do next was find the action's button again.++The card now closes on the answer, not on the request: a refused request, or a group answering `ok: false`,+leaves it open with those words under its sentence, so the retry is the same button. Only a run the group+reports as started closes it. While the action is running both buttons are disabled, since the card outlives+the click now.++## Details++- The rule follows the model library, scheduled tasks, evaluation center, plugin market and conversation+ rounds (`ConfirmModal`'s `refusal` slot): the reason is drawn inside the card that asked.+- `features/settings/plugins-section.tsx`: `runAction` closes the confirmation only when the result reports+ `ok`; otherwise the server's words (or the group's own message) go to a new `actionRefusal` state the+ confirmation draws. Opening the card from an action button clears the previous reason first.+- New browser spec `e2e/plugin-action-refusal.spec.mjs` (two tests): a refused action keeps the card, its+ sentence and its one write, raises no toast, and reopening it does not carry the old reason over; an+ `ok: false` answer keeps the card too, and a run that answers `ok` closes it.++## Compatibility++- No API, wire-format or dependency change: this is only when the card closes and where the reason is drawn.+- A group's notices and the card's live half are re-read as before; nothing else about actions changed.diff --git a/changelog/unreleased/2026-10-22-plugin-action-refusal.zh.md b/changelog/unreleased/2026-10-22-plugin-action-refusal.zh.mdnew file mode 100644index 00000000..0387272a--- /dev/null+++ b/changelog/unreleased/2026-10-22-plugin-action-refusal.zh.md@@ -0,0 +1,32 @@+# 插件设置里的操作被拒时,确认框留着,原因也留在框里++- **Date:** 2026-10-22+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[English](2026-10-22-plugin-action-refusal.md)++设置里插件卡片上的操作(部署必须在这台机器上做一次的事,比如 Windows 沙盒的「初始化」)执行前要先确认,+而那张卡片过去在按下「执行」的那一刻就关掉了。请求被拒的时候,或者分组自己回答根本没执行的时候(「此卡片+上还有任务在运行」),机器一点没变,可原因却是一条 toast:六秒,浮在卡片上方,而下一件事只能自己再去把那个+操作按钮找回来。++现在卡片在**拿到答复**时才关,不是在发出请求时关:被拒的请求、或分组回答 `ok: false`,都会让卡片留着,+把那句话画在句子下面,重试就是同一个按钮。只有分组回答已经开始的那一次才关框。执行期间两个按钮都置灰 ——+卡片现在活得比那次点击长。++## 细节++- 规则沿用模型库、定时任务、评估中心、插件市场与删除对话那几轮(`ConfirmModal` 的 `refusal` 槽):原因画在+ 发起它的那张卡片里。+- `features/settings/plugins-section.tsx`:`runAction` 只在结果报告 `ok` 时关掉确认框;其余情况把服务端的+ 原话(或分组自己的说法)交给新的 `actionRefusal` 状态,由确认框画出来。从操作按钮打开卡片时先清掉上一次+ 的原因。+- 新增浏览器用例 `e2e/plugin-action-refusal.spec.mjs`(两条):被拒的操作留着卡片、句子与那一次请求,不弹+ toast,重新打开时不带旧原因;分组回答 `ok: false` 也留着卡片,而回答 `ok` 的那一次才关框。++## 兼容性++- 没有接口、传输格式或依赖变化;只改了「框什么时候关」与「原因画在哪」。+- 分组的状态提示与卡片的实时部分照旧重读,操作的其它语义没变。diff --git a/packages/web/e2e/plugin-action-refusal.spec.mjs b/packages/web/e2e/plugin-action-refusal.spec.mjsnew file mode 100644index 00000000..2cc4958c--- /dev/null+++ b/packages/web/e2e/plugin-action-refusal.spec.mjs@@ -0,0 +1,149 @@+/**+ * Regression: a settings card's action asks first, and an action the machine did not run keeps+ * that question — with the reason inside it — instead of closing on the way out of the request.+ *+ * The page used to close the confirmation the moment Run was pressed: when the request was+ * refused, or when the group answered `ok: false` ("another task is still running on this+ * card"), the machine was exactly as it was, yet the reason arrived as a toast that dismissed+ * itself after six seconds and sat above the card rather than in it. The card now closes on the+ * answer — only a run the group reports as started closes it — and a refusal leaves it open+ * with the words under its sentence (`ConfirmModal`'s `refusal` slot), so the retry is the same+ * button.+ *+ * The card is stubbed: no group on a development data root reports an action (the Windows+ * sandbox offers its buttons on Windows only), so without a fixture the page has no card with+ * a Run button at all. Both halves the tests need are the page's own contract with the server —+ * the list it reads and the write it sends — and the write is what is measured.+ */+import { test, expect } from "@playwright/test";+import { ADMIN_ID, ADMIN_PASSWORD, login } from "./auth.mjs";++/** The card as the page reads it: the group, and the one action its heading draws a button for. */+const ENTRY = {+ name: "sandbox-wsl",+ configuration: { title: "WSL", titleZh: "WSL", properties: {} },+ values: {},+ actions: [{ id: "initialize", title: "Initialize sandbox distro", titleZh: "初始化沙盒发行版" }],+};++/** The action's button (its title, in the zh dictionary the suite runs in). */+const ACTION = "初始化沙盒发行版";++/** The request refused: a 500 with its own words proves the reason came back to the card. */+const REFUSAL = { code: "plugin_action_refused", message: "the machine is busy right now" };++/** The group's own answer when it will not run the action (the Windows sandbox's second run). */+const NOT_RUN = "Another task is still running on this card.";++/** What a started action answers: it reports progress on the card, so the card may close. */+const STARTED = "Initialize sandbox distro: its progress shows on the WSL card.";++/**+ * Serve the settings read from the fixture and take over the action write. `state.answer` says+ * what the write answers — a refusal, the group's `ok: false`, or a started run — and+ * `state.posts` keeps every write so the tests can tell how many were sent.+ */+async function stubConfig(page, state) {+ const json = (route, body) =>+ route.fulfill({ status: 200, contentType: "application/json", body: JSON.stringify(body) });+ await page.route("**/api/admin/plugin-config**", async (route) => {+ const req = route.request();+ if (new URL(req.url()).pathname.endsWith("/action")) {+ state.posts.push(req.postDataJSON());+ return state.answer(route, json);+ }+ if (req.method() !== "GET") return route.fallback();+ return json(route, { plugins: [ENTRY] });+ });+}++/** The settings dialog, on the page the card lives on. */+async function openSettings(page) {+ await page.goto("/plugins");+ await page.getByRole("button", { name: "插件设置", exact: true }).click();+ const pane = page.getByRole("dialog", { name: "设置" });+ await expect(pane).toBeVisible();+ return pane;+}++/** The card's action button, then the shared confirmation (named by its own title). */+async function askAction(page) {+ await page.getByRole("button", { name: ACTION, exact: true }).click();+ const dialog = page.getByRole("dialog", { name: "执行插件操作" });+ await expect(dialog).toBeVisible();+ return dialog;+}++/** The card's own text with the refusal line dropped — the only thing a refusal may change. */+async function cardText(dialog) {+ return (await dialog.innerText()).replace(/\n操作被拒绝:[^\n]*/, "");+}++/** The notification region: a refusal must not be announced there (that is the old toast). */+const notifications = (page) => page.getByRole("region", { name: "通知" });++const runButton = (dialog) => dialog.getByRole("button", { name: "执行", exact: true });++test("a refused action keeps the question, the reason and the card", async ({ page }) => {+ await login(page.request, ADMIN_ID, ADMIN_PASSWORD);+ const state = {+ posts: [],+ answer: (route, json) =>+ route.fulfill({+ status: 500,+ contentType: "application/json",+ body: JSON.stringify({ error: REFUSAL }),+ }),+ };+ await stubConfig(page, state);++ const pane = await openSettings(page);+ await expect(pane.getByRole("button", { name: ACTION, exact: true })).toBeVisible();+ const dialog = await askAction(page);+ const sentence = await cardText(dialog);++ await runButton(dialog).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 it did before the attempt plus one line.+ await expect(dialog.getByText(REFUSAL.message)).toBeVisible();+ await expect(notifications(page).getByRole("button")).toHaveCount(0);+ expect(state.posts).toEqual([{ name: ENTRY.name, action: "initialize" }]);+ await expect(dialog).toBeVisible();+ expect(await cardText(dialog)).toBe(sentence);++ // Closing the card decides nothing, and opening it again does not carry the old reason over.+ await dialog.getByRole("button", { name: "取消" }).click();+ await expect(dialog).toHaveCount(0);+ await expect(page.getByRole("button", { name: ACTION, exact: true })).toBeVisible();+ const reopened = await askAction(page);+ await expect(reopened.getByText(REFUSAL.message)).toHaveCount(0);+});++test("an action the group answers `ok: false` keeps the card, and a started one closes it", async ({+ page,+}) => {+ await login(page.request, ADMIN_ID, ADMIN_PASSWORD);+ const state = {+ posts: [],+ answer: (route, json) => json(route, { ok: false, message: NOT_RUN, plugins: [ENTRY] }),+ };+ await stubConfig(page, state);++ await openSettings(page);+ const dialog = await askAction(page);+ await runButton(dialog).click();++ // Nothing ran: the card says what the group said, and stays open for the retry.+ await expect(dialog.getByText(NOT_RUN)).toBeVisible();+ await expect(notifications(page).getByRole("button")).toHaveCount(0);+ await expect(dialog).toBeVisible();+ expect(state.posts).toHaveLength(1);++ // The retry is the same card, and this time the group reports it started: the card closes.+ state.answer = (route, json) => json(route, { ok: true, message: STARTED, plugins: [ENTRY] });+ await runButton(dialog).click();+ await expect(dialog).toHaveCount(0);+ expect(state.posts).toHaveLength(2);+ await expect(page.getByRole("button", { name: ACTION, exact: true })).toBeVisible();+});diff --git a/packages/web/src/features/settings/plugins-section.tsx b/packages/web/src/features/settings/plugins-section.tsxindex 82c222ea..4c0aa080 100644--- a/packages/web/src/features/settings/plugins-section.tsx+++ b/packages/web/src/features/settings/plugins-section.tsx@@ -105,6 +105,13 @@ export function PluginsSection({ focus }: { focus?: string } = {}) {id: string;title: string;} | null>(null);+ /**+ * The words for an action the machine refused, drawn inside the confirmation that asked for+ * it. Kept here rather than in a toast: nothing ran, so retrying is the next thing the person+ * does — and the button that retries it is in this card, while a toast dismisses itself after+ * six seconds and sits above it.+ */+ const [actionRefusal, setActionRefusal] = useState<string | null>(null);const { machineIds, machineLabels } = useSessions();/** The machine whose settings the page shows and saves: null for this server. */const [machine, setMachine] = useState<string | null>(null);@@ -284,12 +291,9 @@ export function PluginsSection({ focus }: { focus?: string } = {}) {};/**- * Runs a group's action: what the deployment must DO once on the machine (the Windows- * sandbox's local accounts). The result's own words are what the person sees — the module- * knows what happened, this page does not — and the groups it answers with replace ours,- * because a setup that worked changes what the card says about itself.+ * A group action's button: asks first, with the action's own title (see pendingAction) and+ * without the previous refusal — that sentence belonged to the attempt before.*/- /** A group action's button: asks first, with the action's own title (see pendingAction). */const askAction = (entry: PluginConfigEntry, id: string) => {const action = entry.actions?.find((a) => a.id === id);setPendingAction({@@ -297,18 +301,32 @@ export function PluginsSection({ focus }: { focus?: string } = {}) {id,title: (action && localized(action.title, action.titleZh)) ?? action?.title ?? id,});+ setActionRefusal(null);};+ /**+ * Runs a group's action: what the deployment must DO once on the machine (the Windows+ * sandbox's local accounts). The result's own words are what the person sees — the module+ * knows what happened, this page does not — and the groups it answers with replace ours,+ * because a setup that worked changes what the card says about itself.+ *+ * The confirmation closes on the answer, not on the request: an action that did not run —+ * a refused request, or a group answering `ok: false` ("another task is running") — leaves+ * the machine as it was, so the card stays open with those words in it and the same button+ * retries. Closing it as the request left used to take the reason away with it.+ */const runAction = async (entry: PluginConfigEntry, action: string) => {setBusy(`${entry.name}\0${action}`);try {const res = await api.adminRunPluginConfigAction({ name: entry.name, action }, machine);adopt(res.plugins);const message = localized(res.message, res.messageZh) ?? res.message;- if (res.ok) toastSuccess(message);- else toastError(message);+ if (res.ok) {+ setPendingAction(null);+ toastSuccess(message);+ } else setActionRefusal(message);} catch (e) {- toastError(apiErrorText(e));+ setActionRefusal(apiErrorText(e));} finally {setBusy(null);}@@ -519,10 +537,12 @@ export function PluginsSection({ focus }: { focus?: string } = {}) {onClose={() => setPendingAction(null)}onConfirm={() => {if (pendingAction !== null) void runAction(pendingAction.entry, pendingAction.id);- setPendingAction(null);}}+ // The card stays open while the action runs, so its own buttons must not send it twice.+ busy={busy !== null}confirmLabel={S.settings.pluginActionRun}cancelLabel={S.common.cancel}+ refusal={actionRefusal === null ? undefined : S.common.refused(actionRefusal)}><p className="text-sm text-gray-600 dark:text-gray-300">{pendingAction !== null