A local-first multi-agent app development platform, built on PenguinHarness
fix(web): 连通性测速被拒时,原因留在测速块里,不再只活六秒
lmliheng72e9af28f77b
diff --git a/changelog/unreleased/2026-11-01-proxy-probe-refusal.md b/changelog/unreleased/2026-11-01-proxy-probe-refusal.mdnew file mode 100644index 00000000..1a5b8ccc--- /dev/null+++ b/changelog/unreleased/2026-11-01-proxy-probe-refusal.md@@ -0,0 +1,55 @@+# A failed reachability test says why in the probe block, instead of in a toast that expires++- **Date:** 2026-11-01+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[中文](2026-11-01-proxy-probe-refusal.zh.md)++Settings → Server → Proxy options carries a reachability test under the Save row. Every outcome it+can have — reachable, timed out, DNS, refused, TLS — arrives inside a 200 and lands on its target's+row. Only the request itself failing (a lost session, a dead server) comes back as an error, and+that one filled no row at all: the block looked exactly as it did before anyone pressed the button,+every target still reading 「Not tested」, and the reason arrived as a notification over it. Six+seconds later even that was gone, so a reader who looked away could not tell "not run" from "could+not run".++The sentence now stays in the block: under the 测速 button, above the targets it could not fill, in+the danger ink and as a `role="alert"` clamped to two lines with the whole of it on hover. It is one+sentence per run — six failed requests carry the same words, and six copies of one sentence is not+six pieces of information — and it goes when the next run starts or when a save replaces the path it+described. Nothing was written or measured by a failed run, so the button is the retry.++No new copy was written: the words come from the app's existing error table through the shared+`refusalText()`, behind the same 「操作被拒绝:」 lead-in the other refusals use.++## Details++- `packages/web/src/features/settings/proxy-section.tsx`: a `probeRefusal` state, filled by the+ failing request instead of `toastError` and cleared when a run starts and when saved settings are+ adopted; the sentence is drawn between the button row and the target list, because it is about the+ run rather than about any one target.+- `packages/web/src/features/settings/proxy-probe.ts`: `probeRefusalFor()` — whether one failed+ request earns words. It answers the two rules the block needs in one place: keep the run's first+ sentence (later rejections of the same run are the same news), and drop answers from a run a save+ has already superseded (a sentence about a path nothing travels any more is as wrong as the stale+ numbers a save clears).++## Tests++- `packages/web/test/proxy-probe.test.ts` (six unit cases): a failed request draws its own sentence;+ a second rejection of the same run keeps the first; an answer from a superseded run adds nothing+ and removes nothing; the next run's sentence replaces the last one's; a dead connection uses the+ client's own words; a value with nothing to say falls back to the generic text.+- `packages/web/e2e/proxy-probe-refusal.spec.mjs` (new, against the real server, probe route stubbed+ to answer 500 `internal`): one run puts exactly one sentence in the block, sends six requests, and+ leaves the notification area empty; all six rows still say 「未测试」 and none of them carries the+ sentence; it is still there seven seconds later; the next run, which lands, takes it away and fills+ all six rows.++## Compatibility++- No API, request or stored-data change: the same `POST /api/admin/settings/proxy-probe/:provider`+ is sent with the same body and the same per-target answers are read. Only where a failed *request*+ reports itself moves — from a notification to the block that ran it.diff --git a/changelog/unreleased/2026-11-01-proxy-probe-refusal.zh.md b/changelog/unreleased/2026-11-01-proxy-probe-refusal.zh.mdnew file mode 100644index 00000000..a1cffa2f--- /dev/null+++ b/changelog/unreleased/2026-11-01-proxy-probe-refusal.zh.md@@ -0,0 +1,46 @@+# 连通性测速被拒时,原因留在测速块里,不再只活六秒++- **日期:** 2026-11-01+- **类型:** fix+- **范围:** `web`+- **破坏性:** 无++[English](2026-11-01-proxy-probe-refusal.md)++设置 → 服务器 → 代理选项在「保存」下方有一块连通性测速。它自己能有的每种结果 —— 已连通、连接超时、+域名解析失败、连接被拒绝、TLS 握手失败 —— 都在 200 里回来、各自落在那一行上。只有请求本身失败(丢了+会话、服务端死了)才是错误,而这一种一个格子都填不上:整块与按下按钮之前一模一样,六个目标还都写着+「未测试」,原因则是一条盖在它上面的通知;再过六秒,连那条通知也没了。转头走开的人回来,分不出「没测」+和「测不了」。++现在这句话留在块里:画在「测速」按钮下面、它没能填上的目标上面,danger 色、`role="alert"`、限两行、+整句挂悬停。一次运行只有一句 —— 六个失败请求带的是同一句话,同一句话复制六份不是六条信息 —— 下一次+运行开始、或保存换掉了它描述的那条路径时,它就消失。失败的一轮什么都没写、也什么都没测到,所以那颗+按钮就是重试。++没有新增文案:句子取自应用已有的错误表、经共享的 `refusalText()` 出来,引子仍是别处用的那句+「操作被拒绝:」。++## 细节++- `packages/web/src/features/settings/proxy-section.tsx`:多一个 `probeRefusal` 状态,失败的那条请求填它+ (不再 `toastError`),运行开始与采纳新设置时清空;句子画在按钮行与目标列表之间 —— 它说的是这一轮,+ 不属于任何单独一个目标。+- `packages/web/src/features/settings/proxy-probe.ts`:`probeRefusalFor()` —— 一条失败请求是否该换来一句+ 话。这一块需要的两条规则都在这里:同一轮只认第一句(同一轮后来的拒绝是同一件事);保存已经换掉的那+ 一轮的回答不加、也不减(描述一条不再走的路径,与保存会清掉的旧数字一样是错的)。++## 测试++- `packages/web/test/proxy-probe.test.ts`(新增 6 条):失败的请求画出它自己的句子;同一轮的第二条拒绝+ 保留第一句;被保存换掉的那一轮的回答什么都不加也不减;下一轮的句子替换上一轮的;连接不上时用客户端+ 自己的措辞;什么信息都没有的值退回通用那句。+- `packages/web/e2e/proxy-probe-refusal.spec.mjs`(新,真服务端,探测路由桩成 500 `internal`):一次运行+ 只在块里留下一句话、真发了六条请求、通知区里什么都没有;六个目标还都写着「未测试」,而且没有任何一+ 行在画这句话;七秒后它仍在;接着让这一轮成功,句子随之消失、六行都填上。++## 兼容++- 接口、请求与已存数据都没变:发的还是同一个 `POST /api/admin/settings/proxy-probe/:provider`、同样的+ 请求体,读的也还是每目标一份的答复。变的只是「请求失败」这件事报到哪儿 —— 从一条通知,搬回跑它的+ 那一块里。diff --git a/packages/web/e2e/proxy-probe-refusal.spec.mjs b/packages/web/e2e/proxy-probe-refusal.spec.mjsnew file mode 100644index 00000000..4683e588--- /dev/null+++ b/packages/web/e2e/proxy-probe-refusal.spec.mjs@@ -0,0 +1,154 @@+/**+ * Regression: a reachability test whose REQUESTS failed says why in the probe block itself+ * (Settings → 服务器 → 代理选项), under the button that ran it, and the sentence outlives the six+ * seconds a toast lives.+ *+ * Every outcome the test can have — reachable, timed out, DNS, refused, TLS — arrives inside a+ * 200 and lands on its target's row. Only the request failing (a lost session, a dead server) is+ * an error, and that one filled no row at all: the block looked exactly as it did before anyone+ * pressed the button, and the reason arrived as a notification over it. A reader who looked away+ * was left with six targets still saying 「未测试」 and no way to tell "not run" from "could not+ * run".+ *+ * The probe route is stubbed rather than travelled: what this spec is about is what the page does+ * with the answer, and reaching six real provider hosts from a test machine would make it depend+ * on the network. The refusal is the app's own sentence for the code the server would send+ * (`internal`), so the line on screen is the localized one behind the shared lead-in.+ */+import { test, expect } from "@playwright/test";+import { ADMIN_ID, ADMIN_PASSWORD, login } from "./auth.mjs";++const BASE = process.env.BASE_URL;+const MOCK = process.env.MOCK_URL;++/** The line the block draws: the shared lead-in plus the app's sentence for `internal`. */+const REFUSED = "操作被拒绝:服务器内部错误,请稍后重试。";++/**+ * 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();+ return projectId;+}++/** The settings dialog, opened the way a person opens it: the user menu, then 代理选项. */+async function openProxy(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;+}++/** The probe block: the heading, its button and the targets it lists — one `<section>`. */+function probeBlock(settings) {+ // Anchored on the block's own heading rather than on the button: while a run is in flight the+ // button reads 「测速中…」, and the block has to stay findable to assert what it says.+ return settings.locator('section:has-text("连通性测速")');+}++/**+ * Answer every probe request with a refusal (500 `internal`), until `letThrough()` — one request+ * per target, so a refusal is what six of them land as. Counted, so the spec can tell how many+ * requests the block really fired.+ */+async function stubProbe(page, seen) {+ let refuse = true;+ await page.route("**/api/admin/settings/proxy-probe/*", async (route) => {+ if (route.request().method() !== "POST") return route.fallback();+ const provider = route.request().url().split("/").pop();+ seen.push(provider);+ if (!refuse) {+ await route.fulfill({+ status: 200,+ contentType: "application/json",+ body: JSON.stringify({+ probe: {+ provider,+ url: `https://${provider}.example.invalid/v1/models`,+ outcome: "reachable",+ ms: 42,+ status: 200,+ },+ }),+ });+ return;+ }+ await route.fulfill({+ status: 500,+ contentType: "application/json",+ body: JSON.stringify({ error: { code: "internal", message: "Internal server error" } }),+ });+ });+ return () => {+ refuse = false;+ };+}++test("a failed run keeps its reason in the probe block, past the toast it used to be", async ({+ page,+}) => {+ await ready(page);+ const attempts = [];+ const letThrough = await stubProbe(page, attempts);++ await page.goto("/");+ const settings = await openProxy(page);+ const block = probeBlock(settings);+ await expect(block).toBeVisible();+ const notices = page.getByRole("region", { name: "通知" });+ const rows = block.locator("li");+ // The targets are listed before anyone presses the button — the block knows what it will fetch.+ await expect(rows).toHaveCount(6);+ await expect(block.getByRole("alert")).toHaveCount(0);++ // Run it: every request is refused, and the block says so once — not six times, and not as a+ // notification over a block that looks untouched.+ await block.getByRole("button", { name: "测速", exact: true }).click();+ await expect(block.getByRole("alert")).toHaveText(REFUSED);+ await expect(block.getByRole("alert")).toHaveCount(1);+ expect(attempts).toHaveLength(6);+ await expect(notices.getByRole("button")).toHaveCount(0);++ // Nothing was measured: every row still says 「未测试」, and none of them drew the sentence —+ // it is about the run, so it belongs to the block rather than to any one target.+ await expect(block.getByText("未测试", { exact: true })).toHaveCount(6);+ await expect(block.locator("li").getByRole("alert")).toHaveCount(0);+ // The button is the retry, still at rest.+ await expect(block.getByRole("button", { name: "测速", exact: true })).toBeEnabled();++ // Six seconds is how long a toast lives; this sentence has to still be there after it.+ await page.waitForTimeout(7_000);+ await expect(block.getByRole("alert")).toHaveText(REFUSED);+ await expect(notices.getByRole("button")).toHaveCount(0);++ // The next run is the retry: it lands, so the sentence of the last attempt goes with it.+ letThrough();+ await block.getByRole("button", { name: "测速", exact: true }).click();+ // Each row carries its own latency, next to the words that say what it means (`· 已连通`, which+ // only a screen reader reads out).+ await expect(rows.filter({ hasText: "42 ms" })).toHaveCount(6);+ await expect(block.getByRole("alert")).toHaveCount(0);+ expect(attempts).toHaveLength(12);+});diff --git a/packages/web/src/features/settings/proxy-probe.ts b/packages/web/src/features/settings/proxy-probe.tsnew file mode 100644index 00000000..308b34c9--- /dev/null+++ b/packages/web/src/features/settings/proxy-probe.ts@@ -0,0 +1,51 @@+/**+ * The reachability test's refusal, and which run it belongs to.+ *+ * A probe answers every outcome it can have — reachable, timed out, DNS, refused, TLS — inside a+ * 200, one request per target. Only the request itself failing (a lost session, a dead server)+ * comes back as an error, and that sentence used to be a toast that dismissed itself after six+ * seconds: nothing else on the page changed, because a failed run fills no row, so a reader who+ * looked away was left with six untested targets and no way to tell "not run" from "could not+ * run". It now stays in the probe block until the next run starts.+ *+ * Both rules that decide whether an answer earns a sentence live here, in one place, because the+ * component fires one request per target and every one of them may land with the same failure:+ *+ * - One sentence per run. A lost session fails every target identically, and six copies of one+ * sentence is not six pieces of information.+ * - An answer from a run that is no longer the live one says nothing. Saving adopts new settings+ * mid-flight (and starts a new run when the reader asks again), and a sentence about a path+ * nothing travels any more would be just as wrong as the stale numbers that save clears.+ */+import { refusalText } from "../../lib/api-error";++/** The sentence a run's failed request draws, named by the run it describes. */+export interface ProxyProbeRefusal {+ /** The run this sentence belongs to; a later run's sentence replaces it, its own duplicates do not. */+ readonly run: number;+ /** The words, drawn behind the shared `S.common.refused` lead-in. */+ readonly text: string;+}++/** One failed request of one run, as the component sees it when the promise rejects. */+export interface ProxyProbeAnswer {+ /** The run the request was fired by. */+ readonly run: number;+ /** The run the page is on now (`runSeq.current` at the moment the answer landed). */+ readonly liveRun: number;+ readonly error: unknown;+}++/**+ * What the block should say after one request failed: `current` when this answer earns no words+ * (it is from a superseded run, or its run already has its sentence), otherwise this answer's+ * sentence — which is also how the next run's sentence replaces the last one's.+ */+export function probeRefusalFor(+ current: ProxyProbeRefusal | null,+ answer: ProxyProbeAnswer,+): ProxyProbeRefusal | null {+ if (answer.run !== answer.liveRun) return current;+ if (current !== null && current.run === answer.run) return current;+ return { run: answer.run, text: refusalText(answer.error) };+}diff --git a/packages/web/src/features/settings/proxy-section.tsx b/packages/web/src/features/settings/proxy-section.tsxindex f8d40536..e90497aa 100644--- a/packages/web/src/features/settings/proxy-section.tsx+++ b/packages/web/src/features/settings/proxy-section.tsx@@ -26,6 +26,13 @@* It carries its own busy flag rather than borrowing Save's: a measurement is not an unsaved* edit, so it neither blocks Save nor is blocked by it.*+ * A run whose requests fail (a lost session, a dead server — every outcome the test itself can+ * have arrives inside a 200 and lands on its target's row) says why in this block rather than in a+ * toast: a failed run fills no row, so the block looks exactly as it did before it ran, and the+ * sentence belongs to the button that just did nothing rather than to a notification that+ * dismisses itself over it (7.66, the rule the write refusals follow). It stays until the next run+ * or a save, which supersedes the path it describes.+ ** The targets — name and exact URL — come from the server and are listed before anyone presses* the button, so the page shows concretely what will be requested and a reader can see that* these are plain unauthenticated GETs. A frontend copy of that list could drift from the URLs@@ -52,6 +59,8 @@ import { ApiError } from "../../api/client";import { S } from "../../lib/strings";import { apiErrorText } from "../../lib/api-error";import { toneInk } from "../../lib/tone";+import { probeRefusalFor } from "./proxy-probe";+import type { ProxyProbeRefusal } from "./proxy-probe";/** Brand names: identical in every locale, so they are keyed off the server's provider id rather than doubled into both dictionaries. */const PROVIDER_LABEL: Record<ProxyProbeProvider, string> = {@@ -80,6 +89,11 @@ export function ProxySection() {/** Results by provider (null until a run starts, then filled one at a time), and the probe's own busy flag. */const [results, setResults] = useState<Map<ProxyProbeProvider, ProxyProbeDto> | null>(null);const [probing, setProbing] = useState(false);+ /**+ * Why the last run's requests failed, drawn under the button until the next run or a save. One+ * sentence per run, and none from a superseded one — the rule is `probeRefusalFor`'s.+ */+ const [probeRefusal, setProbeRefusal] = useState<ProxyProbeRefusal | null>(null);/*** Which run each in-flight answer belongs to. A result can land after its run stopped being* the current one — a save adopts new settings mid-flight — and a row filled from a@@ -97,6 +111,7 @@ export function ProxySection() {// counter also discards whatever is still in flight against the old one.runSeq.current += 1;setResults(null);+ setProbeRefusal(null);setProbing(false);};@@ -161,9 +176,8 @@ export function ProxySection() {// figure beside a live one cannot be told apart. An empty map, not null — null is "never// run", and the rows read it to tell "not tested" from "still measuring".setResults(new Map());- // One toast per run, not one per target: a lost session fails every request identically,- // and six copies of the same sentence is not six pieces of information.- let reported = false;+ // The sentence about the last run describes a path this one may no longer travel.+ setProbeRefusal(null);void Promise.allSettled(targets.map((t) =>api@@ -174,10 +188,11 @@ export function ProxySection() {}).catch((e: unknown) => {// Every outcome the probe itself can have, reachable or not, comes back inside a- // 200; only the request failing (a lost session, a dead server) lands here.- if (runSeq.current !== run || reported) return;- reported = true;- toastError(apiErrorText(e));+ // 200; only the request failing (a lost session, a dead server) lands here. Kept in+ // the block rather than toasted: nothing was filled in, and the button is the retry.+ setProbeRefusal((prev) =>+ probeRefusalFor(prev, { run, liveRun: runSeq.current, error: e }),+ );}),),).finally(() => {@@ -240,6 +255,19 @@ export function ProxySection() {{probing ? S.settings.proxyProbeRunning : S.settings.proxyProbeRun}</Button></div>+ {/* The run's own failure, in the block that ran and above the targets it could not fill:+ it is about every one of them, so it belongs to none of their rows. Clamped to two+ lines with the whole of it on hover, because a server's words run long. */}+ {probeRefusal !== null && (+ <p+ role="alert"+ data-tooltip={S.common.refused(probeRefusal.text)}+ data-tooltip-content="text"+ className={`mt-2 line-clamp-2 break-words text-xs ${toneInk.danger}`}+ >+ {S.common.refused(probeRefusal.text)}+ </p>+ )}<ul className="mt-3 space-y-3">{(targets ?? []).map((t) => {// This row's own answer, shown the moment it exists — the rows still waiting keepdiff --git a/packages/web/test/proxy-probe.test.ts b/packages/web/test/proxy-probe.test.tsnew file mode 100644index 00000000..08698b2f--- /dev/null+++ b/packages/web/test/proxy-probe.test.ts@@ -0,0 +1,62 @@+/**+ * Which run a failed probe's sentence belongs to (src/features/settings/proxy-probe.ts).+ *+ * The block fires one request per target, so one lost session produces six rejections carrying the+ * same words — and a save advances the run counter while some of them are still in flight. These+ * are the two rules that keep the block honest: one sentence per run, and none from a run that is+ * no longer the live one.+ */+import { describe, expect, it } from "vitest";+import { ApiError } from "../src/api/client";+import { probeRefusalFor } from "../src/features/settings/proxy-probe";+import type { ProxyProbeRefusal } from "../src/features/settings/proxy-probe";+import { S } from "../src/lib/strings";++/** What a 500 from the probe route becomes: an enveloped code the dictionary has a sentence for. */+const failed = new ApiError(500, "internal", "Internal server error");+const INTERNAL = S.errors.byCode.internal;++const first: ProxyProbeRefusal = { run: 4, text: INTERNAL };++describe("probeRefusalFor", () => {+ it("draws a failed request's own sentence", () => {+ expect(probeRefusalFor(null, { run: 4, liveRun: 4, error: failed })).toEqual({+ run: 4,+ text: INTERNAL,+ });+ });++ it("keeps the run's first sentence: six rejected targets are one sentence, not six", () => {+ expect(probeRefusalFor(first, { run: 4, liveRun: 4, error: failed })).toBe(first);+ });++ it("says nothing for an answer from a run a save has superseded", () => {+ expect(probeRefusalFor(null, { run: 3, liveRun: 4, error: failed })).toBeNull();+ // A sentence already up is left alone too: this answer describes the path it was about.+ expect(probeRefusalFor(first, { run: 3, liveRun: 4, error: failed })).toBe(first);+ });++ it("lets the next run's sentence replace the last one's", () => {+ expect(probeRefusalFor(first, { run: 5, liveRun: 5, error: failed })).toEqual({+ run: 5,+ text: INTERNAL,+ });+ });++ it("uses the app's words for a dead connection, which is no ApiError from the server", () => {+ // A connection that never reaches the server is the client's own `network_error`, code 0.+ const offline = new ApiError(0, "network_error", S.errors.networkError);+ // `network_error` is not in the dictionary's code table: the client built the sentence itself.+ expect(probeRefusalFor(null, { run: 4, liveRun: 4, error: offline })).toEqual({+ run: 4,+ text: S.errors.networkError,+ });+ });++ it("falls back to the generic words for a value with nothing to say", () => {+ expect(probeRefusalFor(null, { run: 4, liveRun: 4, error: undefined })).toEqual({+ run: 4,+ text: S.common.unknownError,+ });+ });+});