A local-first multi-agent app development platform, built on PenguinHarness
fix(web): 回收站的还原与彻底删除被拒时,原因留在那一行下面
lmliheng2f0459a9a65d
diff --git a/changelog/unreleased/2026-11-03-storage-trash-refusal.md b/changelog/unreleased/2026-11-03-storage-trash-refusal.mdnew file mode 100644index 00000000..99ad314e--- /dev/null+++ b/changelog/unreleased/2026-11-03-storage-trash-refusal.md@@ -0,0 +1,51 @@+# A refused trash write says so under the row that asked, past the toast it used to be++- **Date:** 2026-11-03+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[中文](2026-11-03-storage-trash-refusal.zh.md)++Settings → Storage ledger's trash offers three writes: restore an entry, delete one for good, and+delete everything past the retention. All three reported a failure in a six-second notification+only, while the entry stayed listed exactly as it was — same id, same size, same state. Six seconds+later the trash looked as if the button had never been pressed, on the one page whose "delete for+good" is the app's only deletion.++The reason now stays where the button is: under the two buttons of the row that asked, or under the+batch button that asked for the entries past retention. It is `role="alert"` (it is the only+account of what the row's unchanged state means), it names the action in the button's own words and+the entry where there is one, and it carries the server's reason as given. It stays until another+trash write is started; the same button is the retry.++## Details++- `packages/web/src/features/settings/storage-trash-refusal.ts` (new): `storageTrashKey(action,+ id)` — the key a write is known by while it is in flight, and the place its refusal is drawn —+ and `storageTrashRefused(key, reason)`, which turns that key plus a reason into the sentence. The+ batch's key is a word of its own (`purge:expired`), because an entry id is a compact timestamp+ and the batch names no entry at all.+- `packages/web/src/lib/strings{,-en}.ts`: three sentences — restore, delete for good, and delete+ what is past retention — next to the trash's existing ones. Each says which action it was.+- `packages/web/src/features/settings/storage-section.tsx`: one `trashRefusal` state, cleared when+ a trash write starts and set when one is refused; the line is drawn under the row's buttons or+ under the batch button. The failure notification stays, as it already does beside the apply+ refusal on this page — this change adds the account that outlives it, it does not take one away.++## Tests++- `packages/web/test/storage-trash-refusal.test.ts` (new, 8 cases): the two per-entry keys and the+ batch's; the key a refusal keeps; each of the three sentences; the reason travelling verbatim;+ the active language.+- `packages/web/e2e/storage-trash-refusal.spec.mjs` (new, one case on a real server): the trash+ listing and both writes are stubbed at `page.route` (the mode is turned on through the real+ setting). A refused restore puts one sentence under that row and nothing about the row changes;+ seven seconds later it is still there; pressing "delete for good" switches the line to that+ action's words; with the refusal lifted the same button goes through and the sentence goes.++## Compatibility++- No interface, request or storage change: the same `GET …/trash`, `POST …/trash/restore` and+ `POST …/trash/purge`. Only where a refused one is drawn has moved — from a notification alone to+ a line beside the button, which the notification no longer has to carry on its own.diff --git a/changelog/unreleased/2026-11-03-storage-trash-refusal.zh.md b/changelog/unreleased/2026-11-03-storage-trash-refusal.zh.mdnew file mode 100644index 00000000..8e4e1fcf--- /dev/null+++ b/changelog/unreleased/2026-11-03-storage-trash-refusal.zh.md@@ -0,0 +1,43 @@+# 回收站的还原与彻底删除被拒时,原因留在那一行下面,不再只活六秒++- **日期:** 2026-11-03+- **类型:** fix+- **范围:** `web`+- **破坏性:** 无++[English](2026-11-03-storage-trash-refusal.md)++设置 →「存储台账」的回收站有三个写操作:恢复一条、彻底删除一条、彻底删除已过保留期的。三个都+曾在失败时只弹一条六秒的通知,而那一行条目照旧列在那里 —— 编号、体积、状态一个字都没变。六秒之后+回收站看上去像没被点过,而这一页的「彻底删除」正是全应用唯一的删除操作。++现在原因留在按钮所在的地方:那一条的两个按钮下面,或者「彻底删除已过保留期的」这颗批次按钮下面。+它是 `role="alert"`(这一行没有任何别的东西在解释它为什么没变),内容是用那颗按钮自己的措辞说明+是哪一次动作、带了条目编号(有的话)以及服务端给出的原话。它留到下一次回收站写操作为止 —— 同一颗+按钮就是重试。++## 细节++- `packages/web/src/features/settings/storage-trash-refusal.ts`(新):`storageTrashKey(action,+ id)` —— 一次写操作在途时用的键(那一行的 `aria-busy`),也是它的拒绝要画在哪一行的答案;+ `storageTrashRefused(key, reason)` 把那个键与原因变成一句话。批次有自己的词(`purge:expired`):+ 条目编号是紧凑的时间戳,而批次根本不点条目。+- `packages/web/src/lib/strings{,-en}.ts`:三句话 —— 恢复、彻底删除、彻底删除已过保留期的 ——+ 挨着回收站已有的那几句,每句都点明是哪一次动作。+- `packages/web/src/features/settings/storage-section.tsx`:一个 `trashRefusal` 状态,回收站写操作+ 开始时清掉、被拒时写上;句子画在那一行的按钮下面,批次那句画在批次按钮下面。失败通知保留 ——+ 这一页的「执行清理」被拒时本来就是两者并存,本笔是补上一条活得更久的说法,没有撤掉任何一条。++## 测试++- `packages/web/test/storage-trash-refusal.test.ts`(新,8 条):两条按编号的键与批次的键 / 拒绝+ 保留原键 / 三句话各自的样子 / 原因原样带过去 / 跟着界面语言走。+- `packages/web/e2e/storage-trash-refusal.spec.mjs`(新,真服务端一条):回收站的读与两个写都桩在+ `page.route` 上(清理模式走真实的设置接口打开)。被拒的「恢复」在那一行下面留下一条句子,行的+ 其它地方一个字没变;七秒后句子仍在;再按「彻底删除」,句子换成那次动作的措辞;放开拒绝后同一颗+ 按钮走通、句子消失。++## 兼容++- 接口、请求与存储都没变:还是同一次 `GET …/trash`、`POST …/trash/restore`、`POST …/trash/purge`。+ 改变的只有被拒之后画在哪里 —— 从「只有一条通知」到「按钮旁边多一条活得下去的说法」。diff --git a/packages/web/e2e/storage-trash-refusal.spec.mjs b/packages/web/e2e/storage-trash-refusal.spec.mjsnew file mode 100644index 00000000..4097ec0a--- /dev/null+++ b/packages/web/e2e/storage-trash-refusal.spec.mjs@@ -0,0 +1,159 @@+/**+ * Regression: the ledger's trash says, under the row, why a restore or a deletion was refused —+ * and that sentence outlives the six seconds a toast lives.+ *+ * The row is what stays: same id, same size, same state, and the same button is the retry. A toast+ * was the only account of a failure there, so six seconds later the trash looked as if nothing had+ * been pressed at all — on the one page whose "delete for good" is the app's only deletion.+ *+ * The trash read and both writes are stubbed at `page.route`; everything else (the ledger, the+ * mode, the session) is the real server. The entry is a listing the page could have been handed+ * from a real run, and 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;++/** An entry as `GET …/trash` would list one: a compact timestamp id, as a run is moved at. */+const TRASH_ID = "20261103120000";++/** The lines the row draws, in the words of the button that was pressed. */+const RESTORE_REFUSED = `恢复「${TRASH_ID}」被拒:服务器内部错误,请稍后重试。`;+const PURGE_REFUSED = `彻底删除「${TRASH_ID}」被拒:服务器内部错误,请稍后重试。`;++/**+ * Sign in as the seeded administrator (the page is admin-only) and give the Project a model — the+ * onboarding overlay 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 trash's buttons are gated by the cleanup mode, which is off on an untouched install.+ 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;+}++/**+ * Answer the trash listing with one entry, and both of its writes with a refusal (500 `internal`)+ * until `letThrough()` — after which they answer the way a run that landed would. The writes are+ * counted, so the spec can tell a request from a dead button.+ */+const SUCCESS = {+ restore: { id: TRASH_ID, restored: ["logs/run"], skipped: [], remaining: false },+ purge: { purged: [{ id: TRASH_ID, bytes: 4096, files: 12 }] },+};++async function stubTrash(page, writes) {+ let refuse = true;+ await page.route("**/api/admin/storage/trash", async (route) => {+ if (route.request().method() !== "GET") return route.fallback();+ await route.fulfill({+ status: 200,+ contentType: "application/json",+ body: JSON.stringify({+ entries: [+ {+ id: TRASH_ID,+ createdAt: "2026-11-03T04:00:00.000Z",+ planId: null,+ bytes: 4096,+ files: 12,+ items: [{ path: "logs/run", bytes: 4096, files: 12 }],+ expired: false,+ },+ ],+ ttlDays: 7,+ }),+ });+ });+ for (const action of ["restore", "purge"]) {+ await page.route(`**/api/admin/storage/trash/${action}`, async (route) => {+ if (route.request().method() !== "POST") return route.fallback();+ writes.push({ action, body: route.request().postDataJSON() });+ await route.fulfill({+ status: refuse ? 500 : 200,+ contentType: "application/json",+ // The entry is a fixture, so a "landed" write is answered here too — the real route would+ // refuse an id it never wrote, which is a different refusal than the one under test.+ body: JSON.stringify(+ refuse+ ? { error: { code: "internal", message: "Internal server error" } }+ : SUCCESS[action],+ ),+ });+ });+ }+ return () => {+ refuse = false;+ };+}++test("a refused restore or deletion says so under its row, past the toast it used to be", async ({+ page,+}) => {+ await ready(page);+ const writes = [];+ const letThrough = await stubTrash(page, writes);++ await page.goto("/");+ const settings = await openStorage(page);+ const row = settings.locator("tr", { hasText: TRASH_ID });+ await expect(row).toBeVisible();++ // Refused restore: the row is drawn unchanged, with the reason under its buttons.+ await row.getByRole("button", { name: "恢复", exact: true }).click();+ await expect(row.getByRole("alert")).toHaveText(RESTORE_REFUSED);+ await expect(row.getByRole("alert")).toHaveCount(1);+ // Still listed as it was — nothing was restored, so nothing about the row may change.+ await expect(row).toBeVisible();+ expect(writes.map((w) => w.action)).toEqual(["restore"]);+ expect(writes[0].body).toEqual({ id: TRASH_ID });++ // 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(RESTORE_REFUSED);++ // The other button asks its own question, and the line switches to its words.+ await row.getByRole("button", { name: "彻底删除", exact: true }).click();+ await expect(row.getByRole("alert")).toHaveText(PURGE_REFUSED);+ await expect(row.getByRole("alert")).toHaveCount(1);+ expect(writes.map((w) => w.action)).toEqual(["restore", "purge"]);++ // 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);+ expect(writes.map((w) => w.action)).toEqual(["restore", "purge", "purge"]);+});diff --git a/packages/web/src/features/settings/storage-section.tsx b/packages/web/src/features/settings/storage-section.tsxindex 16541d2a..ec7d2ce2 100644--- a/packages/web/src/features/settings/storage-section.tsx+++ b/packages/web/src/features/settings/storage-section.tsx@@ -27,7 +27,10 @@* thing a cleanup decision must not be based on. The same rule governs the bill: a row this* version cannot move is drawn rather than dropped, a refusal is reported with the server's own* reason instead of a summary, and the fingerprint an approval sends is the one the displayed bill- * carries (storage-review.ts) — never one re-read from somewhere else.+ * 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.*/import { useCallback, useEffect, useMemo, useState } from "react";import type { ReactNode } from "react";@@ -60,8 +63,9 @@ import {} from "@adelie/ui";import * as api from "../../api/endpoints";import { S } from "../../lib/strings";-import { apiErrorText } from "../../lib/api-error";+import { apiErrorText, refusalText } from "../../lib/api-error";import { formatBytes, formatDateTime } from "../../lib/format";+import { toneInk } from "../../lib/tone";import {storageClassCost,storageClassLabel,@@ -86,6 +90,8 @@ import {storageUnselectClass,} from "./storage-review";import type { StorageBillGroup } from "./storage-review";+import { storageTrashKey, storageTrashRefused } from "./storage-trash-refusal";+import type { StorageTrashRefusal } from "./storage-trash-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 }) {@@ -538,6 +544,25 @@ function ApplyResult({ result }: { result: StorageApplyResponse }) {);}+/**+ * The line a refused trash write leaves, drawn under the buttons that asked for it.+ *+ * It stays until another trash write is started, because nothing on this page is what a retry+ * would change: the entry is still listed exactly as it was, and the same button is the retry.+ */+function TrashRefusalLine({ text }: { text: string }) {+ return (+ <p+ role="alert"+ data-tooltip={text}+ data-tooltip-content="text"+ className={`mt-1 max-w-[220px] text-left text-xs break-words whitespace-normal ${toneInk.danger}`}+ >+ {text}+ </p>+ );+}+/** The trash: what a move put aside, entry by entry, with the two things a person may do with it. */function TrashBlock({entries,@@ -546,6 +571,7 @@ function TrashBlock({busy,restored,purged,+ refusal,onRestore,onPurge,}: {@@ -555,6 +581,8 @@ function TrashBlock({busy: string | null;restored: StorageRestoreResponse | null;purged: StoragePurgeResponse | null;+ /** The last trash write the server refused — `key` says which row (or the batch) asked for it. */+ refusal: StorageTrashRefusal | null;onRestore: (id: string) => void;/** Without an id: only the entries past the retention. */onPurge: (id?: string) => void;@@ -601,11 +629,11 @@ function TrashBlock({<Buttonsize="sm"disabled={!enabled || busy !== null}- aria-busy={busy === `restore:${entry.id}`}+ aria-busy={busy === storageTrashKey("restore", entry.id)}title={enabled ? undefined : S.settings.storageModeRequired}onClick={() => onRestore(entry.id)}>- {busy === `restore:${entry.id}`+ {busy === storageTrashKey("restore", entry.id)? S.settings.storageTrashRestoring: S.settings.storageTrashRestore}</Button>@@ -616,12 +644,19 @@ function TrashBlock({variant="danger"className="ml-2"disabled={!enabled || busy !== null}- aria-busy={busy === `purge:${entry.id}`}+ aria-busy={busy === storageTrashKey("purge", entry.id)}title={enabled ? undefined : S.settings.storageModeRequired}onClick={() => onPurge(entry.id)}>{S.settings.storageTrashPurge}</Button>+ {/* Under the two buttons that were pressed, whichever of them was refused: the+ row is what stayed, and pressing the same one again is the retry. */}+ {refusal !== null &&+ (refusal.key === storageTrashKey("restore", entry.id) ||+ refusal.key === storageTrashKey("purge", entry.id)) && (+ <TrashRefusalLine text={refusal.text} />+ )}</TableCell></TableRow>))}@@ -629,17 +664,22 @@ function TrashBlock({</Table>)}{entries.some((entry) => entry.expired) && (- <div className="mt-3 flex justify-end">+ <div className="mt-3 flex flex-col items-end"><Buttonsize="sm"variant="danger"disabled={!enabled || busy !== null}- aria-busy={busy === "purge:expired"}+ aria-busy={busy === storageTrashKey("purgeExpired", null)}title={enabled ? undefined : S.settings.storageModeRequired}onClick={() => onPurge()}>{S.settings.storageTrashPurgeExpired}</Button>+ {/* The batch names no entry, so its refusal is its own sentence — and it is the one the+ server answers about entries this page may not even be showing. */}+ {refusal !== null && refusal.key === storageTrashKey("purgeExpired", null) && (+ <TrashRefusalLine text={refusal.text} />+ )}</div>)}{restored !== null && (@@ -710,6 +750,12 @@ export function StorageSection() {const [trashBusy, setTrashBusy] = useState<string | null>(null);const [restored, setRestored] = useState<StorageRestoreResponse | null>(null);const [purged, setPurged] = useState<StoragePurgeResponse | null>(null);+ /**+ * The last trash write the server refused, kept until another one starts: the entry is still+ * listed exactly as it was, so a line that outlives the toast is the only account of why+ * nothing happened (7.19's rule, app-wide).+ */+ 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);@@ -856,15 +902,20 @@ export function StorageSection() {const restore = async (id: string) => {if (trashBusy !== null) return;- setTrashBusy(`restore:${id}`);+ const key = storageTrashKey("restore", id);+ setTrashBusy(key);setRestored(null);setPurged(null);+ setTrashRefusal(null);try {setRestored(await api.adminRestoreStorageTrash(id));// Trees came back into the data root, so the ledger is a measurement of a moment that has// just passed; re-measuring is what keeps the two halves of the page telling one story.await Promise.all([measure(), loadState()]);} catch (e) {+ // The row stays exactly as it was — same id, same size, same state — so the reason has to+ // stay with it: the same button is the retry, and a toast would be gone before it is read.+ setTrashRefusal(storageTrashRefused(key, refusalText(e)));toastError(apiErrorText(e));} finally {setTrashBusy(null);@@ -873,15 +924,20 @@ export function StorageSection() {const purge = async (id?: string) => {if (trashBusy !== null) return;- setTrashBusy(id === undefined ? "purge:expired" : `purge:${id}`);+ const key = storageTrashKey(id === undefined ? "purgeExpired" : "purge", id ?? null);+ setTrashBusy(key);setRestored(null);setPurged(null);+ setTrashRefusal(null);try {setPurged(await api.adminPurgeStorageTrash(id));// The trash is part of the ledger's own figures, so the report is re-read rather than left// showing the size of what has just been deleted.await Promise.all([measure(), loadState()]);} catch (e) {+ // This is the one deletion in the app: a person who pressed it has to be told, where they+ // pressed it, that nothing was deleted and why.+ setTrashRefusal(storageTrashRefused(key, refusalText(e)));toastError(apiErrorText(e));} finally {setTrashBusy(null);@@ -1061,6 +1117,7 @@ export function StorageSection() {busy={trashBusy}restored={restored}purged={purged}+ refusal={trashRefusal}onRestore={(id) => void restore(id)}onPurge={(id) => void purge(id)}/>diff --git a/packages/web/src/features/settings/storage-trash-refusal.ts b/packages/web/src/features/settings/storage-trash-refusal.tsnew file mode 100644index 00000000..92d18ea4--- /dev/null+++ b/packages/web/src/features/settings/storage-trash-refusal.ts@@ -0,0 +1,58 @@+/**+ * The trash's three writes, and the line a refusal leaves under the button that asked.+ *+ * "Restore", "delete for good" and "delete what is past retention" each end in a `catch` that used+ * to be a toast only: six seconds later the entry was still listed, the trash looked untouched, and+ * nothing on screen said why — the shape 7.19 bans app-wide (a refusal lives where the thing it is+ * about lives). One of the three is the only deletion in the whole app, which is what makes the+ * missing account worse here than elsewhere: a person who pressed "delete for good" has to be told,+ * where they pressed it, that nothing was deleted and in the server's own words why.+ *+ * The refusal is keyed the same way as the button that asked, rather than kept as a sentence for+ * the block: an entry's row and the batch button are two different places on the page, and the+ * batch button names no entry at all.+ */+import { S } from "../../lib/strings";++/** The three writes the trash offers; the page names them by the same word in its own state. */+export type StorageTrashAction = "restore" | "purge" | "purgeExpired";++/**+ * The key one trash write is known by: while it is in flight (the row's `aria-busy`) and, if it is+ * refused, the row its line is drawn under.+ *+ * The batch that takes no entry has a word of its own (`purge:expired`); an entry's id is the+ * compact local timestamp a run was moved at (`20261103120000`, `…-2` for the second one in that+ * second — see `storageTrashId` in core), so the two can never collide.+ */+export function storageTrashKey(action: StorageTrashAction, id: string | null): string {+ return action === "purgeExpired" ? "purge:expired" : `${action}:${id ?? ""}`;+}++/** What a refused trash write leaves: the place to draw it (the key above) and the sentence. */+export interface StorageTrashRefusal {+ key: string;+ text: string;+}++/**+ * The line a refused trash write leaves, in the words of the button that was pressed: which action+ * it was (so the sentence still reads right under the batch button, which names no entry), the+ * entry it was for where there is one, and the reason the server gave, as it gave it.+ */+export function storageTrashRefused(key: string, reason: string): StorageTrashRefusal {+ if (key === storageTrashKey("purgeExpired", null)) {+ return { key, text: S.settings.storageTrashRefusedExpired(reason) };+ }+ // The two per-entry writes split on their first colon only: an id travels as it was recorded.+ const split = key.indexOf(":");+ const action = split < 0 ? key : key.slice(0, split);+ const id = split < 0 ? "" : key.slice(split + 1);+ return {+ key,+ text:+ action === "restore"+ ? S.settings.storageTrashRefusedRestore(id, reason)+ : S.settings.storageTrashRefusedPurge(id, reason),+ };+}diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.tsindex 17a51834..a3346332 100644--- a/packages/web/src/lib/strings-en.ts+++ b/packages/web/src/lib/strings-en.ts@@ -732,6 +732,16 @@ export const en: Strings = {no: "The trash entry was empty afterwards and has been removed.",},storageTrashSkippedLine: (path: string, reason: string): string => `${path}: ${reason}`,+ /**+ * A trash write the server refused, drawn under the button that asked: which action, the entry+ * it was for where there is one, and the reason as the server gave it.+ */+ storageTrashRefusedRestore: (id: string, reason: string): string =>+ `Restoring "${id}" was refused: ${reason}`,+ storageTrashRefusedPurge: (id: string, reason: string): string =>+ `Deleting "${id}" for good was refused: ${reason}`,+ storageTrashRefusedExpired: (reason: string): string =>+ `Deleting what is past retention was refused: ${reason}`,uploadLimitsTitle: "Upload limits",/** Its two number fields, both in whole MB. */attachmentMaxMb: "Max attachment size (MB)",diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.tsindex 8ccce97f..a29ca9f5 100644--- a/packages/web/src/lib/strings.ts+++ b/packages/web/src/lib/strings.ts@@ -797,6 +797,17 @@ export const zh = {no: "回收站条目已经空了,随之被移除。",},storageTrashSkippedLine: (path: string, reason: string): string => `${path}:${reason}`,+ /**+ * A trash write the server refused, drawn under the button that asked: which action, the entry+ * it was for where there is one, and the reason as the server gave it. The words name the same+ * action the button does, so the line still reads right under the batch button.+ */+ storageTrashRefusedRestore: (id: string, reason: string): string =>+ `恢复「${id}」被拒:${reason}`,+ storageTrashRefusedPurge: (id: string, reason: string): string =>+ `彻底删除「${id}」被拒:${reason}`,+ storageTrashRefusedExpired: (reason: string): string =>+ `彻底删除已过保留期的条目被拒:${reason}`,uploadLimitsTitle: "上传限制",/** Its two number fields, both in whole MB. */attachmentMaxMb: "单个附件上限(MB)",diff --git a/packages/web/test/storage-trash-refusal.test.ts b/packages/web/test/storage-trash-refusal.test.tsnew file mode 100644index 00000000..ceb6bce3--- /dev/null+++ b/packages/web/test/storage-trash-refusal.test.ts@@ -0,0 +1,85 @@+/**+ * Where a refused trash write lands (`storageTrashRefused`) and how the page names it+ * (`storageTrashKey`). All three writes in the trash used to report a failure in a toast that+ * dismissed itself, while the entry it was about stayed listed exactly as it was — the row is+ * where the retry is, so the line is drawn there.+ *+ * - `restore:<id>` and `purge:<id>` → that row, in the words of the button that was pressed.+ * - `purge:expired` → the batch button, which names no entry, so it gets its own sentence.+ * - The id travels as recorded, and the reason as the server gave it.+ */+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 {+ storageTrashKey,+ storageTrashRefused,+} from "../src/features/settings/storage-trash-refusal";++afterEach(() => {+ setActiveStrings(ZH);+});++describe("storageTrashKey", () => {+ it("names one entry's write by its action and id", () => {+ expect(storageTrashKey("restore", "20261103120000")).toBe("restore:20261103120000");+ expect(storageTrashKey("purge", "20261103120000-2")).toBe("purge:20261103120000-2");+ });++ it("gives the batch that takes no entry a word of its own", () => {+ // An entry's id is a compact timestamp, so it can never be the word this batch is known by.+ expect(storageTrashKey("purgeExpired", null)).toBe("purge:expired");+ });+});++describe("storageTrashRefused", () => {+ it("keeps the key it was given, so the page draws it under that row", () => {+ const key = storageTrashKey("purge", "20261103120000");+ expect(storageTrashRefused(key, "There is no trash entry with that id.").key).toBe(key);+ });++ it("says a refused restore in the restore button's words", () => {+ const refusal = storageTrashRefused(+ storageTrashKey("restore", "20261103120000"),+ "A file already exists at that path.",+ );+ expect(refusal.text).toBe("恢复「20261103120000」被拒:A file already exists at that path.");+ });++ it("says a refused deletion in the delete button's words", () => {+ const refusal = storageTrashRefused(+ storageTrashKey("purge", "20261103120000-2"),+ "There is no trash entry with that id.",+ );+ expect(refusal.text).toBe(+ "彻底删除「20261103120000-2」被拒:There is no trash entry with that id.",+ );+ });++ it("says the batch's refusal as its own sentence, with no entry in it", () => {+ const refusal = storageTrashRefused(+ storageTrashKey("purgeExpired", null),+ "Internal server error",+ );+ expect(refusal.text).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.+ const refusal = storageTrashRefused(+ storageTrashKey("purge", "x"),+ "服务器内部错误,请稍后重试。",+ );+ expect(refusal.text).toBe("彻底删除「x」被拒:服务器内部错误,请稍后重试。");+ });++ it("follows the interface language", () => {+ setActiveStrings(EN);+ expect(S.settings.storageTrashRefusedPurge("t-1", "nope")).toBe(+ 'Deleting "t-1" for good was refused: nope',+ );+ expect(S.settings.storageTrashRefusedExpired("nope")).toBe(+ "Deleting what is past retention was refused: nope",+ );+ });+});