A local-first multi-agent app development platform, built on PenguinHarness
fix(web): 装入插件库被拒时原因留在那一行里,不再只活六秒
lmliheng067fb8f45b8f
diff --git a/changelog/unreleased/2026-11-06-plugin-library-add-refusal.md b/changelog/unreleased/2026-11-06-plugin-library-add-refusal.mdnew file mode 100644index 00000000..00b3ed87--- /dev/null+++ b/changelog/unreleased/2026-11-06-plugin-library-add-refusal.md@@ -0,0 +1,55 @@+# A published plugin the library could not take says why in its own row, not in a six-second toast++- **Date:** 2026-11-06+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[中文](2026-11-06-plugin-library-add-refusal.zh.md)++The plugin shelf's one verb on a published package — "add to the library" — is the npm import the+header dialog performs, without typing the address. When that fetch did not land (the registry did+not answer, the package could not be downloaded, the request never arrived) nothing changed: the+plugin was still nowhere, the same row still stood on the shelf with the same button, and the+reason went to a notification that dismissed itself after six seconds. Afterwards the row read+exactly as it had before the press, with nothing said about why.++That sentence now renders under the row it belongs to (`role="alert"`, danger colour, two lines,+the whole sentence on hover), outside the row's link so a click on it does not navigate away, and+stays until the next attempt on the shelf or the page goes. The row and its button are what the+reader retries from, so the reason has to outlive the press — which is the whole difference between+this and a toast. A name already taken is not a refusal and keeps its own place: the overwrite+confirmation, which the row raises with the plugin named in it.++## Details++- `packages/web/src/features/plugins/library-add-refusal.ts` (new): `libraryAddRefused(error)` —+ the pure decision of which words appear, so it is testable without the page. Plugin codes read+ through `pluginImportErrorText` (their own copy, never the English wire message), anything the+ client raised itself through `refusalText` (7.19's rule).+- `packages/web/src/features/plugins/plugins-page.tsx`: the page keeps `libraryRefusal`+ (specifier + sentence). `addPublishedToLibrary()` no longer toasts a failure: it clears the+ sentence when an attempt starts and writes it when the attempt fails; the published row reads it+ through `ModuleRow`'s new `refusal` slot. The row is now a column — the existing flex row plus+ the sentence underneath — so the reason sits inside the card rather than inside the link.+- `packages/web/src/lib/strings{,-en}.ts`: one new sentence,+ `plugins.libraryAddRefused(reason)`.++## Tests++- `packages/web/test/library-add-refusal.test.ts` (new, 5 cases): a plugin code reads its own+ localized copy and never the wire message; a code the plugin routes do not own falls back to the+ shared table; a value the client raised is shown as it wrote it; nothing to say falls back to the+ generic sentence; the active language is the one used.+- `packages/web/e2e/plugin-library-add-refusal.spec.mjs` (new, real server + real browser, 2+ cases): the fetch is stubbed to a 502 and the shelf's own verb is pressed — the sentence appears+ in that row, the notification region never carries it, the row and its enabled retry are still+ there, **seven seconds later** (past the six an error notification lives) it is still there, and+ the next attempt clears it. The second case: a 409 `plugin_exists` still opens the overwrite+ question (which names the plugin) and draws no refusal line; answering it re-sends the same+ request with `overwrite: true`.++## Compatibility++No interface change, no new dependency, no Project config change. The success path, the overwrite+question and the header dialog's own imports are untouched.diff --git a/changelog/unreleased/2026-11-06-plugin-library-add-refusal.zh.md b/changelog/unreleased/2026-11-06-plugin-library-add-refusal.zh.mdnew file mode 100644index 00000000..d3343341--- /dev/null+++ b/changelog/unreleased/2026-11-06-plugin-library-add-refusal.zh.md@@ -0,0 +1,44 @@+# 插件库没收下的那个上架插件,原因留在它自己那一行里,不再只活六秒++- **日期:** 2026-11-06+- **类型:** fix+- **范围:** `web`+- **破坏性:** 否++[English](2026-11-06-plugin-library-add-refusal.md)++插件市场上架包里那唯一一个动作 —— 「装入插件库」—— 就是标题行那个对话框做的 npm 导入,只是+不必自己敲地址。那次取包没落地时(registry 不答复、包下不下来、请求根本没到)什么都没变:插件+仍然哪里都不在,同一行仍在架上、同一个按钮仍在原地,而原因只落进一条通知,六秒后自己消失。此后+那一行读起来与按下之前一模一样,没说为什么。++那句话现在画在它所属的那一行下面(`role="alert"`、危险色、限两行、整句挂悬停),并且落在这一行+的链接之外,点它不会被带到别处;一直留到下次在架上再试或离开这一页。行与它那个按钮就是重试的+地方,所以原因必须活过这一次按下 —— 这正是它与通知的区别。名字已被占用不算拒绝,仍归它自己+那个位置:覆盖确认框,由这一行弹出并带着插件名。++## 明细++- `packages/web/src/features/plugins/library-add-refusal.ts`(新):`libraryAddRefused(error)` ——+ 纯判断,念哪句话只在这一处,不依赖页面就能测。插件自己的错误码走 `pluginImportErrorText`+ (它们自己的文案,绝不念线上英文原文),本仓自己抛的值走 `refusalText`(7.19 的规则)。+- `packages/web/src/features/plugins/plugins-page.tsx`:页面多一个 `libraryRefusal`(specifier ++ 句子)。`addPublishedToLibrary()` 不再把失败交给通知:开始一次尝试时清掉句子,失败时写上;上架+ 行经 `ModuleRow` 新增的 `refusal` 槽读到它。那一行从单行 flex 改成列 —— 原有的那一行加下面的+ 句子 —— 于是原因在卡片里,而不是在链接里。+- `packages/web/src/lib/strings{,-en}.ts`:一条新文案 `plugins.libraryAddRefused(reason)`。++## 测试++- `packages/web/test/library-add-refusal.test.ts`(新,5 条):插件自己的错误码念它自己的本地化+ 句子、不带线上英文原文;插件路由不拥有的码退回共享的表;本仓自己抛的值按原话念;无话可说时+ 退回通用句;用的是当前语言。+- `packages/web/e2e/plugin-library-add-refusal.spec.mjs`(新,真服务端 + 真浏览器,2 条):把取包+ 桩成 502,按架上自己的那个按钮 —— 句子出现在那一行里、通知区里没有它、行与可用的重试按钮都还+ 在、**七秒后**(超过错误通知活着的 6 秒)它仍在,下一次尝试把它清掉。第二条:409+ `plugin_exists` 仍弹出覆盖确认(带着插件名)且不画拒绝句;答复它会把同一个请求带上+ `overwrite: true` 重发。++## 兼容性++不碰接口、不引入新依赖、不改 Project 配置。成功路径、覆盖确认、以及标题行对话框自己的导入都没动。diff --git a/packages/web/e2e/plugin-library-add-refusal.spec.mjs b/packages/web/e2e/plugin-library-add-refusal.spec.mjsnew file mode 100644index 00000000..c05a631f--- /dev/null+++ b/packages/web/e2e/plugin-library-add-refusal.spec.mjs@@ -0,0 +1,175 @@+/**+ * Regression: adding a published plugin to the library from its row — the shelf's one verb —+ * keeps its reason IN that row when the write does not land, instead of in a toast that+ * dismisses itself after six seconds.+ *+ * The fetch writes nothing else: a refusal leaves the plugin exactly as it was (nowhere yet) and+ * leaves the same row standing with the same button, which is the retry. Nothing in the row was+ * typed either, so there is no field to put the reason under — it belongs under the row, and that+ * is where it is drawn now (`role="alert"`, danger colour, two lines, the whole sentence on+ * hover). A 409 is not a refusal: it is the overwrite question, which the row still raises.+ *+ * Both halves the test needs are the page's own contract with the server — the registry it reads+ * (a development data root publishes nothing, so without a fixture there is no shelf row) 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";++const BASE = process.env.BASE_URL;+const MOCK = process.env.MOCK_URL;++/** A published package the build does not ship and the library does not hold: a shelf row. */+const SPEC = "@adelie/probe-shelf";++/** The line this page draws for the code the refused write answers with. */+const REFUSED = "装入插件库失败:下载失败,请确认该地址可以访问。";++/** The registry entry, shaped like the server's own rows. */+const ENTRY = {+ name: SPEC,+ version: "2026.11.6.1",+ description: "A published plugin the shelf offers",+ authors: ["adelie"],+ license: "MIT",+ keywords: ["probe"],+ categories: ["tooling"],+ updatedAt: 1762387200,+};++/**+ * Sign in as the seeded administrator (the shelf's verb 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();+ return projectId;+}++/** The registry read: one entry nothing else on the page carries, so it lands on the shelf. */+async function stubRegistry(page) {+ await page.route("**/api/plugins/registry", async (route) => {+ if (route.request().method() !== "GET") return route.fallback();+ await route.fulfill({+ status: 200,+ contentType: "application/json",+ body: JSON.stringify({ plugins: [ENTRY] }),+ });+ });+}++/**+ * Take over the import the row sends. `state.mode` is "refuse", "exists" (the 409 that becomes a+ * question) or "land"; `state.posts` keeps every body so the tests can tell what was really sent.+ */+async function stubDownload(page, state) {+ const answer = (route, status, body) =>+ route.fulfill({+ status,+ contentType: "application/json",+ body: JSON.stringify(body),+ });+ await page.route("**/api/plugins/download", async (route) => {+ if (route.request().method() !== "POST") return route.fallback();+ state.posts.push(route.request().postDataJSON());+ if (state.mode === "refuse")+ return answer(route, 502, {+ error: { code: "download_failed", message: "the registry did not answer" },+ });+ if (state.mode === "exists")+ return answer(route, 409, {+ error: {+ code: "plugin_exists",+ message: `A user plugin named ${SPEC.split("/").pop()} is already installed.`,+ },+ });+ return answer(route, 200, {+ plugin: { name: SPEC.split("/").pop(), version: ENTRY.version, description: "" },+ });+ });+}++/** Open the page and unfold the shelf: a typed query opens both lists and narrows them here. */+async function openShelf(page) {+ await page.goto("/plugins");+ const search = page.getByPlaceholder("搜索插件");+ await expect(search).toBeVisible();+ await search.fill("probe-shelf");+ const row = page.getByRole("link", { name: new RegExp("probe-shelf") }).first();+ await expect(row).toBeVisible();+ return row;+}++/** The row's one verb, by the accessible name it carries for this specifier. */+const addVerb = (page) => page.getByRole("button", { name: `装入插件库 ${SPEC}` });++test("a refused add to the library keeps the reason in the row, past six seconds", async ({+ page,+}) => {+ await ready(page);+ const state = { posts: [], mode: "refuse" };+ await stubRegistry(page);+ await stubDownload(page, state);+ await openShelf(page);++ await addVerb(page).click();++ const line = page.getByRole("alert").filter({ hasText: "装入插件库失败" });+ await expect(line).toBeVisible();+ await expect(line).toHaveText(REFUSED);+ // The reason is the row's, not a notification's.+ await expect(page.getByRole("region", { name: "通知" })).not.toContainText(REFUSED);+ // The row and its retry are still there: a refusal changed nothing.+ await expect(addVerb(page)).toBeEnabled();++ // Past the six seconds an error notification lived: the sentence is still on screen.+ await page.waitForTimeout(7000);+ await expect(line).toBeVisible();+ await expect(line).toHaveText(REFUSED);++ // The retry is the same button, and it clears the reason of the attempt before it.+ state.mode = "land";+ await addVerb(page).click();+ await expect(page.getByRole("alert").filter({ hasText: "装入插件库失败" })).toHaveCount(0);+ expect(state.posts).toEqual([{ url: SPEC }, { url: SPEC }]);+});++test("a name already taken still asks before overwriting, and draws no refusal line", async ({+ page,+}) => {+ await ready(page);+ const state = { posts: [], mode: "exists" };+ await stubRegistry(page);+ await stubDownload(page, state);+ await openShelf(page);++ await addVerb(page).click();++ const dialog = page.getByRole("dialog", { name: "覆盖同名用户插件" });+ await expect(dialog).toBeVisible();+ await expect(dialog).toContainText("probe-shelf");+ await expect(page.getByRole("alert").filter({ hasText: "装入插件库失败" })).toHaveCount(0);++ // The answer re-sends the same request with `overwrite`, and the question closes once it lands.+ state.mode = "land";+ await dialog.getByRole("button", { name: "覆盖导入" }).click();+ await expect(dialog).toHaveCount(0);+ expect(state.posts).toEqual([{ url: SPEC }, { url: SPEC, overwrite: true }]);+});diff --git a/packages/web/src/features/plugins/library-add-refusal.ts b/packages/web/src/features/plugins/library-add-refusal.tsnew file mode 100644index 00000000..0c532a3f--- /dev/null+++ b/packages/web/src/features/plugins/library-add-refusal.ts@@ -0,0 +1,32 @@+/**+ * The sentence a published plugin's row keeps after its one verb — "add to the library" — was+ * refused, and why it stays in that row instead of in a notification.+ *+ * That verb fetches the package into the plugin library (the same npm import the header dialog+ * performs, `POST /api/plugins/download`) and writes nothing else: a refusal leaves the plugin+ * exactly as it was — not in the library, not on any Agent — and leaves the row standing in the+ * shelf with the same button, which is the retry. Nothing was typed into this row either, so+ * there is no field to look at: the reason is about the row itself. It used to arrive as a+ * notification, which floated over the list, dismissed itself after six seconds, and left a row+ * that read exactly as it did before the press; it is drawn in the row now, under its tags+ * (`ModuleRow`'s refusal slot), because that is where the retry is.+ *+ * The one answer that is not a refusal keeps its own place: a 409 `plugin_exists` is a question+ * (overwriting replaces every file of the user plugin, local edits included), and the row raises+ * the same overwrite confirmation the import dialog does. The page decides that before asking+ * this function, so it never sees that 409.+ *+ * Whose words: the plugin routes get their own copy (`pluginImportErrorText`, which falls back to+ * the shared code table), and a value this codebase raised itself — nothing the server answered —+ * is read through `refusalText`, the rule every refusal slot in the app follows (7.19).+ */+import { ApiError } from "../../api/client";+import { refusalText } from "../../lib/api-error";+import { S } from "../../lib/strings";+import { pluginImportErrorText } from "./plugin-import";++/** The line the published row keeps: the reason, wrapped in the row's own sentence. */+export function libraryAddRefused(error: unknown): string {+ const reason = error instanceof ApiError ? pluginImportErrorText(error) : refusalText(error);+ return S.plugins.libraryAddRefused(reason);+}diff --git a/packages/web/src/features/plugins/plugins-page.tsx b/packages/web/src/features/plugins/plugins-page.tsxindex 832bce3d..1c43012f 100644--- a/packages/web/src/features/plugins/plugins-page.tsx+++ b/packages/web/src/features/plugins/plugins-page.tsx@@ -113,6 +113,7 @@ import type { WriteOutcome } from "../models/write-outcome";import { PluginDetailModal } from "./plugin-detail";import { PluginImportActions } from "./plugin-import-dialog";import { pluginImportErrorText, pluginNameFromError } from "./plugin-import";+import { libraryAddRefused } from "./library-add-refusal";import { SettingsDialog } from "../settings/settings-dialog";import { formatRelativeDate } from "../../lib/format";import { SkillTile } from "../skills/skill-icon-view";@@ -391,6 +392,15 @@ export function PluginsPage() {specifier: string;name: string;} | null>(null);+ /**+ * The server's words for the last "add to the library" it refused, and the row they belong to.+ * It has to outlive a toast: the write changed nothing, so that row is still on the shelf with+ * the same button, and the sentence belongs in it (library-add-refusal.ts).+ */+ const [libraryRefusal, setLibraryRefusal] = useState<{+ specifier: string;+ reason: string;+ } | null>(null);/*** Open the confirmation for one module plugin change, without the previous refusal: that@@ -782,9 +792,15 @@ export function PluginsPage() {* A 409 (the name is taken) opens the same overwrite question the dialog asks for its own* imports rather than a toast: it is a question, and the answer resends the request with* `overwrite`.+ *+ * Any other refusal is drawn IN this row (library-add-refusal.ts): the fetch wrote nothing, so+ * the row is still here with the same button, and a notification would take the reason away+ * after six seconds while the retry stayed on screen. One attempt, one reason: starting the+ * next one clears it.*/const addPublishedToLibrary = async (specifier: string, overwrite = false) => {setPublishing(specifier);+ setLibraryRefusal(null);try {const res = await api.importPluginFromUrl({url: specifier,@@ -801,7 +817,7 @@ export function PluginsPage() {});} else {setOverwriteImport(null);- toastError(pluginImportErrorText(e));+ setLibraryRefusal({ specifier, reason: libraryAddRefused(e) });}} finally {setPublishing(null);@@ -883,6 +899,7 @@ export function PluginsPage() {state="none"shipped={false}installLabel={S.plugins.addToLibrary}+ refusal={libraryRefusal?.specifier === row.specifier ? libraryRefusal.reason : undefined}busy={publishing === row.specifier}blocked={publishing !== null && publishing !== row.specifier}onInstall={isAdmin ? () => void addPublishedToLibrary(row.specifier) : null}@@ -2238,6 +2255,7 @@ function ModuleRow({shipped,onlyOn,removeBlocked,+ refusal,busy,blocked,installLabel,@@ -2255,6 +2273,12 @@ function ModuleRow({onlyOn?: string[];/** Why Remove is unavailable in this view, when it is. */removeBlocked?: string;+ /**+ * Why the last write this row offers was refused. It is drawn in the row because a refusal+ * changes nothing: the row and its button are what the reader retries from, and a sentence+ * that dismisses itself would be gone before the second attempt.+ */+ refusal?: string;/** This row's own install or removal is running. */busy: boolean;/** Another row's is: one at a time, so the rest are held rather than queued. */@@ -2357,53 +2381,70 @@ function ModuleRow({</>);return (- <div className="flex items-center gap-3 rounded-md p-4 transition-colors hover:bg-gray-100/70 dark:hover:bg-gray-800/60">- {entry !== undefined ? (- <Link to={`/plugins/registry/${specifier}`} className="min-w-0 flex-1">- {body}- </Link>- ) : (- <div className="min-w-0 flex-1">{body}</div>- )}- {/* The verb, in the library card's shape: one square light icon button, its copy in- aria-label and title. While it runs, a spinner stands in for the glyph. */}- <div className="flex shrink-0 items-center justify-center gap-1.5">- {state === "none"- ? onInstall !== null && (- <Button- size="sm"- className="h-8 w-8 shrink-0 justify-center p-0"- aria-label={`${busy ? S.plugins.installing : installText} ${specifier}`}- aria-busy={busy}- title={busy ? S.plugins.installing : installText}- disabled={busy || blocked}- onClick={onInstall}- >- {busy ? (- <StatusIcon state="running" />- ) : (- <GlyphIcon d={INSTALL_ICON} size={ICON_SIZE.iconButton} />- )}- </Button>- )- : onRemove !== null && (- <Button- size="sm"- className="h-8 w-8 shrink-0 justify-center p-0"- aria-label={`${S.plugins.uninstall} ${specifier}`}- aria-busy={busy}- title={removeBlocked ?? S.plugins.uninstall}- disabled={busy || blocked || removeBlocked !== undefined}- onClick={onRemove}- >- {busy ? (- <StatusIcon state="running" />- ) : (- <GlyphIcon d={ICONS.trash} size={ICON_SIZE.iconButton} />- )}- </Button>- )}+ <div className="rounded-md transition-colors hover:bg-gray-100/70 dark:hover:bg-gray-800/60">+ <div className="flex items-center gap-3 p-4">+ {entry !== undefined ? (+ <Link to={`/plugins/registry/${specifier}`} className="min-w-0 flex-1">+ {body}+ </Link>+ ) : (+ <div className="min-w-0 flex-1">{body}</div>+ )}+ {/* The verb, in the library card's shape: one square light icon button, its copy in+ aria-label and title. While it runs, a spinner stands in for the glyph. */}+ <div className="flex shrink-0 items-center justify-center gap-1.5">+ {state === "none"+ ? onInstall !== null && (+ <Button+ size="sm"+ className="h-8 w-8 shrink-0 justify-center p-0"+ aria-label={`${busy ? S.plugins.installing : installText} ${specifier}`}+ aria-busy={busy}+ title={busy ? S.plugins.installing : installText}+ disabled={busy || blocked}+ onClick={onInstall}+ >+ {busy ? (+ <StatusIcon state="running" />+ ) : (+ <GlyphIcon d={INSTALL_ICON} size={ICON_SIZE.iconButton} />+ )}+ </Button>+ )+ : onRemove !== null && (+ <Button+ size="sm"+ className="h-8 w-8 shrink-0 justify-center p-0"+ aria-label={`${S.plugins.uninstall} ${specifier}`}+ aria-busy={busy}+ title={removeBlocked ?? S.plugins.uninstall}+ disabled={busy || blocked || removeBlocked !== undefined}+ onClick={onRemove}+ >+ {busy ? (+ <StatusIcon state="running" />+ ) : (+ <GlyphIcon d={ICONS.trash} size={ICON_SIZE.iconButton} />+ )}+ </Button>+ )}+ </div></div>+ {/* A write this row offered that did not land: the row still stands, its button is the+ retry, so the reason sits under the row rather than in a notification that dismisses+ itself. Outside the link on purpose — the row's body is a link to the registry page, and+ clicking a reason should not take the reader somewhere else. */}+ {refusal !== undefined && (+ <p+ role="alert"+ data-testid="row-refusal"+ data-tooltip={refusal}+ data-tooltip-content="text"+ className={`-mt-1 px-4 pb-3 line-clamp-2 break-words text-xs ${toneInk.danger}`}+ >+ {refusal}+ </p>+ )}</div>);}diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.tsindex 43fb1e99..45cc51bd 100644--- a/packages/web/src/lib/strings-en.ts+++ b/packages/web/src/lib/strings-en.ts@@ -2889,6 +2889,11 @@ export const en: Strings = {* success toast, the overwrite question).*/addToLibrary: "Add to the library",+ /**+ * Why that verb did not land, drawn in the row itself (library-add-refusal.ts): the write+ * changes nothing on a refusal, so the row and its button are the retry.+ */+ libraryAddRefused: (reason: string): string => `Could not add it to the library: ${reason}`,pluginCount: (n: number): string => (n === 1 ? "1 plugin" : `${n} plugins`),searchPlaceholder: "Search plugins",/** Section labels of the plugin detail Modal. */diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.tsindex da2526bd..4436bade 100644--- a/packages/web/src/lib/strings.ts+++ b/packages/web/src/lib/strings.ts@@ -2937,6 +2937,11 @@ export const zh = {* success toast, the overwrite question).*/addToLibrary: "装入插件库",+ /**+ * Why that verb did not land, drawn in the row itself (library-add-refusal.ts): the write+ * changes nothing on a refusal, so the row and its button are the retry.+ */+ libraryAddRefused: (reason: string): string => `装入插件库失败:${reason}`,/** Plugin count in the group header (small text to the right of the category name). */pluginCount: (n: number): string => `${n} 个插件`,/** Search box of the create dialog's plugin picker. */diff --git a/packages/web/test/library-add-refusal.test.ts b/packages/web/test/library-add-refusal.test.tsnew file mode 100644index 00000000..f95fb196--- /dev/null+++ b/packages/web/test/library-add-refusal.test.ts@@ -0,0 +1,57 @@+/**+ * A published plugin's row after its "add to the library" write was refused+ * (src/features/plugins/library-add-refusal.ts): which words the row keeps, and whose.+ *+ * The write fetches the package into the plugin library and changes nothing else, so a refusal+ * leaves the same row with the same button — that is where the sentence belongs, and it is the+ * whole reason this test exists: a toast would be gone after six seconds while the retry stayed+ * on screen. The 409 that turns into a question never reaches here (the page asks first).+ */+import { afterEach, describe, expect, it } from "vitest";+import { ApiError } from "../src/api/client";+import { en as EN } from "../src/lib/strings-en";+import { S, setActiveStrings, zh as ZH } from "../src/lib/strings";+import { libraryAddRefused } from "../src/features/plugins/library-add-refusal";++afterEach(() => {+ setActiveStrings(ZH);+});++describe("libraryAddRefused", () => {+ it("wraps the plugin routes' own words for the codes they answer with", () => {+ // `download_failed` has copy of its own in S.plugins.importErrors — the server's message is+ // English-only and the interface may not be.+ const line = libraryAddRefused(+ new ApiError(502, "download_failed", "RAW ENGLISH SERVER MESSAGE"),+ );+ expect(line).toBe(S.plugins.libraryAddRefused(S.plugins.importErrors.download_failed));+ expect(line).not.toContain("RAW ENGLISH");+ });++ it("falls back to the shared code table for a code the plugin routes do not own", () => {+ const line = libraryAddRefused(new ApiError(500, "internal", "RAW ENGLISH"));+ expect(line).toBe(S.plugins.libraryAddRefused(S.errors.byCode["internal"] as string));+ });++ it("shows an error the client raised itself as it wrote it", () => {+ // `refusalText`'s rule: only an ApiError is read through a code table.+ expect(libraryAddRefused(new TypeError("Failed to fetch"))).toBe(+ S.plugins.libraryAddRefused("Failed to fetch"),+ );+ expect(libraryAddRefused(undefined)).toBe(S.plugins.libraryAddRefused(S.common.unknownError));+ });++ it("names the verb the row offers, so the sentence says which write failed", () => {+ // The row's verb is "add to the library", not the Project's install: the reason has to+ // match the button above it.+ expect(libraryAddRefused(undefined)).toContain(S.plugins.addToLibrary);+ });++ it("speaks the interface language", () => {+ setActiveStrings(EN);+ expect(libraryAddRefused(new ApiError(502, "download_failed", "raw"))).toBe(+ S.plugins.libraryAddRefused(S.plugins.importErrors.download_failed),+ );+ expect(S.plugins.libraryAddRefused("x").toLowerCase()).toContain("add it to the library");+ });+});