Skip to content

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

fix(web): 清理模式的开关与「固定」被拒时,原因留在控件旁边

lmliheng101c5aa8998b
diff --git a/changelog/unreleased/2026-11-03-storage-settings-refusal.md b/changelog/unreleased/2026-11-03-storage-settings-refusal.md
new file mode 100644
index 00000000..be333296
--- /dev/null
+++ b/changelog/unreleased/2026-11-03-storage-settings-refusal.md
@@ -0,0 +1,54 @@
+# A refused cleanup-mode switch or pin says so beside the control, past the toast it used to be
+
+- **Date:** 2026-11-03
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[中文](2026-11-03-storage-settings-refusal.zh.md)
+
+Settings → Storage ledger has two writes on `StorageSettings`: the cleanup-mode switch, and each
+bill row's "Pin / Unpin". Neither is optimistic — the switch always shows the position the server
+answered with, and a refused pin leaves its button reading "Pin" — so a failure used to be a
+six-second notification only: six seconds later the switch sat quietly where it was (or the button
+still said "Pin") and nothing on screen said why. That switch is the gate on every other write this
+page offers ("nothing moves without a review"), and the pin is what keeps a path off later bills.
+
+Now the reason stays beside the control itself: the switch's line sits under the sentence that
+describes its position and names the direction that failed ("on" / "off"); the pin's line sits under
+that row's own button, in the button's words, with the path and the server's own reason. Both are
+`role="alert"` and both stay until the next write of the same kind — the control itself is the retry.
+
+## Details
+
+- `packages/web/src/features/settings/storage-settings-refusal.ts` (new): `storageModeRefused(enabled,
+ reason)` builds the switch's sentence (the direction comes from where this request was going, not
+ from the position on screen); `storagePinRefused(path, pinned, reason)` builds the pin's sentence
+ together with the path whose row draws it.
+- `packages/web/src/lib/strings{,-en}.ts`: three sentences — the mode switch, pin, unpin — beside the
+ wording of their own buttons, each naming the action that failed.
+- `packages/web/src/features/settings/storage-section.tsx`: two states (`modeRefusal` / `pinRefusal`),
+ cleared when a write starts and set when it is refused; `ModeRow` takes a `refusal` drawn under its
+ status sentence; `BillRow` takes a `refusal` drawn under that row's button (`BillGroup` hands it to
+ the row whose path it names). The failure notification stays: "Clean up" already reports a refusal
+ both on the page and as a toast on this page, and this adds the account that outlives it.
+
+## Tests
+
+- `packages/web/test/storage-settings-refusal.test.ts` (new, 9): each direction of the switch, pin vs
+ unpin wording, the path carried verbatim (spaces and colons included), the reason carried verbatim,
+ and the interface language.
+- `packages/web/e2e/storage-settings-refusal.spec.mjs` (new, two against a real server):
+ - Cleanup mode: the settings PUT is stubbed to 500; clicking the switch draws "Turning the cleanup
+ mode off was refused: …" under its status sentence while the switch stays on (it never moved);
+ seven seconds later the sentence is still there; once lifted the same switch really turns the mode
+ off and the sentence goes.
+ - Pin: the bill listing is a fixture entry and that row's pin is stubbed to 500; clicking "Pin"
+ draws the refusal under that row's own button, which still reads "Pin"; seven seconds later it is
+ still there; once lifted the same button works, the button reads "Unpin" and the sentence goes.
+
+## Compatibility
+
+- No route, request or stored shape changed: the same `GET`/`PUT …/admin/storage/settings` and the
+ same `POST …/plans/:id/pin`. What changed is only where a refusal is drawn — from "a notification
+ only" to "one more account beside the control that asked".
diff --git a/changelog/unreleased/2026-11-03-storage-settings-refusal.zh.md b/changelog/unreleased/2026-11-03-storage-settings-refusal.zh.md
new file mode 100644
index 00000000..09a3ca69
--- /dev/null
+++ b/changelog/unreleased/2026-11-03-storage-settings-refusal.zh.md
@@ -0,0 +1,46 @@
+# 清理模式的开关与「固定」被拒时,原因留在控件旁边,不再只活六秒
+
+- **日期:** 2026-11-03
+- **类型:** fix
+- **范围:** `web`
+- **破坏性:** 无
+
+[English](2026-11-03-storage-settings-refusal.md)
+
+设置 →「存储台账」有两个写在 `StorageSettings` 上:清理模式的开关,与账单每一行的「固定 / 取消
+固定」。两者都不做乐观写入 —— 开关永远显示服务端答回来的位置,被拒的固定也不会把那颗按钮改成
+「取消固定」—— 所以失败此前只剩一条六秒的通知:六秒之后开关静静地还在原处、按钮还写着「固定」,
+屏幕上没有一句话解释为什么。而这一页的开关正是其余每个写操作的闸门(「没有人看过就什么都不动」),
+固定则是决定某条路径会不会再出现在下一份账单里的那一下。
+
+现在原因留在控件自己旁边:开关那句在它的状态说明下面,点名是「开启」还是「关闭」失败;固定那句在
+那一行的按钮下面,用按钮自己的措辞(固定 / 取消固定)带上路径与服务端原话。两处都是 `role="alert"`,
+都留到下一次同一个写为止 —— 同一个控件就是重试。
+
+## 细节
+
+- `packages/web/src/features/settings/storage-settings-refusal.ts`(新):`storageModeRefused(enabled,
+ reason)` 给出开关要画的那句(方向来自这一次请求想去的那个位置,不是页面上显示的位置);
+ `storagePinRefused(path, pinned, reason)` 给出固定那句,连它该画在哪一行(`path`)一起。
+- `packages/web/src/lib/strings{,-en}.ts`:三句话 —— 清理模式的开关、固定、取消固定 —— 挨着它们
+ 各自的按钮文案,每句都点明是哪一次动作。
+- `packages/web/src/features/settings/storage-section.tsx`:两个状态(`modeRefusal` / `pinRefusal`),
+ 写操作开始时清掉、被拒时写上;`ModeRow` 多一个 `refusal`,画在状态说明下面;`BillRow` 多一个
+ `refusal`,画在那一行的按钮下面(`BillGroup` 按 `path` 只交给对上的那行)。失败通知保留 ——
+ 这一页的「执行清理」被拒时本来就是「页面上一条 + 一条通知」并存,本笔是补上一条活得更久的说法。
+
+## 测试
+
+- `packages/web/test/storage-settings-refusal.test.ts`(新,9 条):开关两个方向各自的措辞 / 固定与
+ 取消固定各自的措辞 / 路径原样带过去(含空格与冒号)/ 原因原样带过去 / 跟着界面语言走。
+- `packages/web/e2e/storage-settings-refusal.spec.mjs`(新,真服务端两条):
+ - 清理模式:设置的那次 PUT 桩成 500,点开关 → 状态说明下面出现「关闭清理模式被拒:…」,开关仍
+ 在开位(它本来就没动);七秒后那句仍在;放开之后同一颗开关真的把模式关掉、句子消失。
+ - 固定:账单列表桩成一份条目、那一行的 pin 桩成 500,点「固定」→ 那一行下面出现「固定「…」被拒:
+ …」、按钮仍写着「固定」;七秒后仍在;放开之后同一颗按钮走通、按钮变成「取消固定」、句子消失。
+
+## 兼容
+
+- 接口、请求与存储都没变:还是同一次 `GET`/`PUT …/admin/storage/settings`、同一次
+ `POST …/plans/:id/pin`。改变的只有被拒之后画在哪里 —— 从「只有一条通知」到「控件旁边多一条活得
+ 下去的说法」。
diff --git a/packages/web/e2e/storage-settings-refusal.spec.mjs b/packages/web/e2e/storage-settings-refusal.spec.mjs
new file mode 100644
index 00000000..681654d8
--- /dev/null
+++ b/packages/web/e2e/storage-settings-refusal.spec.mjs
@@ -0,0 +1,203 @@
+/**
+ * Regression: the ledger says, beside the control, why a cleanup-mode switch or a pin was refused
+ * — and that sentence outlives the six seconds a toast lives.
+ *
+ * Neither write moves optimistically: the switch shows the position the server answered with, and a
+ * refused pin leaves that row's button reading what it read before the click. So a toast was the
+ * only account of the failure, and six seconds later the page looked as if nothing had been pressed
+ * — on the page whose switch is the gate on every write it offers ("nothing moves without a
+ * review"), and whose pin is what keeps a path off later bills.
+ *
+ * The bill listing and both writes are stubbed at `page.route`; everything else (the ledger, the
+ * mode, the session) is the real server. The reason asserted is the app's own sentence for the code
+ * the server would send (`internal`).
+ */
+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 one path the stubbed bill lists, and the words both refusals use for it. */
+const PATH = "workspaces/probe";
+
+/**
+ * Sign in as the seeded administrator (the page is admin-only), give the Project a model — the
+ * onboarding overlay covers the page without one — and turn the cleanup mode on, which is what
+ * draws the bill and enables every control this spec presses.
+ */
+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();
+ const mode = await page.request.put(`${BASE}/api/admin/storage/settings`, {
+ data: { enabled: true },
+ });
+ expect(mode.ok(), "enable cleanup mode").toBeTruthy();
+}
+
+/** The settings dialog, opened the way a person opens it: the user menu, then a page. */
+async function openStorage(page) {
+ // The user menu shares its name with the Project switcher, so take the last match (as chat.spec).
+ await page.getByRole("button", { name: ADMIN_ID }).last().click();
+ await page.getByRole("menuitem", { name: "设置", exact: true }).click();
+ const settings = page.getByRole("dialog", { name: "设置" });
+ await expect(settings).toBeVisible();
+ await settings.getByRole("button", { name: "存储台账", exact: true }).click();
+ return settings;
+}
+
+/** A bill a real scan could have written: one movable entry, still inside its day. */
+const PLAN = {
+ id: "probe-plan",
+ root: "/tmp/adelie-probe",
+ createdAt: "2026-11-03T04:00:00.000Z",
+ expiresAt: "2026-11-04T04:00:00.000Z",
+ fingerprint: "probe-fingerprint",
+ totalBytes: 4096,
+ entries: [
+ {
+ path: PATH,
+ class: "tmp_workspaces",
+ bytes: 4096,
+ files: 3,
+ lastModifiedAt: "2026-11-01T04:00:00.000Z",
+ rules: ["empty"],
+ fingerprint: "probe-entry",
+ executable: true,
+ },
+ ],
+ excluded: [],
+ executableClasses: ["tmp_workspaces"],
+ appliedAt: null,
+ appliedPaths: [],
+ usable: true,
+ expired: false,
+};
+
+/** The refusal both routes answer with until their stub lets a write through. */
+const REFUSAL = { error: { code: "internal", message: "Internal server error" } };
+
+/**
+ * Answer one settings write with a refusal (500 `internal`) until `letThrough()`. The writes are
+ * counted, so the spec can tell a request from a dead control. A read of the same URL (the mode's
+ * settings are one) is the server's own answer — only the write is stubbed.
+ */
+async function stubWrite(page, url, writes, landed) {
+ let refuse = true;
+ await page.route(url, async (route) => {
+ if (route.request().method() === "GET") return route.fallback();
+ writes.push(route.request().postDataJSON());
+ await route.fulfill({
+ status: refuse ? 500 : 200,
+ contentType: "application/json",
+ body: JSON.stringify(refuse ? REFUSAL : landed),
+ });
+ });
+ return () => {
+ refuse = false;
+ };
+}
+
+test("a refused cleanup-mode switch says so beside the switch, past the toast it used to be", async ({
+ page,
+}) => {
+ await ready(page);
+ const writes = [];
+ // The mode is on, so the switch asks to turn it off — and the settings answer it lands with is
+ // the serviced position, which the page then acts on.
+ const letThrough = await stubWrite(page, "**/api/admin/storage/settings", writes, {
+ settings: { enabled: false, trashTtlDays: 7, pins: [] },
+ });
+
+ await page.goto("/");
+ const settings = await openStorage(page);
+ const mode = settings.getByRole("switch", { name: "允许人工审核后的清理" });
+ await expect(mode).toBeVisible();
+ await expect(mode).toHaveAttribute("aria-checked", "true");
+
+ await mode.click();
+ const line = settings.getByRole("alert");
+ await expect(line).toHaveText("关闭清理模式被拒:服务器内部错误,请稍后重试。");
+ // The switch never moved: the position is the server's answer, not the click.
+ await expect(mode).toHaveAttribute("aria-checked", "true");
+ expect(writes).toEqual([{ enabled: false }]);
+
+ // Six seconds is how long a toast lives; this sentence has to still be there after it.
+ await page.waitForTimeout(7_000);
+ await expect(settings.getByRole("alert")).toHaveText(
+ "关闭清理模式被拒:服务器内部错误,请稍后重试。",
+ );
+
+ // With the refusal lifted the same switch works, the mode really turns off, and the line goes.
+ letThrough();
+ await mode.click();
+ await expect(mode).toHaveAttribute("aria-checked", "false");
+ await expect(settings.getByRole("alert")).toHaveCount(0);
+ expect(writes).toEqual([{ enabled: false }, { enabled: false }]);
+});
+
+test("a refused pin says so under the row's own button, past the toast it used to be", async ({
+ page,
+}) => {
+ await ready(page);
+ const writes = [];
+ // The bill is a fixture, so the page is handed it; the pin itself is the write under test.
+ await page.route("**/api/admin/storage/plans", async (route) => {
+ if (route.request().method() !== "GET") return route.fallback();
+ await route.fulfill({
+ status: 200,
+ contentType: "application/json",
+ body: JSON.stringify({ plans: [PLAN] }),
+ });
+ });
+ // A landed pin answers with the settings blob the page then draws the pins from.
+ const letThrough = await stubWrite(page, "**/api/admin/storage/plans/probe-plan/pin", writes, {
+ settings: { enabled: true, trashTtlDays: 7, pins: [PATH] },
+ });
+
+ await page.goto("/");
+ const settings = await openStorage(page);
+ const row = settings.locator("tr", { hasText: PATH });
+ await expect(row).toBeVisible();
+
+ await row.getByRole("button", { name: "固定", exact: true }).click();
+ await expect(row.getByRole("alert")).toHaveText(
+ `固定「${PATH}」被拒:服务器内部错误,请稍后重试。`,
+ );
+ await expect(row.getByRole("alert")).toHaveCount(1);
+ // The button still says "固定": nothing was pinned, so nothing about the row may claim it was.
+ await expect(row.getByRole("button", { name: "固定", exact: true })).toBeVisible();
+ expect(writes).toEqual([{ path: PATH, pinned: true }]);
+
+ // Six seconds is how long a toast lives; this sentence has to still be there after it.
+ await page.waitForTimeout(7_000);
+ await expect(row.getByRole("alert")).toHaveText(
+ `固定「${PATH}」被拒:服务器内部错误,请稍后重试。`,
+ );
+
+ // With the refusal lifted the same button works, and the sentence goes: the row is the retry.
+ letThrough();
+ await row.getByRole("button", { name: "固定", exact: true }).click();
+ await expect(row.getByRole("alert")).toHaveCount(0);
+ await expect(row.getByRole("button", { name: "取消固定", exact: true })).toBeVisible();
+ expect(writes).toEqual([
+ { path: PATH, pinned: true },
+ { path: PATH, pinned: true },
+ ]);
+});
diff --git a/packages/web/src/features/settings/storage-section.tsx b/packages/web/src/features/settings/storage-section.tsx
index ec7d2ce2..24384d1e 100644
--- a/packages/web/src/features/settings/storage-section.tsx
+++ b/packages/web/src/features/settings/storage-section.tsx
@@ -30,7 +30,10 @@
* carries (storage-review.ts) — never one re-read from somewhere else. The trash's three writes
* follow the same rule (storage-trash-refusal.ts): an entry whose restore or deletion was refused
* is still listed exactly as it was, so the reason stays under the buttons that asked, where the
- * retry is — and one of those three is the only deletion in the app.
+ * retry is — and one of those three is the only deletion in the app. The mode switch and each
+ * row's pin follow it as well (storage-settings-refusal.ts): neither moves optimistically, so a
+ * refused one leaves its control exactly where the server has it, and the sentence says why beside
+ * that control.
*/
import { useCallback, useEffect, useMemo, useState } from "react";
import type { ReactNode } from "react";
@@ -92,6 +95,8 @@ import {
import type { StorageBillGroup } from "./storage-review";
import { storageTrashKey, storageTrashRefused } from "./storage-trash-refusal";
import type { StorageTrashRefusal } from "./storage-trash-refusal";
+import { storageModeRefused, storagePinRefused } from "./storage-settings-refusal";
+import type { StoragePinRefusal } from "./storage-settings-refusal";
/** A section of the page: its heading, an optional line saying what the heading's rows mean. */
function Block({ title, hint, children }: { title: string; hint?: string; children: ReactNode }) {
@@ -291,12 +296,15 @@ function ModeRow({
settings,
busy,
failed,
+ refusal,
onChange,
}: {
settings: StorageSettings | null;
busy: boolean;
/** The settings could not be read: the switch then shows the position the page acts on (off). */
failed: boolean;
+ /** A switch the server refused: the position it asked for, and why — drawn beside the switch. */
+ refusal: string | null;
onChange: (enabled: boolean) => void;
}) {
const enabled = settings?.enabled === true;
@@ -323,6 +331,14 @@ function ModeRow({
? S.settings.storageModeOn
: S.settings.storageModeOff}
</p>
+ {/* The switch never moved (the position comes from the server's answer, never the click), so
+ this sentence is the only account of why it is still where it is — and the switch above it
+ is the retry. */}
+ {refusal !== null && (
+ <p role="alert" className={`mt-1 text-xs break-words ${toneInk.danger}`}>
+ {refusal}
+ </p>
+ )}
</Block>
);
}
@@ -362,6 +378,7 @@ function BillGroup({
approvable,
enabled,
pinning,
+ pinRefusal,
onToggleRow,
onSelectClass,
onUnselectClass,
@@ -379,6 +396,8 @@ function BillGroup({
enabled: boolean;
/** The path whose pin request is in flight, so one row's button is busy and no others are. */
pinning: string | null;
+ /** The last pin the server refused — its path says which row draws the line. */
+ pinRefusal: StoragePinRefusal | null;
onToggleRow: (path: string) => void;
onSelectClass: (classKey: StorageClass) => void;
onUnselectClass: (classKey: StorageClass) => void;
@@ -440,6 +459,7 @@ function BillGroup({
movable={movable.has(entry.path)}
enabled={enabled}
pinning={pinning}
+ refusal={pinRefusal?.path === entry.path ? pinRefusal.text : null}
onToggleRow={onToggleRow}
onPin={onPin}
/>
@@ -458,6 +478,7 @@ function BillRow({
movable,
enabled,
pinning,
+ refusal,
onToggleRow,
onPin,
}: {
@@ -468,6 +489,8 @@ function BillRow({
movable: boolean;
enabled: boolean;
pinning: string | null;
+ /** A pin of this row the server refused: the sentence to draw under its button, or null. */
+ refusal: string | null;
onToggleRow: (path: string) => void;
onPin: (path: string, pinned: boolean) => void;
}) {
@@ -506,6 +529,18 @@ function BillRow({
>
{pinned ? S.settings.storageUnpin : S.settings.storagePin}
</Button>
+ {/* The button still says what it said before the click (nothing is pinned optimistically),
+ so the refusal belongs under it: the same button is the retry. */}
+ {refusal !== null && (
+ <p
+ role="alert"
+ data-tooltip={refusal}
+ data-tooltip-content="text"
+ className={`mt-1 max-w-[220px] text-left text-xs break-words whitespace-normal ${toneInk.danger}`}
+ >
+ {refusal}
+ </p>
+ )}
</TableCell>
</TableRow>
);
@@ -758,6 +793,13 @@ export function StorageSection() {
const [trashRefusal, setTrashRefusal] = useState<StorageTrashRefusal | null>(null);
/** The path whose pin request is in flight, so one row's button is busy and no others are. */
const [pinning, setPinning] = useState<string | null>(null);
+ /**
+ * The last mode switch or pin the server refused, kept until the next one starts: neither write
+ * moves optimistically, so the control itself still shows the position the server holds and this
+ * line is the only account of why (7.19's rule, app-wide).
+ */
+ const [modeRefusal, setModeRefusal] = useState<string | null>(null);
+ const [pinRefusal, setPinRefusal] = useState<StoragePinRefusal | null>(null);
const measure = useCallback(async () => {
setBusy(true);
@@ -822,10 +864,14 @@ export function StorageSection() {
const saveMode = async (next: boolean) => {
if (modeBusy) return;
setModeBusy(true);
+ setModeRefusal(null);
try {
setSettings((await api.adminUpdateStorageSettings({ enabled: next })).settings);
toastSuccess(S.common.saved);
} catch (e) {
+ // The switch snaps back to the position the server still holds (it was never moved), so the
+ // reason has to stay beside it: nothing on this page changed, and the switch is the retry.
+ setModeRefusal(storageModeRefused(next, refusalText(e)));
toastError(apiErrorText(e));
} finally {
setModeBusy(false);
@@ -882,6 +928,7 @@ export function StorageSection() {
const pin = async (path: string, pinned: boolean) => {
if (plan === null || pinning !== null) return;
setPinning(path);
+ setPinRefusal(null);
try {
setSettings((await api.adminPinStoragePath(plan.id, { path, pinned })).settings);
// A pinned path is refused by an apply, so it must not stay ticked: the refusal is
@@ -894,6 +941,9 @@ export function StorageSection() {
});
}
} catch (e) {
+ // The row is not pinned and nothing else about it changed, so the reason is drawn under the
+ // button that asked, in that button's own words.
+ setPinRefusal(storagePinRefused(path, pinned, refusalText(e)));
toastError(apiErrorText(e));
} finally {
setPinning(null);
@@ -976,6 +1026,7 @@ export function StorageSection() {
settings={settings}
busy={modeBusy}
failed={modeFailed}
+ refusal={modeRefusal}
onChange={(next) => void saveMode(next)}
/>
{report === null && (
@@ -1061,6 +1112,7 @@ export function StorageSection() {
approvable={approvable}
enabled={enabled}
pinning={pinning}
+ pinRefusal={pinRefusal}
onToggleRow={(path) =>
setSelection((current) => storageTogglePath(plan, current, path, pins))
}
diff --git a/packages/web/src/features/settings/storage-settings-refusal.ts b/packages/web/src/features/settings/storage-settings-refusal.ts
new file mode 100644
index 00000000..9cd3bfbd
--- /dev/null
+++ b/packages/web/src/features/settings/storage-settings-refusal.ts
@@ -0,0 +1,48 @@
+/**
+ * The cleanup mode and the pins — the page's two writes on `StorageSettings` — and the line a
+ * refusal leaves beside the control that asked.
+ *
+ * Neither write moves optimistically, which is exactly why the reason cannot be a toast: a refused
+ * switch is still where the server has it (the page acts on the answer, never the click), and a
+ * refused pin leaves that row's button saying what it said before. Six seconds later the switch is
+ * simply off, or the button simply says "pin" again, and nothing on screen says why — the shape
+ * 7.19 bans app-wide. Both controls are where the retry is, so both refusals are drawn there.
+ *
+ * The mode gates every write on this page, and a mode that silently refused to turn on is the
+ * page's whole promise (nothing moves without a review) failing shut; the pin is what keeps a path
+ * off later bills, and a pin that silently refused lists it again.
+ */
+import { S } from "../../lib/strings";
+
+/**
+ * The line a refused mode switch leaves under the sentence that describes the switch's position:
+ * which way it was asked to move (so the sentence names the action that failed) and the reason the
+ * server gave, as it gave it.
+ */
+export function storageModeRefused(enabled: boolean, reason: string): string {
+ return S.settings.storageModeRefused(enabled, reason);
+}
+
+/** What a refused pin leaves: the path whose row it belongs under, and the sentence. */
+export interface StoragePinRefusal {
+ path: string;
+ text: string;
+}
+
+/**
+ * The line a refused pin leaves under that row's own button, in the button's words: pinning and
+ * unpinning are two different asks, and a path refused for being pinned says something else than
+ * one refused for being let go. The path travels as the bill spells it — that is the row it fits.
+ */
+export function storagePinRefused(
+ path: string,
+ pinned: boolean,
+ reason: string,
+): StoragePinRefusal {
+ return {
+ path,
+ text: pinned
+ ? S.settings.storagePinRefused(path, reason)
+ : S.settings.storageUnpinRefused(path, reason),
+ };
+}
diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.ts
index a3346332..1ec7f6cb 100644
--- a/packages/web/src/lib/strings-en.ts
+++ b/packages/web/src/lib/strings-en.ts
@@ -639,6 +639,12 @@ export const en: Strings = {
storageModeFailed: "Could not read the cleanup mode's settings, so this page treats it as off.",
/** The hint on every write control the mode gates, so a disabled button says why. */
storageModeRequired: "Turn the cleanup mode on first",
+ /**
+ * A mode switch the server refused, drawn under the sentence that describes the switch: which
+ * way it was asked to move (the switch itself never moved), and the reason as the server gave it.
+ */
+ storageModeRefused: (enabled: boolean, reason: string): string =>
+ `Turning the cleanup mode ${enabled ? "on" : "off"} was refused: ${reason}`,
/** The bill's own state, one sentence each: the difference decides whether a selection may run. */
storagePlanStateText: {
usable: "Not applied yet, and still within its day: the entries you tick can be moved.",
@@ -691,6 +697,14 @@ export const en: Strings = {
storageExcludedTitle: (count: number): string => `This bill left out ${count} pinned paths`,
storagePin: "Pin",
storageUnpin: "Unpin",
+ /**
+ * A pin the server refused, drawn under that row's own button in its words: pinning and
+ * unpinning are two different asks, and the path says which row it is about.
+ */
+ storagePinRefused: (path: string, reason: string): string =>
+ `Pinning "${path}" was refused: ${reason}`,
+ storageUnpinRefused: (path: string, reason: string): string =>
+ `Unpinning "${path}" was refused: ${reason}`,
/** The one action that moves something, and what it does when it does it. */
storageApply: "Clean up",
storageApplying: "Cleaning up…",
diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.ts
index a29ca9f5..bfdfda05 100644
--- a/packages/web/src/lib/strings.ts
+++ b/packages/web/src/lib/strings.ts
@@ -705,6 +705,12 @@ export const zh = {
storageModeFailed: "无法读取清理模式设置,因此按「已关闭」处理。",
/** The hint on every write control the mode gates, so a disabled button says why. */
storageModeRequired: "需要先开启清理模式",
+ /**
+ * A mode switch the server refused, drawn under the sentence that describes the switch: which
+ * way it was asked to move (the switch itself never moved), and the reason as the server gave it.
+ */
+ storageModeRefused: (enabled: boolean, reason: string): string =>
+ `${enabled ? "开启" : "关闭"}清理模式被拒:${reason}`,
/** The bill's own state, one sentence each: the difference decides whether a selection may run. */
storagePlanStateText: {
usable: "尚未执行,且仍在有效期内:勾选的条目可以被移动。",
@@ -757,6 +763,13 @@ export const zh = {
storageExcludedTitle: (count: number): string => `这份账单排除了 ${count} 条已固定路径`,
storagePin: "固定",
storageUnpin: "取消固定",
+ /**
+ * A pin the server refused, drawn under that row's own button in its words: pinning and
+ * unpinning are two different asks, and the path says which row it is about.
+ */
+ storagePinRefused: (path: string, reason: string): string => `固定「${path}」被拒:${reason}`,
+ storageUnpinRefused: (path: string, reason: string): string =>
+ `取消固定「${path}」被拒:${reason}`,
/** The one action that moves something, and what it does when it does it. */
storageApply: "执行清理",
storageApplying: "清理中…",
diff --git a/packages/web/test/storage-settings-refusal.test.ts b/packages/web/test/storage-settings-refusal.test.ts
new file mode 100644
index 00000000..f5ddc9c9
--- /dev/null
+++ b/packages/web/test/storage-settings-refusal.test.ts
@@ -0,0 +1,90 @@
+/**
+ * How the ledger names a refused settings write: the mode switch (`storageModeRefused`) and a
+ * row's pin (`storagePinRefused`). Neither write moves optimistically — the switch shows the
+ * position the server answered with, and the pin button still reads what it read before the click —
+ * so a toast used to be the only account of a failure, and six seconds later the page looked as if
+ * nothing had been pressed.
+ *
+ * - The mode's sentence names the direction that failed ("开启" / "关闭"), because the switch is
+ * still in the other position.
+ * - The pin's sentence names the ask ("固定" / "取消固定") and travels with the path it is about,
+ * which is the row the line is drawn under.
+ * - The reason is whatever the server gave, verbatim.
+ */
+import { afterEach, describe, expect, it } from "vitest";
+import { S, setActiveStrings, zh as ZH } from "../src/lib/strings";
+import { en as EN } from "../src/lib/strings-en";
+import {
+ storageModeRefused,
+ storagePinRefused,
+} from "../src/features/settings/storage-settings-refusal";
+
+afterEach(() => {
+ setActiveStrings(ZH);
+});
+
+describe("storageModeRefused", () => {
+ it("names turning the mode on as the ask that failed", () => {
+ expect(storageModeRefused(true, "Internal server error")).toBe(
+ "开启清理模式被拒:Internal server error",
+ );
+ });
+
+ it("names turning it off as a different ask", () => {
+ // The switch is still where the server has it, so the sentence has to say which way failed.
+ expect(storageModeRefused(false, "Internal server error")).toBe(
+ "关闭清理模式被拒:Internal server error",
+ );
+ });
+
+ it("carries the server's reason verbatim, punctuation and all", () => {
+ // `refusalText` already localized what it could; whatever it hands over is what is drawn.
+ expect(storageModeRefused(false, "服务器内部错误,请稍后重试。")).toBe(
+ "关闭清理模式被拒:服务器内部错误,请稍后重试。",
+ );
+ });
+
+ it("follows the interface language", () => {
+ setActiveStrings(EN);
+ expect(S.settings.storageModeRefused(true, "nope")).toBe(
+ "Turning the cleanup mode on was refused: nope",
+ );
+ expect(S.settings.storageModeRefused(false, "nope")).toBe(
+ "Turning the cleanup mode off was refused: nope",
+ );
+ });
+});
+
+describe("storagePinRefused", () => {
+ it("keeps the path, so the page draws the line under that row", () => {
+ const refusal = storagePinRefused("logs/a.log", true, "Internal server error");
+ expect(refusal.path).toBe("logs/a.log");
+ });
+
+ it("says a refused pin in the pin button's words", () => {
+ expect(storagePinRefused("logs/a.log", true, "Internal server error").text).toBe(
+ "固定「logs/a.log」被拒:Internal server error",
+ );
+ });
+
+ it("says a refused unpin in the unpin button's words", () => {
+ expect(storagePinRefused("logs/a.log", false, "Internal server error").text).toBe(
+ "取消固定「logs/a.log」被拒:Internal server error",
+ );
+ });
+
+ it("carries the path as the bill spells it, separators and all", () => {
+ // The path is the row's identity: nothing about it may be shortened or escaped on the way in.
+ expect(storagePinRefused("a b/c:d", true, "nope").text).toBe("固定「a b/c:d」被拒:nope");
+ });
+
+ it("follows the interface language", () => {
+ setActiveStrings(EN);
+ expect(storagePinRefused("logs/a.log", true, "nope").text).toBe(
+ 'Pinning "logs/a.log" was refused: nope',
+ );
+ expect(storagePinRefused("logs/a.log", false, "nope").text).toBe(
+ 'Unpinning "logs/a.log" was refused: nope',
+ );
+ });
+});