A local-first multi-agent app development platform, built on PenguinHarness
fix(web): 模型库弹窗的「测试连通性」被拒时,原因留在按钮下面,不再只活六秒
lmliheng08a40a77fabf
diff --git a/changelog/unreleased/2026-11-04-model-test-refusal.md b/changelog/unreleased/2026-11-04-model-test-refusal.mdnew file mode 100644index 00000000..95ec7a31--- /dev/null+++ b/changelog/unreleased/2026-11-04-model-test-refusal.md@@ -0,0 +1,60 @@+# A refused model "test connection" says so under the buttons, not in a six-second toast++- **Date:** 2026-11-04+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[中文](2026-11-04-model-test-refusal.zh.md)++The model config dialog's "test connection" button runs the form's current — still unsaved — values+past the server and saves nothing. Every way that probe fails is a sentence the reader has to keep+while fixing the same form: a wrong key, a base URL that answers nothing, an id whose group cannot+route it. All of them arrived as a notification only — it sits over the dialog and dismisses itself+after six seconds, while the form did not change one character: six seconds later nothing on screen+said the button had been pressed.++The sentence is now drawn in the dialog, directly under the row of buttons (`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 what the probe was sent, and the same button is the retry.+A probe that *connects* keeps its toast with the latency (it leaves nothing behind to explain), and+so does an entry its group cannot route: that one keeps the advice instead of the route's own+vocabulary, with the relayed sentence going to the console.++## Details++- `packages/web/src/features/models/model-test-refusal.ts` (new, 60 lines): `modelTestRefusal(answer,+ fix)` turns one probe's answer into that line, `null` for a connecting one. Three shapes, each+ following a rule the app already has: a failed request reads the localized sentence for its error+ code (`refusalText`), an answer with no detail falls back to the generic text (an empty line under+ the button would say less than the toast it replaced), and a routable entry that failed relays the+ route's own sentence — which is what makes a wrong key or a wrong endpoint diagnosable. `fix`+ (from `unroutableFix`, judged on the form at press time) replaces that sentence with the advice the+ entry's own shape calls for.+- `packages/web/src/features/models/models-page.tsx`: one `testRefusal` state — cleared when the+ probe starts and on every edit (the probe sent exactly the values the sentence describes), set+ when the answer was a refusal. The line is drawn under the button row; the success toast and the+ console copy of a relayed unroutable sentence are unchanged.+- `packages/web/src/lib/strings{,-en}.ts`: **no new copy** — it reuses `testFailed(detail)` /+ `testStalePin` / `testNotRoutable`, the sentences the card's own status line already uses.++## Tests++- `packages/web/test/model-test-refusal.test.ts` (new, 7 cases): a connecting answer leaves nothing /+ the route's detail travels verbatim / a detail-less answer falls back to the generic text / a+ failed request reads its code's localized sentence (raw English never reaches the screen) / an+ error the client raised itself keeps its own words / both pieces of routing advice replace the+ route's sentence, whatever shape the answer had / the active language.+- `packages/web/e2e/models-test-refusal.spec.mjs` (new, two cases on a real server): the probe route+ is stubbed at `page.route`. Case ①: an answer that failed upstream draws the route's sentence under+ the button row, the notification region holds nothing to dismiss, nothing was written, the form is+ untouched, and seven seconds later the line is still there; editing a field drops it. Case ②: a+ request that failed on the way out — a coded 500 — reads in the app's words while the probe carried+ the form's unsaved key (`sk-probe`); once the route is let through, the same button retries, the+ line goes, and the latency toast appears instead.++## Compatibility++- No interface, request or storage change: the same `POST …/models/test`, which saves nothing. Only+ where a refused one is drawn has moved — from a notification alone to a line under the buttons+ that outlives it.diff --git a/changelog/unreleased/2026-11-04-model-test-refusal.zh.md b/changelog/unreleased/2026-11-04-model-test-refusal.zh.mdnew file mode 100644index 00000000..ae61cab8--- /dev/null+++ b/changelog/unreleased/2026-11-04-model-test-refusal.zh.md@@ -0,0 +1,48 @@+# 模型库配置弹窗的「测试连通性」被拒时,原因留在按钮下面,不再只活六秒++- **日期:** 2026-11-04+- **类型:** fix+- **范围:** `web`+- **破坏性:** 无++[English](2026-11-04-model-test-refusal.md)++模型库配置弹窗里那颗「测试连通性」,跑的是表单当前(尚未保存的)值,什么都不写。每一种失败+都是读者改同一张表单时要一直看着的那句话:key 不对、base URL 没回应、这个 id 所在的分组路由+不了它。这些此前都只落进一条通知 —— 它盖在弹窗上方、六秒后自行消失,而表单一个字都没变:六秒+之后,屏上没有任何东西说明这颗按钮被按过。++现在这句话画在弹窗里、按钮那一行的正下方(`role="alert"`、危险色、限两行、整句挂悬停),留到+表单被编辑或下一次测试开始为止 —— 那几个字段正是探测送出去的值,同一颗按钮就是重试。连接成功+的那次仍然是一条带延时的通知(它没有留下需要解释的东西);分组路由不了的那种也仍然给出建议,+而不是路由自己的那套词,被换掉的原句进控制台。++## 细节++- `packages/web/src/features/models/model-test-refusal.ts`(新,60 行):`modelTestRefusal(answer,+ fix)` 把一次探测的答复变成那句话,连接成功给 `null`。三种答复各按既有规则取词:请求本身失败+ 走它错误码对应的本地化句子(`refusalText`);答复里连细节都没有时退回通用那句 —— 按钮下面+ 一行空白比它取代的那条通知说得更少;能路由却失败的把路由自己的句子原样带过去,那正是让「key+ 错了」和「地址错了」都诊断得出来的东西。`fix`(`unroutableFix`,按按下那一刻的表单判)把这句+ 换成该条目自身形状对应的建议。+- `packages/web/src/features/models/models-page.tsx`:一个 `testRefusal` 状态 —— 探测开始时清掉、+ 表单任何一次编辑也清掉(探测送的正是这句话描述的那几个值)、被拒时写上。句子画在按钮行下面;+ 成功那条通知与「路由不了的原句进控制台」都保持原样。+- `packages/web/src/lib/strings{,-en}.ts`:**没有新文案** —— 复用 `testFailed(detail)` /+ `testStalePin` / `testNotRoutable`,也就是卡片自己那行状态用的同一批句子。++## 测试++- `packages/web/test/model-test-refusal.test.ts`(新,7 条):连接成功不留话 / 路由的细节原样带+ 过去 / 没有细节时退回通用那句 / 请求失败按错误码取本地化句子(原始英文不出现在屏上)/ 客户端+ 自己抛的错保留自己的话 / 两种路由建议都替换掉路由的句子(不论答复是哪种形状)/ 跟着界面语言走。+- `packages/web/e2e/models-test-refusal.spec.mjs`(新,真服务端两条):探测路由桩在 `page.route`+ 上。用例①:路由答复失败时按钮行下面出现它的句子、通知区没有可点条目、什么都没写、表单原样,+ 七秒后句子仍在;改一个字段即清掉。用例②:请求本身失败(500 加错误码)时按应用的本地化句子+ 显示,而探测带走的是表单里未保存的 key(`sk-probe`);放行之后同一颗按钮重试 —— 句子消失,+ 换成那条带延时的成功通知。++## 兼容++- 接口、请求与存储都没变:还是同一次 `POST …/models/test`,不写任何东西。改变的只有被拒之后画+ 在哪里 —— 从「只有一条通知」到「按钮下面多一条活得下去的说法」。diff --git a/packages/web/e2e/models-test-refusal.spec.mjs b/packages/web/e2e/models-test-refusal.spec.mjsnew file mode 100644index 00000000..46deb7dd--- /dev/null+++ b/packages/web/e2e/models-test-refusal.spec.mjs@@ -0,0 +1,198 @@+/**+ * Regression: the model config dialog's "test connection" button says why a probe did not get+ * through — in the dialog, under the row of buttons that asked — 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 past the server and writes nothing, so every failed+ * probe is a form that looks untouched plus one sentence the reader has to keep while fixing it+ * (a wrong key, a base URL that answers nothing). Six seconds later that sentence used to be gone,+ * and the form carried no sign 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. Both shapes the route can send are exercised — an answer that failed upstream+ * (`{ok:false,message}`) and a request that failed on the way out (a coded error) — because they+ * reach the dialog's line through different rules.+ */+import { test, expect } from "@playwright/test";+import { provisionAndLogin } from "./auth.mjs";++const BASE = process.env.BASE_URL;+const P = "password123";++/** The group and model the tests work with; unique enough to appear nowhere else. */+const GROUP = "probetest";+const MODEL = "probe-test";+const NAME = "Probe Test";+const BASE_URL = "http://127.0.0.1:9/v1";++/** The row the model is, as this file seeds it: a hand-added model of a user-defined group. */+const ROW = {+ provider: GROUP,+ modelId: MODEL,+ displayName: NAME,+ contextWindow: 32000,+ clientType: "openai-chat",+ baseUrl: BASE_URL,+ maxTokens: 4096,+};++/** The table entry a `ModelInfo` came from: every field the response reports, sent back as-is. */+function toEntry(m) {+ const entry = { provider: m.provider, modelId: m.modelId };+ for (const key of [+ "displayName",+ "contextWindow",+ "clientType",+ "vision",+ "maxTokens",+ "fastMode",+ "pricing",+ ]) {+ if (m[key] !== undefined) entry[key] = m[key];+ }+ if (m.credential?.baseUrl !== undefined) entry.baseUrl = m.credential.baseUrl;+ return entry;+}++/**+ * Provision the user and seed their Project with the model, through the table PUT so nothing here+ * depends on the built-in catalog. Idempotent: a rerun on the same data root rewrites the row the+ * tests expect rather than trusting it.+ */+async function projectWithModel(page, user) {+ await provisionAndLogin(page.request, user, P);+ const { projects } = await (await page.request.get(`${BASE}/api/projects`)).json();+ const projectId = projects[0].projectId;+ const read = async () =>+ (await page.request.get(`${BASE}/api/projects/${projectId}/models`)).json();++ const table = await read();+ const current = table.models.find((m) => m.provider === GROUP && m.modelId === MODEL);+ if (!current || (current.displayName ?? "") !== NAME) {+ const put = await page.request.put(`${BASE}/api/projects/${projectId}/models`, {+ data: {+ defaultModel: table.defaultModel,+ models: [...table.models.filter((m) => m.provider !== GROUP).map(toEntry), ROW],+ },+ });+ expect(put.ok(), "seed the model through the table PUT").toBeTruthy();+ }+ expect(+ (await read()).models.find((m) => m.provider === GROUP && m.modelId === MODEL),+ "the Project holds the model",+ ).toBeTruthy();+}++/**+ * Open the model's config dialog. The list is filtered rather than scrolled: a user-defined group+ * sits far below the built-in ones, and a search force-opens every group it leaves visible.+ */+async function openModelDialog(page) {+ await page.goto("/models");+ await page.locator('input[placeholder*="搜索"]').first().fill(NAME);+ const card = page.getByText(NAME, { exact: true }).first();+ await expect(card).toBeVisible();+ await card.click();+ const dialog = page.getByRole("dialog");+ await expect(dialog).toBeVisible();+ await expect(page.getByRole("button", { name: "删除模型" })).toBeVisible();+ return dialog;+}++/** The line the dialog draws under the button row. */+function line(dialog) {+ return dialog.getByRole("alert");+}++/** The notification area's dismissible entries: what a refusal used to be. */+function toasts(page) {+ return page.getByRole("region", { name: "通知" }).getByRole("button");+}++test("a refused probe leaves its reason under the button row, where it stays", async ({ page }) => {+ await projectWithModel(page, "r190test");++ const dialog = await openModelDialog(page);+ const detail = "connect ECONNREFUSED 127.0.0.1:9";+ const posts = [];+ await page.route("**/api/projects/*/models/test", async (route) => {+ if (route.request().method() !== "POST") return route.fallback();+ posts.push(route.request().postDataJSON());+ await route.fulfill({+ status: 200,+ contentType: "application/json",+ body: JSON.stringify({ ok: false, message: detail }),+ });+ });++ await dialog.getByRole("button", { name: "测试连通性" }).click();++ // The route's own words, behind the sentence's lead-in, in the dialog — not in a toast.+ await expect(line(dialog)).toHaveText(`连通失败:${detail}`);+ await expect(toasts(page)).toHaveCount(0);+ expect(posts).toHaveLength(1);++ // The probe saved nothing: the form is exactly as it was seeded.+ await expect(dialog.getByLabel("自定义 base URL")).toHaveValue(BASE_URL);++ // And the reason is still on screen after the toast that used to carry it would have gone.+ await page.waitForTimeout(7000);+ await expect(line(dialog)).toHaveText(`连通失败:${detail}`);++ // An edit retires it: the sentence described the form the probe was sent, and that form is no+ // longer the one on screen.+ await dialog.getByLabel("自定义 base URL").fill("http://127.0.0.1:9/v2");+ await expect(line(dialog)).toHaveCount(0);+});++test("a request that failed on the way out reads in the app's words, and the retry clears it", async ({+ page,+}) => {+ await projectWithModel(page, "r190retry");++ const dialog = await openModelDialog(page);+ const posts = [];+ let refuse = true;+ await page.route("**/api/projects/*/models/test", async (route) => {+ if (route.request().method() !== "POST") return route.fallback();+ posts.push(route.request().postDataJSON());+ if (!refuse) {+ await route.fulfill({+ status: 200,+ contentType: "application/json",+ body: JSON.stringify({ ok: true, latencyMs: 1200 }),+ });+ return;+ }+ await route.fulfill({+ status: 500,+ contentType: "application/json",+ body: JSON.stringify({ error: { code: "internal", message: "RAW ENGLISH MESSAGE" } }),+ });+ });++ // A key typed but not yet saved: the probe asks about it, which is why its refusal belongs on the+ // form rather than in a notification.+ await dialog.getByLabel("API key").fill("sk-probe");++ await dialog.getByRole("button", { name: "测试连通性" }).click();+ // The code's own sentence, not the server's English.+ await expect(line(dialog)).toHaveText("连通失败:服务器内部错误,请稍后重试。");+ await expect(toasts(page)).toHaveCount(0);+ expect(posts).toHaveLength(1);+ // What was probed is the draft, not the stored row.+ expect(posts[0]).toMatchObject({+ provider: GROUP,+ modelId: MODEL,+ apiKey: "sk-probe",+ baseUrl: BASE_URL,+ });++ // The button is the retry, and a probe that connects leaves nothing behind: its numbers go to the+ // toast the dialog has always used for them.+ refuse = false;+ await dialog.getByRole("button", { name: "测试连通性" }).click();+ await expect(line(dialog)).toHaveCount(0);+ await expect(page.getByRole("region", { name: "通知" })).toContainText("连通正常(1200 ms)");+ expect(posts).toHaveLength(2);+});diff --git a/packages/web/src/features/models/model-test-refusal.ts b/packages/web/src/features/models/model-test-refusal.tsnew file mode 100644index 00000000..1851741a--- /dev/null+++ b/packages/web/src/features/models/model-test-refusal.ts@@ -0,0 +1,60 @@+/**+ * The model config dialog's "test connection" button: the sentence a probe that did not get+ * through leaves under the button row, and why that sentence is a line in the dialog rather than+ * a toast.+ *+ * The button runs the form's current — still unsaved — values past the server, so every way a+ * probe can fail is something the reader has to keep while they fix that same form: a wrong key,+ * a base URL that answers nothing, an id whose group cannot route it. All of them used to arrive+ * as one notification, which sits over the dialog and dismisses itself after six seconds — the+ * form 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 dialog, under the buttons 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 (`testOk`, latency in the sentence). That outcome leaves+ * nothing behind to explain — no field is wrong, and the number is not something the form has to be+ * read against — so only one of the two answers has a place on the dialog.+ */+import type { ModelTestResponse } 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 ModelTestAnswer {+ /** The route's answer, or `null` when the request itself failed (login gone, server down). */+ readonly result: ModelTestResponse | null;+ /** Why the request failed; read only when `result` is `null`. */+ readonly error?: unknown;+}++/**+ * The line the dialog draws under the test button, or `null` when the probe connected.+ *+ * Two of the three shapes follow the rule the rest of the app's refusal slots follow+ * (`refusalText`): 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. A routable entry that failed relays the route's own sentence, which is what+ * makes a wrong key or a wrong endpoint diagnosable.+ *+ * `fix` is the third shape and comes from `unroutableFix` (judged on the form at press time, so it+ * describes what was actually probed): an entry its group cannot place fails upstream with+ * AgentHub's own vocabulary — the id, then the client types it does support — which leaves the+ * reader to infer what to do. That case keeps the advice instead, and the relayed sentence goes to+ * the console for whoever reads the report.+ */+export function modelTestRefusal(+ answer: ModelTestAnswer,+ fix: "sync" | "custom" | null,+): string | null {+ if (answer.result !== null && answer.result.ok) return null;+ if (fix === "sync") return S.models.testStalePin;+ if (fix === "custom") return S.models.testNotRoutable;+ const message =+ answer.result === null+ ? refusalText(answer.error)+ : (answer.result.message ?? S.common.unknownError);+ return S.models.testFailed(message);+}diff --git a/packages/web/src/features/models/models-page.tsx b/packages/web/src/features/models/models-page.tsxindex b11214c7..20dcc60a 100644--- a/packages/web/src/features/models/models-page.tsx+++ b/packages/web/src/features/models/models-page.tsx@@ -77,7 +77,7 @@ import {import * as api from "../../api/endpoints";import { ApiError } from "../../api/client";import { S } from "../../lib/strings";-import { apiErrorText } from "../../lib/api-error";+import { apiErrorText, refusalText } from "../../lib/api-error";import { useDocumentTitle } from "../../lib/use-document-title";import { useProject } from "../../state/project";import { useAuth } from "../../state/auth";@@ -167,6 +167,8 @@ import { GroupBalance } from "./group-balance";import { isPinned, usePinnedBalance } from "./balance";import { refusalOf } from "./write-outcome";import type { WriteOutcome } from "./write-outcome";+import { modelTestRefusal } from "./model-test-refusal";+import type { ModelTestAnswer } from "./model-test-refusal";/*** The authorization flows a group's Connect dialog can run, keyed by the flow named in that@@ -2665,6 +2667,13 @@ function ModelDialog({const [fieldErrors, setFieldErrors] = useState<FieldErrors>({});/** Connectivity test in progress. */const [testing, setTesting] = useState(false);+ /**+ * The sentence the last refused probe left under the button row (model-test-refusal.ts). It+ * lives on the dialog rather than in a toast because the form it names is on the dialog: cleared+ * by every edit (the probe sent exactly the values it describes) and at the start of the next+ * probe.+ */+ const [testRefusal, setTestRefusal] = useState<string | null>(null);/*** Action pending confirmation: anything that writes to the Project config goes through a* confirmation step — save config / set as default / set as vision proxy model / delete.@@ -2751,6 +2760,9 @@ function ModelDialog({const set = (patch: Partial<RowState>) => {setForm((prev) => ({ ...prev, ...patch }));+ // A refused probe described the values it was sent: any edit makes that sentence describe a+ // form that is no longer on screen, so it goes with the field it named.+ setTestRefusal(null);// Clear the error marker for whichever field was changed (keys match RowState field names).setFieldErrors((prev) => {const next = { ...prev };@@ -2760,22 +2772,25 @@ function ModelDialog({};/**- * What a failed probe says. An entry its group cannot place fails upstream with AgentHub's- * own sentence — the id, then the list of client types it does support — which names an- * internal vocabulary and leaves the reader to infer what to do about it. That case gets a- * message naming the problem and the fix its own shape calls for (unroutableFix); every- * other failure still relays the upstream text, which is what makes a wrong key or a wrong- * endpoint diagnosable. The relayed sentence is not lost either way: it goes to the console,- * where a developer looking into a report can still read it.+ * What a failed probe says: the sentence under the button (model-test-refusal.ts), not a toast —+ * the form it describes is right there, and a toast would be gone before the reader finished+ * reading the reason against it. The refusal is judged on the form as it was pressed, because+ * that is what the probe sent.*/- const reportTestFailure = (message: string) => {+ const reportTestFailure = (answer: ModelTestAnswer) => {const fix = unroutableFix(form.provider, form.modelId, form.clientType);- if (fix === null) {- toastError(S.models.testFailed(message));- return;+ // An entry its group cannot place gets the advice instead of the route's sentence (see+ // modelTestRefusal); that sentence is not lost — it goes to the console, where whoever reads+ // a report can still find the id and the client types it named. Every other failure is+ // relayed in the line itself, so only this case needs the extra copy.+ if (fix !== null) {+ const relayed =+ answer.result === null+ ? refusalText(answer.error)+ : (answer.result.message ?? S.common.unknownError);+ console.warn(`[models] ${form.provider}/${form.modelId.trim()}: ${relayed}`);}- console.warn(`[models] ${form.provider}/${form.modelId.trim()}: ${message}`);- toastError(fix === "sync" ? S.models.testStalePin : S.models.testNotRoutable);+ setTestRefusal(modelTestRefusal(answer, fix));};/**@@ -2787,6 +2802,9 @@ function ModelDialog({*/const runTest = async () => {setTesting(true);+ // The previous probe's sentence described a form that may have been edited since, and this+ // press is a new question: the line goes while the answer is in flight.+ setTestRefusal(null);try {// Always tests against the **current form draft**, unaffected by already-persisted// values (per user intent: test exactly what's typed right now):@@ -2810,9 +2828,9 @@ function ModelDialog({body.fastMode = form.fastMode;const res = await api.testModel(projectId, body);if (res.ok) toastSuccess(S.models.testOk(res.latencyMs ?? 0));- else reportTestFailure(res.message ?? "");+ else reportTestFailure({ result: res });} catch (e) {- reportTestFailure(apiErrorText(e));+ reportTestFailure({ result: null, error: e });} finally {setTesting(false);}@@ -3500,6 +3518,19 @@ function ModelDialog({</>)}</div>+ {testRefusal !== null && (+ // Under the buttons that asked, not over the dialog: `line-clamp-2` keeps a long+ // upstream sentence from heightening it, and the whole text 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>+ )}</div>)}diff --git a/packages/web/test/model-test-refusal.test.ts b/packages/web/test/model-test-refusal.test.tsnew file mode 100644index 00000000..ab16a39a--- /dev/null+++ b/packages/web/test/model-test-refusal.test.ts@@ -0,0 +1,82 @@+/**+ * The model config dialog's "test connection" line (src/features/models/model-test-refusal.ts):+ * which answers leave a sentence under the button row, and whose words that sentence uses.+ *+ * A failed probe changes nothing else in the dialog — the form keeps every value it was asked+ * with, and nothing is written — 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, the two+ * pieces of routing advice that replace the route's own vocabulary, and the two languages; the+ * rule that matters most is the first: 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 { modelTestRefusal } from "../src/features/models/model-test-refusal";++afterEach(() => {+ setActiveStrings(ZH);+});++describe("modelTestRefusal", () => {+ it("leaves no line when the probe connected", () => {+ // The latency travels in the success toast; there is no failure for the dialog to keep.+ expect(modelTestRefusal({ result: { ok: true, latencyMs: 120 } }, null)).toBeNull();+ expect(modelTestRefusal({ result: { ok: true } }, null)).toBeNull();+ });++ it("carries the route's own detail behind the sentence's lead-in", () => {+ // What a wrong key or a wrong endpoint looks like: the route's words, relayed as they are.+ const detail = "401 Unauthorized: invalid api key";+ expect(modelTestRefusal({ result: { ok: false, message: detail } }, null)).toBe(+ S.models.testFailed(detail),+ );+ });++ it("still says something when the route refused without a detail", () => {+ expect(modelTestRefusal({ result: { ok: false } }, null)).toBe(+ S.models.testFailed(S.common.unknownError),+ );+ });++ it("reads a failed request through its code, so the line is the localized one", () => {+ const refused = modelTestRefusal(+ { result: null, error: new ApiError(500, "internal", "RAW ENGLISH SERVER MESSAGE") },+ null,+ );+ expect(refused).toBe(S.models.testFailed(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(modelTestRefusal({ result: null, error: new Error("network down") }, null)).toBe(+ S.models.testFailed("network down"),+ );+ expect(modelTestRefusal({ result: null, error: undefined }, null)).toBe(+ S.models.testFailed(S.common.unknownError),+ );+ });++ it("replaces an unroutable answer with the advice its own shape calls for", () => {+ // The upstream sentence names client types the reader cannot act on, so the line carries the+ // advice instead — the same split the card makes (`unroutableFix`).+ const answer = { result: { ok: false, message: "model X is not supported for client openai" } };+ expect(modelTestRefusal(answer, "sync")).toBe(S.models.testStalePin);+ expect(modelTestRefusal(answer, "custom")).toBe(S.models.testNotRoutable);+ // The advice is about the entry, not about one kind of answer: a request that failed on the+ // way out gets it too.+ expect(modelTestRefusal({ result: null, error: new Error("boom") }, "custom")).toBe(+ S.models.testNotRoutable,+ );+ });++ it("speaks the active language", () => {+ setActiveStrings(EN);+ expect(modelTestRefusal({ result: { ok: false } }, null)).toBe(+ EN.models.testFailed(EN.common.unknownError),+ );+ expect(modelTestRefusal({ result: { ok: false } }, "sync")).toBe(EN.models.testStalePin);+ });+});