Skip to content

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

fix(web): MCP 卡片的「测试连接」被拒时,原因留在按钮下面,不再只活六秒

lmliheng6a663310267b
diff --git a/changelog/unreleased/2026-11-04-mcp-test-refusal.md b/changelog/unreleased/2026-11-04-mcp-test-refusal.md
new file mode 100644
index 00000000..602aaabb
--- /dev/null
+++ b/changelog/unreleased/2026-11-04-mcp-test-refusal.md
@@ -0,0 +1,58 @@
+# A refused MCP "test connection" says so under the button, not in a six-second toast
+
+- **Date:** 2026-11-04
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[中文](2026-11-04-mcp-test-refusal.zh.md)
+
+Agent settings → Tools → MCP Server's edit card has a "test connection" button that runs the form's
+current (still unsaved) values. Every way that probe fails is a sentence the reader has to keep
+while fixing the form: a command that is not on PATH, a URL that times out, a server whose stderr
+tail names the certificate. All of them arrived as a notification only — it sits over the card and
+dismisses itself after six seconds, while the card itself did not change one character: six seconds
+later nothing on screen said the button had been pressed.
+
+The sentence is now drawn in the card, directly under the button (`role="alert"`, danger colour,
+two lines at most with the whole text on hover), and it stays until the form is edited or the next
+probe starts — those fields are the connection it describes, and the same button is the retry. A
+probe that *connects* keeps its toast with the tool count and latency (the models card's idiom): it
+leaves nothing behind that needs explaining.
+
+## Details
+
+- `packages/web/src/features/agents/mcp-test-refusal.ts` (new, 44 lines): `mcpTestRefusal(answer)`
+ turns one probe's answer into that line, or `null` when it connected. The three shapes of an
+ answer each take their words by the existing rule (`refusalText`): the route's own detail (spawn
+ error, timeout, stderr tail) travels verbatim; a failed request reads its code's localized
+ sentence; an answer carrying no detail at all falls back to the generic text — an empty line
+ under the button would say less than the toast it replaced.
+- `packages/web/src/features/agents/mcp-servers-section.tsx`: one `testRefusal` state, cleared when
+ a probe starts (it is that attempt's answer, not the card's standing state) and set when one is
+ refused; the line is drawn under the row the button lives in. Any edit to the form, and opening
+ another card, clears it, because the probe sent exactly those values. The connecting toast stays
+ as it was; the now-unused `toastError` import goes.
+- `packages/web/src/lib/strings{,-en}.ts`: **no new strings** — it reuses `mcpTestFail(detail)`
+ ("Connection failed: …"), since the form in the card is the server being described.
+
+## Tests
+
+- `packages/web/test/mcp-test-refusal.test.ts` (new, 6 cases): a connecting answer leaves nothing
+ (including "connected but exposed no tools") / the route's detail travels verbatim / a detail-less
+ refusal falls back to the generic text / a failed request reads its code's localized sentence (the
+ raw English never reaches the screen) / an error the client raised itself keeps its own words /
+ the active language.
+- `packages/web/e2e/mcp-test-refusal.spec.mjs` (new, two cases on a real server): the probe route is
+ stubbed at `page.route` (a refusal, then the connecting answer once lifted). Case ①: after the
+ refusal the line is in the card, the notification region holds nothing to dismiss, the card draws
+ it exactly once, the probe request carried the form's two unsaved values, the form itself is
+ untouched, and seven seconds later the line is still there. Case ②: editing one field drops the
+ sentence; the same button retries and goes through — no line comes back, the connecting
+ notification carries the tool count and latency, and the second probe travelled to the edited URL.
+
+## Compatibility
+
+- No interface, request or storage change: the same `POST …/agents/<agent>/config/mcp-test`, which
+ saves nothing. Only where a refused one is drawn has moved — from a notification alone to a line
+ under the button that outlives it.
diff --git a/changelog/unreleased/2026-11-04-mcp-test-refusal.zh.md b/changelog/unreleased/2026-11-04-mcp-test-refusal.zh.md
new file mode 100644
index 00000000..ffbd2464
--- /dev/null
+++ b/changelog/unreleased/2026-11-04-mcp-test-refusal.zh.md
@@ -0,0 +1,47 @@
+# MCP Server 弹窗的「测试连接」被拒时,原因留在按钮下面,不再只活六秒
+
+- **日期:** 2026-11-04
+- **类型:** fix
+- **范围:** `web`
+- **破坏性:** 无
+
+[English](2026-11-04-mcp-test-refusal.md)
+
+Agent 设置 → 工具 → MCP Server 的编辑卡片里那颗「测试连接」,跑的是表单当前(尚未保存的)值。
+每一种失败都是读者改表单时要一直看着的那句话:命令不在 PATH 上、地址超时、server 的 stderr
+尾巴里写着证书问题。这些此前都只落进一条通知 —— 它盖在卡片上方、六秒后自行消失,而卡片本身
+一个字都没变:六秒之后,屏上没有任何东西说明这颗按钮被按过。
+
+现在这句话画在卡片里、按钮正下方(`role="alert"`、危险色、限两行、整句挂悬停),留到表单被
+编辑或下一次测试开始为止 —— 表单的那几个字段正是它描述的连接,而同一颗按钮就是重试。连接成功的
+那次仍然是一条带工具数与耗时的通知(模型库那张卡片的写法):它没有留下需要解释的东西。
+
+## 细节
+
+- `packages/web/src/features/agents/mcp-test-refusal.ts`(新,44 行):`mcpTestRefusal(answer)`
+ 把一次探测的答复变成那句话,连接成功给 `null`。三种答复各按既有规则取词
+ (`refusalText`):路由自己的细节(spawn 错误 / 超时 / stderr 尾巴)原样带过去;请求本身失败
+ 走它的错误码对应的本地化句子;路由答复里连细节都没有时退回通用那句 —— 按钮下面一行空白比它
+ 取代的那条通知说得更少。
+- `packages/web/src/features/agents/mcp-servers-section.tsx`:一个 `testRefusal` 状态 —— 探测开始
+ 时清掉(那是上一次的答复)、被拒时写上;句子画在「测试连接」按钮那一行的下面。表单的任何一次
+ 编辑、以及打开另一张卡片都清掉它,因为探测送的正是这份表单的全部值。连接成功那句通知与原样
+ 保留;`toastError` 的导入随之去掉。
+- `packages/web/src/lib/strings{,-en}.ts`:**没有新文案** —— 复用 `mcpTestFail(detail)`
+ (「连接失败:…」),卡片里那张表单就是被说的那个 server。
+
+## 测试
+
+- `packages/web/test/mcp-test-refusal.test.ts`(新,6 条):连接成功不留话(含「连上但一个工具都
+ 没有」)/ 路由的细节原样带过去 / 没有细节时退回通用那句 / 请求失败按错误码取本地化句子(原始
+ 英文不出现在屏上)/ 客户端自己抛的错保留自己的话 / 跟着界面语言走。
+- `packages/web/e2e/mcp-test-refusal.spec.mjs`(新,真服务端两条):探测路由桩在 `page.route` 上
+ (500 → 后放行的成功答复)。用例①:被拒后句子在卡片里、通知区没有可点条目、卡片里只有这一条,
+ 探测请求带的是表单里那两个未保存的值,表单原样不动,七秒后句子仍在。用例②:改一个字段就清掉
+ 那句话,同一颗按钮重试走通 —— 句子不再出现、成功那条通知带上工具数与耗时,第二次探测发往改过的
+ 地址。
+
+## 兼容
+
+- 接口、请求与存储都没变:还是同一次 `POST …/agents/<agent>/config/mcp-test`,不写任何东西。
+ 改变的只有被拒之后画在哪里 —— 从「只有一条通知」到「按钮下面多一条活得下去的说法」。
diff --git a/packages/web/e2e/mcp-test-refusal.spec.mjs b/packages/web/e2e/mcp-test-refusal.spec.mjs
new file mode 100644
index 00000000..8fd022db
--- /dev/null
+++ b/packages/web/e2e/mcp-test-refusal.spec.mjs
@@ -0,0 +1,152 @@
+/**
+ * Regression: the MCP server modal's "test connection" button says why a probe did not get through
+ * — in the card, under that button — instead of leaving the form exactly as it was with the reason
+ * in a notification that dismissed itself after six seconds.
+ *
+ * The button runs the form's unsaved values through the server's connect-and-discover route and
+ * saves nothing, so every failed probe is a form that looks untouched plus one sentence the reader
+ * has to keep while fixing it (a command that is not on PATH, a URL that times out, a stderr tail
+ * naming a certificate). Six seconds later that sentence used to be gone, and nothing on the card
+ * said the button had been pressed at all.
+ *
+ * The probe route is stubbed rather than travelled: what this spec is about is what the page does
+ * with the answer, and a real probe would spawn a child process for the test's own curiosity. The
+ * refusal is the app's own sentence for the code the server would send (`internal`), and the
+ * connecting answer is the shape the route sends (a tool list plus a latency).
+ */
+import { test, expect } from "@playwright/test";
+import { provisionAndLogin } from "./auth.mjs";
+
+const BASE = process.env.BASE_URL;
+const MOCK = process.env.MOCK_URL;
+const P = "password123";
+const AGENT = "default_agent";
+const NAME = "probe-mcp";
+
+/** The line the card draws for a refused probe: the sentence's lead-in plus the code's words. */
+const REFUSED_LINE = "连接失败:服务器内部错误,请稍后重试。";
+
+/** Provision the user, give the Project a model (the onboarding overlay covers the page without one), and put one MCP server on the Agent. */
+async function projectWithServer(page, user) {
+ await provisionAndLogin(page.request, user, P);
+ const projectId = (await (await page.request.get(`${BASE}/api/projects`)).json()).projects[0]
+ .projectId;
+ const models = 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(models.ok(), "put models").toBeTruthy();
+ const seeded = await page.request.put(
+ `${BASE}/api/projects/${projectId}/agents/${AGENT}/config`,
+ {
+ data: {
+ config: { mcpServers: [{ name: NAME, config: { url: "https://example.com/mcp" } }] },
+ },
+ },
+ );
+ expect(seeded.ok(), "seed the MCP server").toBeTruthy();
+}
+
+/**
+ * Take over the probe route: every POST is counted (the body, so the spec can check it carried the
+ * form's values), answered with the server's refusal until `state.refuse` is cleared, and then
+ * with a connecting answer of the shape the route sends.
+ */
+async function stubProbe(page, state) {
+ await page.route("**/api/projects/*/agents/*/config/mcp-test", async (route) => {
+ if (route.request().method() !== "POST") return route.fallback();
+ state.seen.push(route.request().postDataJSON());
+ if (state.refuse) {
+ await route.fulfill({
+ status: 500,
+ contentType: "application/json",
+ body: JSON.stringify({ error: { code: "internal", message: "RAW ENGLISH MESSAGE" } }),
+ });
+ return;
+ }
+ await route.fulfill({
+ status: 200,
+ contentType: "application/json",
+ body: JSON.stringify({ ok: true, tools: ["mcp__probe-mcp__ping"], latencyMs: 1200 }),
+ });
+ });
+}
+
+/** The edit card, opened the way a person opens it: the row's 编辑 button. */
+async function openEditCard(page) {
+ await page.goto(`/agents/${AGENT}?tab=tools`);
+ const row = page.getByRole("row", { name: new RegExp(NAME) });
+ await expect(row).toBeVisible();
+ await row.getByRole("button", { name: "编辑" }).click();
+ const card = page.getByRole("dialog", { name: "编辑 MCP Server" });
+ await expect(card).toBeVisible();
+ return card;
+}
+
+/** The notification region: a refusal must not be announced there (that is the old toast). */
+const notifications = (page) => page.getByRole("region", { name: "通知" });
+
+test("a refused probe keeps the reason under the button, and only there", async ({ page }) => {
+ await projectWithServer(page, "r189refuse");
+ const state = { seen: [], refuse: true };
+ await stubProbe(page, state);
+
+ const card = await openEditCard(page);
+ await card.getByRole("button", { name: "测试连接" }).click();
+
+ // The sentence is in the card, under the button that asked, and it is not a toast: the
+ // notification region holds nothing to dismiss, and the card draws it exactly once.
+ await expect(card.getByRole("alert")).toHaveText(REFUSED_LINE);
+ await expect(notifications(page).getByRole("button")).toHaveCount(0);
+ await expect(card.getByRole("alert")).toHaveCount(1);
+
+ // The probe carried the form's own values — the unsaved ones — as the modal promises.
+ expect(state.seen).toHaveLength(1);
+ expect(state.seen[0].config.url).toBe("https://example.com/mcp");
+ expect(state.seen[0].name).toBe(NAME);
+
+ // The form is untouched: nothing was saved, and the card still says what it said.
+ await expect(card.getByLabel("url")).toHaveValue("https://example.com/mcp");
+ // By placeholder rather than by label: the name field's accessible name carries its hint
+ // ("name 工具名前缀:mcp__<name>__<tool…"), which also matches the headers textarea's.
+ await expect(card.getByPlaceholder("filesystem")).toHaveValue(NAME);
+
+ // Six seconds is how long a toast lives; this line has to still be there after it.
+ await page.waitForTimeout(7_000);
+ await expect(card.getByRole("alert")).toHaveText(REFUSED_LINE);
+});
+
+test("an edit drops the sentence, and the same button is the retry", async ({ page }) => {
+ await projectWithServer(page, "r189retry");
+ const state = { seen: [], refuse: true };
+ await stubProbe(page, state);
+
+ const card = await openEditCard(page);
+ await card.getByRole("button", { name: "测试连接" }).click();
+ await expect(card.getByRole("alert")).toHaveText(REFUSED_LINE);
+
+ // The probe sent exactly the values that were on screen, so changing one of them makes the
+ // sentence describe a connection nothing asked about any more.
+ await card.getByLabel("url").fill("https://other.example.com/mcp");
+ await expect(card.getByRole("alert")).toHaveCount(0);
+
+ // Same button, second press: this time the probe connects, so the sentence stays away and the
+ // numbers arrive as the toast every connecting probe uses.
+ state.refuse = false;
+ await card.getByRole("button", { name: "测试连接" }).click();
+ await expect(notifications(page).getByText("连接成功,发现 1 个工具(1.2s)")).toBeVisible();
+ await expect(card.getByRole("alert")).toHaveCount(0);
+ expect(state.seen).toHaveLength(2);
+ // The second probe travelled to the edited URL, not the one the first sentence was about.
+ expect(state.seen[1].config.url).toBe("https://other.example.com/mcp");
+});
diff --git a/packages/web/src/features/agents/mcp-servers-section.tsx b/packages/web/src/features/agents/mcp-servers-section.tsx
index 0ff0aa3e..bc387806 100644
--- a/packages/web/src/features/agents/mcp-servers-section.tsx
+++ b/packages/web/src/features/agents/mcp-servers-section.tsx
@@ -7,8 +7,9 @@
* inside the modal instead of half-applying.
*
* Connectivity testing mirrors the models page: the modal carries a standalone
- * "test connection" button in a top action row (result as a toast, tool count +
- * latency — the models dialog idiom), and the section header offers a bulk test that
+ * "test connection" button in a top action row (a connecting answer pops as a toast with the
+ * tool count and latency — the models dialog idiom — while a refused probe keeps its sentence
+ * under that button, see `mcp-test-refusal.ts`), and the section header offers a bulk test that
* probes every configured server sequentially behind a confirm dialog, writing a
* tone-colored badge onto each row as its result lands (the group speed-test idiom).
*
@@ -45,7 +46,6 @@ import {
TableHeaderCell,
TableRow,
Textarea,
- toastError,
toastSuccess,
} from "@adelie/ui";
import type { OptionMenuChoice } from "@adelie/ui";
@@ -68,6 +68,7 @@ import {
type McpTransportKind,
} from "./mcp-servers-form";
import { flippedEnabled, toggleRefusalFor, type McpToggleRefusal } from "./mcp-servers-toggle";
+import { mcpTestRefusal } from "./mcp-test-refusal";
import { toneInk } from "../../lib/tone";
/** Maps a validation error code to its localized message. */
@@ -177,8 +178,13 @@ export function McpServersSection({
// taken from may have moved, and the sentence names a position in it.
const [toggleRefusal, setToggleRefusal] = useState<McpToggleRefusal | null>(null);
// Connectivity probe: runs the current form state through POST /config/mcp-test
- // (server-side connect + discovery, nothing saved); the result pops as a toast.
+ // (server-side connect + discovery, nothing saved). A probe that connects pops as a toast; one
+ // that does not leaves its sentence under the button that asked (see `mcp-test-refusal.ts`),
+ // because a failed probe changes nothing else on the card — without that line the form looks
+ // exactly as it did before the press. Cleared by every edit to the form (the probe sent exactly
+ // these values) and at the start of the next probe.
const [testing, setTesting] = useState(false);
+ const [testRefusal, setTestRefusal] = useState<string | null>(null);
// Bulk test: confirm dialog open / run in progress / per-row results keyed by server name.
const [testAllOpen, setTestAllOpen] = useState(false);
const [testAllRunning, setTestAllRunning] = useState(false);
@@ -243,6 +249,7 @@ export function McpServersSection({
setEditIndex(null);
setFieldErrors({});
setModalError(null);
+ setTestRefusal(null);
};
const openEdit = (index: number) => {
@@ -252,6 +259,7 @@ export function McpServersSection({
setEditIndex(index);
setFieldErrors({});
setModalError(null);
+ setTestRefusal(null);
};
const closeModal = () => {
@@ -263,6 +271,9 @@ export function McpServersSection({
setForm((prev) => (prev ? { ...prev, ...patch } : prev));
setFieldErrors({});
setModalError(null);
+ // The probe sent the whole form, so any edit makes its sentence describe values that are no
+ // longer on screen.
+ setTestRefusal(null);
};
/** Probes the current form state (unsaved values on purpose: verify before persisting). */
@@ -273,13 +284,16 @@ export function McpServersSection({
setFieldErrors(built.errors);
return;
}
+ // This probe's answer replaces the last one's (see the state's comment).
+ setTestRefusal(null);
setTesting(true);
try {
const res = await api.testAgentMcpServer(projectId, agentId, built.server);
- if (res.ok) toastSuccess(S.agent.mcpTestOk(res.tools?.length ?? 0, res.latencyMs));
- else toastError(S.agent.mcpTestFail(res.error ?? S.common.unknownError));
+ const refusal = mcpTestRefusal({ result: res });
+ if (refusal === null) toastSuccess(S.agent.mcpTestOk(res.tools?.length ?? 0, res.latencyMs));
+ else setTestRefusal(refusal);
} catch (e) {
- toastError(S.agent.mcpTestFail(apiErrorText(e)));
+ setTestRefusal(mcpTestRefusal({ result: null, error: e }));
} finally {
setTesting(false);
}
@@ -524,8 +538,8 @@ export function McpServersSection({
</p>
</div>
{/* Entry-level action right under the tabs — the models dialog idiom: a standalone
- test button, enabled once the target (command / url) is filled in; the result
- pops as a toast. */}
+ test button, enabled once the target (command / url) is filled in; a connecting
+ answer pops as a toast, a refused one stays below (see `mcp-test-refusal.ts`). */}
<div className="flex flex-wrap items-center gap-2">
<Button
size="sm"
@@ -535,6 +549,19 @@ export function McpServersSection({
{testing ? S.agent.mcpTesting : S.agent.mcpTest}
</Button>
</div>
+ {testRefusal !== null && (
+ // Under the button that asked, not over the card: `line-clamp-2` keeps a long
+ // stderr tail from heightening the modal, and the whole sentence is on hover, the
+ // way every other refusal slot in the app carries its longer form.
+ <p
+ role="alert"
+ data-tooltip={testRefusal}
+ data-tooltip-content="text"
+ className={`line-clamp-2 break-words text-xs ${toneInk.danger}`}
+ >
+ {testRefusal}
+ </p>
+ )}
<Input
size="sm"
label={S.agent.mcpName}
diff --git a/packages/web/src/features/agents/mcp-test-refusal.ts b/packages/web/src/features/agents/mcp-test-refusal.ts
new file mode 100644
index 00000000..d63bb295
--- /dev/null
+++ b/packages/web/src/features/agents/mcp-test-refusal.ts
@@ -0,0 +1,44 @@
+/**
+ * The MCP server modal's "test connection" button: the sentence a probe that did not get through
+ * leaves under it, and why that sentence is a line in the card rather than a toast.
+ *
+ * The button runs the form's current — still unsaved — values through the server's
+ * connect-and-discover route. Every way a probe can fail is something the reader has to keep while
+ * fixing the form: a stdio command that is not on PATH, a URL that times out, a server whose
+ * stderr tail names the certificate. All of them used to arrive as one notification, which sits
+ * over the card and dismisses itself after six seconds — the card then looked exactly as it did
+ * before the button was pressed, with the one sentence that explains the failure gone.
+ *
+ * So the refusal is drawn inside the modal, under the button that asked, and it stays until the
+ * form is edited or the next probe starts: the fields it describes are the ones the reader is
+ * about to change, and the button is the retry.
+ *
+ * A probe that *connects* keeps the toast (tool count + latency, the models dialog idiom). That
+ * outcome leaves nothing behind to explain — no field is wrong, and its numbers are not something
+ * the form has to be read against — so only one of the two answers has a place on the card.
+ */
+import type { McpServerTestResponse } from "@adelie/server/api";
+import { S } from "../../lib/strings";
+import { refusalText } from "../../lib/api-error";
+
+/** What one press of the button came back with. */
+export interface McpTestAnswer {
+ /** The route's own answer, or `null` when the request itself failed (login gone, server down). */
+ readonly result: McpServerTestResponse | null;
+ /** Why the request failed; read only when `result` is `null`. */
+ readonly error?: unknown;
+}
+
+/**
+ * The line the modal draws under the test button, or `null` when the probe connected.
+ *
+ * Three shapes reach it, and each keeps the rule the rest of the app's refusal slots follow
+ * (`refusalText`): the route's answer carries its own detail (spawn error, timeout, stderr tail),
+ * a failed request carries its code's sentence, and an answer with no detail at all falls back to
+ * the generic text — an empty line under the button would say less than the toast it replaced.
+ */
+export function mcpTestRefusal(answer: McpTestAnswer): string | null {
+ if (answer.result === null) return S.agent.mcpTestFail(refusalText(answer.error));
+ if (answer.result.ok) return null;
+ return S.agent.mcpTestFail(answer.result.error ?? S.common.unknownError);
+}
diff --git a/packages/web/test/mcp-test-refusal.test.ts b/packages/web/test/mcp-test-refusal.test.ts
new file mode 100644
index 00000000..6f860e78
--- /dev/null
+++ b/packages/web/test/mcp-test-refusal.test.ts
@@ -0,0 +1,71 @@
+/**
+ * The MCP server modal's "test connection" line (src/features/agents/mcp-test-refusal.ts): which
+ * answers leave a sentence under the button, and whose words that sentence uses.
+ *
+ * A failed probe changes nothing else on the card — the form keeps every value it was asked with —
+ * so this line is the only thing that accounts for the failure once the six-second toast is gone.
+ * The cases below are the three shapes the answer comes in plus the two languages, and the rule
+ * that matters most: a probe that connected leaves nothing behind.
+ */
+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 { mcpTestRefusal } from "../src/features/agents/mcp-test-refusal";
+
+afterEach(() => {
+ setActiveStrings(ZH);
+});
+
+describe("mcpTestRefusal", () => {
+ it("leaves no line when the probe connected", () => {
+ expect(mcpTestRefusal({ result: { ok: true, tools: ["mcp__fs__read"], latencyMs: 120 } })).toBe(
+ null,
+ );
+ // A server that exposed nothing still connected — the toast says so, and there is no failure
+ // for the card to keep.
+ expect(mcpTestRefusal({ result: { ok: true, tools: [], latencyMs: 8 } })).toBeNull();
+ });
+
+ it("carries the route's own detail verbatim, behind the sentence's lead-in", () => {
+ // What the route sends on a stdio spawn failure: its own words, sometimes a stderr tail.
+ const detail = "spawn npx ENOENT · stderr: cannot find module";
+ expect(mcpTestRefusal({ result: { ok: false, error: detail } })).toBe(
+ S.agent.mcpTestFail(detail),
+ );
+ });
+
+ it("still says something when the route refused without a detail", () => {
+ // An empty line under the button would say less than the toast it replaced.
+ expect(mcpTestRefusal({ result: { ok: false } })).toBe(
+ S.agent.mcpTestFail(S.common.unknownError),
+ );
+ });
+
+ it("reads a failed request through its code, so the line is the localized one", () => {
+ const refused = mcpTestRefusal({
+ result: null,
+ error: new ApiError(500, "internal", "RAW ENGLISH SERVER MESSAGE"),
+ });
+ expect(refused).toBe(S.agent.mcpTestFail(S.errors.byCode["internal"] as string));
+ expect(refused).not.toContain("RAW ENGLISH SERVER MESSAGE");
+ });
+
+ it("keeps the message of an error the client itself raised", () => {
+ // `refusalText`'s rule: only an ApiError goes through the code table; anything else with
+ // something to say is shown as it is (a dropped connection, say), not as "unknown".
+ expect(mcpTestRefusal({ result: null, error: new Error("network down") })).toBe(
+ S.agent.mcpTestFail("network down"),
+ );
+ expect(mcpTestRefusal({ result: null, error: undefined })).toBe(
+ S.agent.mcpTestFail(S.common.unknownError),
+ );
+ });
+
+ it("follows the interface language", () => {
+ setActiveStrings(EN);
+ expect(mcpTestRefusal({ result: { ok: false, error: "spawn npx ENOENT" } })).toBe(
+ "Connection failed: spawn npx ENOENT",
+ );
+ });
+});