From 4b990d556f3b454b6e89821077a2b3f9993a8529 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Mon, 12 Oct 2026 09:24:33 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat(web):=20critical-update=20banner=20?= =?UTF-8?q?=E2=80=94=20the=20#1870=20notice=20reaches=20the=20browser?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The critical-update line (#1870, #1977 display policy) only ever surfaced on the /acp panel and acp_status; the web UI had NO update notice at all — the browser only had the disk-vs-running stale banner. A remote user on an old install never learned a critical release existed, which the notes-package staleout of 0.1.191-0.1.193 made painfully visible. - admin.ts: one updateReadyLine() feeds BOTH /__bili/status and /__bili/overview (the #2152 advisory-parity lesson: one source, no drift) — null when invisible (#1977: routine/recommended stay silent) - page.ts: #update-banner above #stale-banner (the original surface is kept untouched; the new banner carries release context, stale stays the generic restart cue) - client.ts renderBanners: shows the wire line behind a localized label, escapeHtml'd (registry summary is remote-doc text) - tests/web-update-banner.test.ts: wire parity across both endpoints, #1977 silence for non-critical spans, ready vs available wording, pending-restart branch, page/client/escape assertions --- src/server/admin.ts | 16 +++- src/web/client.ts | 17 ++++ src/web/i18n.ts | 2 + src/web/page.ts | 1 + tests/web-update-banner.test.ts | 150 ++++++++++++++++++++++++++++++++ 5 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 tests/web-update-banner.test.ts diff --git a/src/server/admin.ts b/src/server/admin.ts index 5dc099a08a..9a22b7b467 100644 --- a/src/server/admin.ts +++ b/src/server/admin.ts @@ -16,6 +16,7 @@ import { getBlindTunnelStats } from "../mitm.js"; import { handlePluginCompact, handlePluginFork, handlePluginManifest, handlePluginRegister, handlePluginRuntimeInfo, handlePluginSessionName, handlePluginSnapshot, handlePluginStatus, handlePluginTool } from "../plugin.js"; import { parseAgentProviderReport, recordAgentProviders, agentProviderRecipes, sanitizeAgentProviderField } from "../agent-providers.js"; import { defaultLogFile } from "../paths.js"; +import { describeUpdateReady, getUpdateVisibility } from "../update-notes.js"; import { getUnrecognizedPathStats } from "./observability.js"; import { getStore } from "../persist.js"; import { BodyTooLargeError, headerValue, readBody, selfAdminProbePath } from "../server.js"; @@ -723,6 +724,18 @@ function currentAdvisoryPayload() { /** Stale-install state for the web UI badge (#811): whether the on-disk * version is newer than the running process, plus the opt-in flag state and * the live in-flight request count. */ +// #1870/#1977 web surface: the /acp panel and acp_status carry the critical +// update line, but the web UI had NO update notice at all — the browser only +// had the disk-vs-running stale banner. Shared single source (the #2152 +// advisory-parity lesson): one helper feeds BOTH /__bili/status and +// /__bili/overview, so the web banner's data source can never drift from the +// panel's. null when the span is invisible (routine/recommended-only or clean +// install — silent by default, #1977). +function updateReadyLine(): string | null { + const upd = getUpdateVisibility(VERSION); + return upd.visible ? describeUpdateReady(upd) : null; +} + async function sendStatus(res: http.ServerResponse, opts: ProxyOptions): Promise { let diskVersion: string | undefined; let stale = false; @@ -739,7 +752,7 @@ async function sendStatus(res: http.ServerResponse, opts: ProxyOptions): Promise loggerLog("warn", `split-session canary (#2170): conversation ${w.base} has live traffic under multiple session keys (design persona forks are excluded): ${w.sessions.map((s) => `${s.id} (requests=${s.requests})`).join("; ")}. For a non-persona host this is the #2165 failure shape (stolen anchor / never-compressing split) — investigate if unexpected.`); } } - res.end(JSON.stringify({ version: VERSION, commit: BUILD_COMMIT, diskVersion, stale, autoRestartOnUpdate: opts.autoRestartOnUpdate, advisory: currentAdvisoryPayload(), pluginAdvisories: detectCostAdvisories(process.env), inFlight: totalInFlight(), splitSessions: splitWarnings, conflicts: summarizeConflicts(listSessions()) }, null, 2)); + res.end(JSON.stringify({ version: VERSION, commit: BUILD_COMMIT, diskVersion, stale, updateReady: updateReadyLine(), autoRestartOnUpdate: opts.autoRestartOnUpdate, advisory: currentAdvisoryPayload(), pluginAdvisories: detectCostAdvisories(process.env), inFlight: totalInFlight(), splitSessions: splitWarnings, conflicts: summarizeConflicts(listSessions()) }, null, 2)); } // #2090 plan A — read-only view backing the web UI's "Signed upstreams" card: @@ -787,6 +800,7 @@ async function sendOverview(res: http.ServerResponse, opts: ProxyOptions): Promi commit: BUILD_COMMIT, diskVersion, stale, + updateReady: updateReadyLine(), autoRestartOnUpdate: opts.autoRestartOnUpdate, advisory: currentAdvisoryPayload(), pluginAdvisories: detectCostAdvisories(process.env), diff --git a/src/web/client.ts b/src/web/client.ts index a25f92dac2..0f11d900e2 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -484,6 +484,23 @@ export const WEB_CLIENT = `(function () { } } function renderBanners(d) { + // #1870 web surface: critical update notice (#1977 — only critical + // spans ever reach here; the server sends null otherwise). Kept ABOVE + // the stale banner: it carries the release context (version + summary), + // while stale-banner stays the generic disk-vs-running restart cue. + const ub = $("update-banner"); + if (ub) { + const line = d.updateReady; + if (line) { + ub.hidden = false; + ub.classList.add("show"); + ub.innerHTML = "" + t("sys.update") + " " + escapeHtml(line); + } else { + ub.hidden = true; + ub.classList.remove("show"); + ub.innerHTML = ""; + } + } const stale = $("stale-banner"); if (d.stale) { stale.hidden = false; diff --git a/src/web/i18n.ts b/src/web/i18n.ts index 6b823204f6..e005f741a0 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -100,6 +100,7 @@ export const MESSAGES: Record> = { "sys.disk_version": "磁盘版本", "sys.inflight": "进行中请求", "sys.blind_tunnels": "MITM 盲隧道(CONNECT 后无 TLS)", + "sys.update": "升级提醒:", "sys.stale": "磁盘已有新版本 v{disk} —— 重启 bili 生效(当前运行 v{running})", "sys.stale_auto": "自动重启已启用,空闲时自动切换", "sys.stale_manual": "自动重启未启用(需要 --auto-restart-on-update)", @@ -536,6 +537,7 @@ export const MESSAGES: Record> = { "sys.disk_version": "On-disk version", "sys.inflight": "In-flight requests", "sys.blind_tunnels": "MITM blind tunnels (CONNECT without TLS)", + "sys.update": "Update notice:", "sys.stale": "Newer version v{disk} on disk — restart bili to apply (running v{running})", "sys.stale_auto": "Auto-restart enabled — switches automatically when idle", "sys.stale_manual": "Auto-restart not enabled (needs --auto-restart-on-update)", diff --git a/src/web/page.ts b/src/web/page.ts index 4802d0448b..9e3dc8174c 100644 --- a/src/web/page.ts +++ b/src/web/page.ts @@ -21,6 +21,7 @@ export function renderPage(origin: string, version: string, embed = false, theme return `billion-context
billion-contextv${version}
+ diff --git a/tests/web-update-banner.test.ts b/tests/web-update-banner.test.ts new file mode 100644 index 0000000000..6021532d10 --- /dev/null +++ b/tests/web-update-banner.test.ts @@ -0,0 +1,150 @@ +// #1870 web surface: the critical-update notice reached the /acp panel and +// acp_status, but the web UI had NO update banner at all — the browser only +// had the disk-vs-running stale banner, so a remote user on an old install +// never learned a critical release existed (the exact gap the notes-package +// staleout of 0.1.191-0.1.193 made visible). The fix shares one +// updateReadyLine() between /__bili/status and /__bili/overview; these tests +// pin the wire contract both banners/panels read: +// 1. PARITY (#2152 lesson): status and overview report byte-identical +// updateReady — null when invisible, the describeUpdateReady line when a +// critical span is pending. +// 2. #1977 silence: routine/recommended-only spans stay null on the wire +// (the web banner must NOT become a routine-update nag). +// 3. the page actually ships the banner element and the client references +// it + escapes the remote-doc line (registry text → innerHTML). +import test from "node:test"; +import assert from "node:assert/strict"; +import http from "node:http"; +import { once } from "node:events"; +import { mkdtempSync } from "node:fs"; +import { tmpdir } from "node:os"; +import path from "node:path"; +import { defaultConfig } from "acp-kernel"; +import { startServer } from "../src/server.ts"; +import type { ProxyOptions } from "../src/config.ts"; +import { SessionStore, _setStoreForTest } from "../src/persist.ts"; +import { _setForTest as setRegistryForTest } from "../src/registry.ts"; +import { _resetReleaseNotesWatcherForTest, _setReleaseNotesStateForTest, type ReleaseNoteEntry } from "../src/update-notes.ts"; +import { renderPage } from "../src/web/page.ts"; +import { WEB_CLIENT } from "../src/web/client.ts"; +import { rmrf } from "./tmp-rm.ts"; + +process.env.BILI_PERSIST_ZSTD = "0"; + +function close(server: http.Server): Promise { + return new Promise((resolve, reject) => server.close((error) => (error ? reject(error) : resolve()))); +} + +async function freePort(): Promise { + const server = http.createServer(); + server.listen(0, "127.0.0.1"); + await once(server, "listening"); + const port = (server.address() as { port: number }).port; + await close(server); + return port; +} + +type Wire = { updateReady: string | null }; + +async function fetchWire(port: number, path: string): Promise { + const res = await fetch(`http://127.0.0.1:${port}${path}`); + assert.equal(res.status, 200, `${path} answers 200`); + return (await res.json()) as Wire; +} + +function entry(version: string, tier: "routine" | "recommended" | "critical", summary: string): ReleaseNoteEntry { + return { version, tier, summary, date: "2026-10-12" }; +} + +test("#1870 web surface: /__bili/overview and /__bili/status share one updateReady line (banner data source)", async () => { + // Hermetic sessions dir: /__bili/overview walks the disk store, and a missing + // dir rejects loudly by design (#1937) — pin an existing temp dir. + const prevSessionsDir = process.env.BILI_SESSIONS_DIR; + const sessionsDir = mkdtempSync(path.join(tmpdir(), "bili-update-banner-")); + process.env.BILI_SESSIONS_DIR = sessionsDir; + _setStoreForTest(new SessionStore({ enabled: false })); + setRegistryForTest({}); + const upstreamPort = await freePort(); // never contacted — management endpoints only + const opts: ProxyOptions = { + port: 0, + host: "127.0.0.1", + upstream: `http://127.0.0.1:${upstreamPort}`, + routes: {}, + modelContextLimit: 400_000, + kernelConfig: defaultConfig(400_000), + compress: { injectTool: false, injectNudge: false }, + promptCache: { routing: "auto" }, + sessionHeader: "x-acp-session", + log: false, + debug: false, + passthrough: false, + autoUpdate: false, + compat: { roles: {} }, + streamErrorShape: "protocol", + passthroughSource: null, + autoRestartOnUpdate: false, + updateTag: "latest", + advisoryCheck: false, + releaseNotesCheck: false, + mitm: { enabled: false, domains: [] }, + }; + const proxy = await startServer(opts); + await once(proxy, "listening"); + const port = (proxy.address() as { port: number }).port; + try { + // 1) empty watcher state (fresh boot, check never ran) → null on BOTH + // surfaces — the banner stays hidden, not crashy. + _resetReleaseNotesWatcherForTest(); + let s = await fetchWire(port, "/__bili/status"); + let o = await fetchWire(port, "/__bili/overview"); + assert.equal(o.updateReady, null, "overview reports null updateReady with empty state"); + assert.deepEqual(o.updateReady, s.updateReady, "overview/status updateReady parity (empty state)"); + + // 2) routine/recommended-only span → STILL null (#1977: the web banner + // must not become a routine-update nag). + _setReleaseNotesStateForTest({ entries: [entry("99.0.1", "recommended", "polish"), entry("99.0.0", "routine", "chores")] }); + s = await fetchWire(port, "/__bili/status"); + o = await fetchWire(port, "/__bili/overview"); + assert.equal(o.updateReady, null, "recommended/routine span stays invisible on the wire"); + assert.deepEqual(o.updateReady, s.updateReady, "overview/status updateReady parity (invisible span)"); + + // 3) critical span → the describeUpdateReady line on BOTH surfaces, + // byte-identical, carrying version + summary + install hint. + _setReleaseNotesStateForTest({ entries: [entry("99.0.2", "critical", "fixes cache corruption")] }); + s = await fetchWire(port, "/__bili/status"); + o = await fetchWire(port, "/__bili/overview"); + assert.ok(typeof o.updateReady === "string" && o.updateReady.length > 0, "critical span surfaces a line"); + assert.deepEqual(o.updateReady, s.updateReady, "overview/status updateReady parity (critical span)"); + assert.ok(o.updateReady!.includes("Critical update available:"), "carries the available wording"); + assert.ok(o.updateReady!.includes("99.0.2"), "names the version"); + assert.ok(o.updateReady!.includes("npm install -g billion-context@99.0.2"), "carries the install hint"); + + // 4) pending restart with a critical in span → the ready/restart branch. + _setReleaseNotesStateForTest({ entries: [entry("99.0.3", "critical", "fixes cache corruption")], diskVersion: "99.0.3" }); + s = await fetchWire(port, "/__bili/status"); + o = await fetchWire(port, "/__bili/overview"); + assert.deepEqual(o.updateReady, s.updateReady, "overview/status updateReady parity (pending restart)"); + assert.ok(o.updateReady!.includes("Critical update ready:"), "carries the ready wording"); + assert.ok(o.updateReady!.includes("restart to finish"), "carries the restart instruction"); + } finally { + _resetReleaseNotesWatcherForTest(); + await close(proxy); + await rmrf(sessionsDir); + if (prevSessionsDir === undefined) delete process.env.BILI_SESSIONS_DIR; + else process.env.BILI_SESSIONS_DIR = prevSessionsDir; + } +}); + +test("#1870 web surface: the page ships the banner element and the client renders it escaped", () => { + const html = renderPage("http://127.0.0.1:19999", "0.0.0-test"); + assert.ok(html.includes('id="update-banner"'), "page carries the update-banner div"); + // the stale banner (the original surface) stays untouched alongside it + assert.ok(html.includes('id="stale-banner"'), "stale-banner kept"); + + assert.ok(WEB_CLIENT.includes('"update-banner"'), "client targets the update-banner element"); + assert.ok(WEB_CLIENT.includes("d.updateReady"), "client reads the wire field"); + assert.ok(WEB_CLIENT.includes('t("sys.update")'), "client uses the localized label"); + // remote-doc text (registry summary) flows through innerHTML → must be escaped + const m = /innerHTML = "" \+ t\("sys\.update"\) \+ "<\/strong> " \+ escapeHtml\(line\)/; + assert.ok(m.test(WEB_CLIENT), "the update line is HTML-escaped before innerHTML"); +}); From 28602246f9696d492c9580b8f3fc459704c4c97f Mon Sep 17 00:00:00 2001 From: ework-agent Date: Mon, 12 Oct 2026 10:14:32 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix(update-notes):=20drop=20the=20npm=20ins?= =?UTF-8?q?tall=20prescription=20=E2=80=94=20hosts=20install=20differently?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit describeUpdateReady and the acp_status section both told every user to `npm install -g billion-context@X`, but bili runs under several hosts (npm -g / opencode plugin / dsh / pi) with different install flows — the wrong hint is worse than none. Name the version, let each client's own docs say how. - update-notes.ts: describeUpdateReady loses the install suffix on all branches (web banner, /acp panel, acp_status all share the wording) - acp-status.ts: drop the "Update with: npm install -g …" line - tests: pin the ABSENCE of any npm-install prescription --- src/acp-status.ts | 5 ++--- src/update-notes.ts | 17 ++++++++++------- tests/update-notes.test.ts | 7 ++++--- tests/web-update-banner.test.ts | 2 +- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/acp-status.ts b/src/acp-status.ts index bcc125fd6f..eb44a1de87 100644 --- a/src/acp-status.ts +++ b/src/acp-status.ts @@ -308,9 +308,8 @@ export function handleAcpStatus(args: Record, ctx: AcpStatusCtx for (const e of upd.span) { lines.push(` · ${e.version} [${e.tier}] ${e.summary}`); } - if (!upd.pendingRestart) { - lines.push(` Update with: npm install -g billion-context@${upd.span[upd.span.length - 1]?.version ?? "latest"}`); - } + // No install command on purpose: hosts differ (npm -g / opencode + // plugin / dsh / pi) — naming the version is host-neutral advice. lines.push("Live state: GET /__bili/status → update."); extra.push(...lines); } diff --git a/src/update-notes.ts b/src/update-notes.ts index 88fddd2826..c84cb472b3 100644 --- a/src/update-notes.ts +++ b/src/update-notes.ts @@ -181,11 +181,14 @@ export function getUpdateVisibility(runningVersion: string): UpdateVisibility & }; } -/** Shared wording for the /acp panel line — one line, stripper-safe slot is - * the caller's job. Kept compact: the panel is small, and acp_status carries - * the full span. Only ever rendered for critical spans (#1977); the final - * fallback branch exists for totality (invisible states never reach the - * surfaces, but the function must stay total for future callers). */ +/** Shared wording for the /acp panel line, acp_status and the web update + * banner — one line, stripper-safe slot is the caller's job. Kept compact: + * the panel is small, and acp_status carries the full span. Only ever + * rendered for critical spans (#1977); the final fallback branch exists for + * totality (invisible states never reach the surfaces, but the function + * must stay total for future callers). NEVER prescribes an install command: + * hosts differ (npm -g / opencode plugin / dsh / pi) and the wrong hint is + * worse than none — name the version, let the client's own docs say how. */ export function describeUpdateReady(v: UpdateVisibility): string { const latest = v.span.length > 0 ? v.span[v.span.length - 1].version : v.diskVersion; const topCritical = v.span.find((e) => e.tier === "critical"); @@ -194,9 +197,9 @@ export function describeUpdateReady(v: UpdateVisibility): string { return `Critical update ready: ${latest} — restart to finish.${notable}`; } if (topCritical && latest !== undefined) { - return `Critical update available: ${latest} — ${topCritical.summary} (npm install -g billion-context@${latest})`; + return `Critical update available: ${latest} — ${topCritical.summary}`; } - return `Update available: ${latest ?? "newer version"} — npm install -g billion-context@${latest ?? "latest"}`; + return `Update available: ${latest ?? "newer version"}.`; } function throttleFile(): string { diff --git a/tests/update-notes.test.ts b/tests/update-notes.test.ts index 85d179935f..8ccd2525cd 100644 --- a/tests/update-notes.test.ts +++ b/tests/update-notes.test.ts @@ -156,7 +156,7 @@ test("#1977 describeUpdateReady: critical wording + byte-stability", () => { _setReleaseNotesStateForTest({ entries: ENTRIES }); // no disk info const rec = describeUpdateReady(getUpdateVisibility("0.1.179")); assert.ok(rec.startsWith("Critical update available: 0.1.181 —"), `critical wording (got: ${rec})`); - assert.ok(rec.includes("npm install -g billion-context@0.1.181"), "manual command when restart cannot finish it"); + assert.ok(!rec.includes("npm install"), "no install command — hosts differ (npm -g / opencode / dsh / pi)"); // Span with NO critical entry + no pending restart = invisible; the // routine-only branch exists for panel completeness only. @@ -242,11 +242,12 @@ test("#1977 acp_status: CRITICAL UPDATE READY section lists the span; clean + no assert.ok(out.text.includes(`· ${NEXT2} [routine] docs and log polish`), "span renders up to the disk version the restart will finish"); assert.ok(out.text.includes("GET /__bili/status → update"), "points at the live-state field"); - // No disk info (auto-update off): AVAILABLE wording + manual command. + // No disk info (auto-update off): AVAILABLE wording — and NO install + // command anywhere (hosts differ: npm -g / opencode / dsh / pi). _setReleaseNotesStateForTest({ entries: SURFACE_ENTRIES }); const avail = handleAcpStatus({}, ctx); assert.ok(avail.text.includes("CRITICAL UPDATE AVAILABLE (instance-level):"), "available headline when nothing is pending"); - assert.ok(avail.text.includes(`npm install -g billion-context@${NEXT2}`), "manual update command present"); + assert.ok(!avail.text.includes("npm install"), "no npm install prescription (host-neutral wording)"); assert.ok(!avail.text.includes("UPDATE READY"), "ready wording reserved for the pending-restart case"); } finally { _resetReleaseNotesWatcherForTest(); diff --git a/tests/web-update-banner.test.ts b/tests/web-update-banner.test.ts index 6021532d10..ab4db211da 100644 --- a/tests/web-update-banner.test.ts +++ b/tests/web-update-banner.test.ts @@ -117,7 +117,7 @@ test("#1870 web surface: /__bili/overview and /__bili/status share one updateRea assert.deepEqual(o.updateReady, s.updateReady, "overview/status updateReady parity (critical span)"); assert.ok(o.updateReady!.includes("Critical update available:"), "carries the available wording"); assert.ok(o.updateReady!.includes("99.0.2"), "names the version"); - assert.ok(o.updateReady!.includes("npm install -g billion-context@99.0.2"), "carries the install hint"); + assert.ok(!o.updateReady!.includes("npm install"), "no npm install prescription (hosts differ: npm -g / opencode / dsh / pi)"); // 4) pending restart with a critical in span → the ready/restart branch. _setReleaseNotesStateForTest({ entries: [entry("99.0.3", "critical", "fixes cache corruption")], diskVersion: "99.0.3" }); From aa14eb6b0e46b1c537ce3d49a703d0396f6a16fd Mon Sep 17 00:00:00 2001 From: ework-agent Date: Mon, 12 Oct 2026 10:27:30 +0800 Subject: [PATCH 3/3] fix(web): update banner says ">= version" and composes zh/en separately MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The banner read "Critical update available: 0.1.193" — as if exactly that version were the target. Any release >= the critical one is safe, and hosts with auto-update often land on a newer build, so the guidance must be "upgrade to vX or newer" (大到等于). Baking an English sentence also left the zh UI showing a mixed-language line. - update-notes.ts: describeUpdateReady's available branch now names the MINIMUM fixed version (first critical in the ascending span) with a >= prefix; new updateBannerPayload() exports kind/version/summary so the SERVER never bakes a sentence — locales compose it - admin.ts: /__bili/status + /__bili/overview carry the structured payload - client.ts + i18n.ts: zh 「请升级到 v{version} 或更新版本」/ en "upgrade to v{version} or newer", ready branch "重启 bili 即可生效" / "restart bili to apply" — each fully localized, remote summary HTML-escaped - tests: pin version selection (minimum critical, disk version on ready), parity, #1977 silence, per-locale composition, no npm-install prescription --- src/server/admin.ts | 20 ++++++++++-------- src/update-notes.ts | 26 ++++++++++++++++++++++- src/web/client.ts | 9 ++++++-- src/web/i18n.ts | 4 ++++ tests/update-notes.test.ts | 11 ++++++++-- tests/web-update-banner.test.ts | 37 +++++++++++++++++++-------------- 6 files changed, 77 insertions(+), 30 deletions(-) diff --git a/src/server/admin.ts b/src/server/admin.ts index 9a22b7b467..88e6a7180e 100644 --- a/src/server/admin.ts +++ b/src/server/admin.ts @@ -16,7 +16,7 @@ import { getBlindTunnelStats } from "../mitm.js"; import { handlePluginCompact, handlePluginFork, handlePluginManifest, handlePluginRegister, handlePluginRuntimeInfo, handlePluginSessionName, handlePluginSnapshot, handlePluginStatus, handlePluginTool } from "../plugin.js"; import { parseAgentProviderReport, recordAgentProviders, agentProviderRecipes, sanitizeAgentProviderField } from "../agent-providers.js"; import { defaultLogFile } from "../paths.js"; -import { describeUpdateReady, getUpdateVisibility } from "../update-notes.js"; +import { getUpdateVisibility, updateBannerPayload } from "../update-notes.js"; import { getUnrecognizedPathStats } from "./observability.js"; import { getStore } from "../persist.js"; import { BodyTooLargeError, headerValue, readBody, selfAdminProbePath } from "../server.js"; @@ -725,15 +725,17 @@ function currentAdvisoryPayload() { * version is newer than the running process, plus the opt-in flag state and * the live in-flight request count. */ // #1870/#1977 web surface: the /acp panel and acp_status carry the critical -// update line, but the web UI had NO update notice at all — the browser only +// update payload, but the web UI had NO update notice at all — the browser only // had the disk-vs-running stale banner. Shared single source (the #2152 // advisory-parity lesson): one helper feeds BOTH /__bili/status and // /__bili/overview, so the web banner's data source can never drift from the -// panel's. null when the span is invisible (routine/recommended-only or clean -// install — silent by default, #1977). -function updateReadyLine(): string | null { - const upd = getUpdateVisibility(VERSION); - return upd.visible ? describeUpdateReady(upd) : null; +// panel's. STRUCTURED, not a baked English sentence: the client composes the +// sentence per locale (zh/en) from kind/version/summary, and "available" +// carries the MINIMUM fixed version so every locale can say "v{version} 或更新版本 / +// v{version} or newer". null when the span is invisible (routine/recommended- +// only or clean install — silent by default, #1977). +function updateReadyPayload(): { kind: "available" | "ready"; version: string; summary: string } | null { + return updateBannerPayload(getUpdateVisibility(VERSION)); } async function sendStatus(res: http.ServerResponse, opts: ProxyOptions): Promise { @@ -752,7 +754,7 @@ async function sendStatus(res: http.ServerResponse, opts: ProxyOptions): Promise loggerLog("warn", `split-session canary (#2170): conversation ${w.base} has live traffic under multiple session keys (design persona forks are excluded): ${w.sessions.map((s) => `${s.id} (requests=${s.requests})`).join("; ")}. For a non-persona host this is the #2165 failure shape (stolen anchor / never-compressing split) — investigate if unexpected.`); } } - res.end(JSON.stringify({ version: VERSION, commit: BUILD_COMMIT, diskVersion, stale, updateReady: updateReadyLine(), autoRestartOnUpdate: opts.autoRestartOnUpdate, advisory: currentAdvisoryPayload(), pluginAdvisories: detectCostAdvisories(process.env), inFlight: totalInFlight(), splitSessions: splitWarnings, conflicts: summarizeConflicts(listSessions()) }, null, 2)); + res.end(JSON.stringify({ version: VERSION, commit: BUILD_COMMIT, diskVersion, stale, updateReady: updateReadyPayload(), autoRestartOnUpdate: opts.autoRestartOnUpdate, advisory: currentAdvisoryPayload(), pluginAdvisories: detectCostAdvisories(process.env), inFlight: totalInFlight(), splitSessions: splitWarnings, conflicts: summarizeConflicts(listSessions()) }, null, 2)); } // #2090 plan A — read-only view backing the web UI's "Signed upstreams" card: @@ -800,7 +802,7 @@ async function sendOverview(res: http.ServerResponse, opts: ProxyOptions): Promi commit: BUILD_COMMIT, diskVersion, stale, - updateReady: updateReadyLine(), + updateReady: updateReadyPayload(), autoRestartOnUpdate: opts.autoRestartOnUpdate, advisory: currentAdvisoryPayload(), pluginAdvisories: detectCostAdvisories(process.env), diff --git a/src/update-notes.ts b/src/update-notes.ts index c84cb472b3..ca149b52ec 100644 --- a/src/update-notes.ts +++ b/src/update-notes.ts @@ -197,11 +197,35 @@ export function describeUpdateReady(v: UpdateVisibility): string { return `Critical update ready: ${latest} — restart to finish.${notable}`; } if (topCritical && latest !== undefined) { - return `Critical update available: ${latest} — ${topCritical.summary}`; + // ≥ the MINIMUM version carrying the fix (topCritical = first critical + // in the ascending span): any version at-or-above it is safe, so the + // line must read "≥ X", not "X" — pinning exactly X would be wrong + // advice for hosts whose installer grabbed a newer release. + return `Critical update available: ≥ ${topCritical.version} — ${topCritical.summary}`; } return `Update available: ${latest ?? "newer version"}.`; } +/** Localizable wire payload for the web update banner (#1870 web surface): + * the SERVER must not bake an English sentence — the UI ships zh + en, so + * it sends kind/version/summary and lets i18n compose the sentence + * ("upgrade to v{version} or newer", separately translated per locale). + * available → version = the MINIMUM version carrying the critical fix + * (first critical in the ascending span; anything ≥ it is safe). + * ready → version = the on-disk version a restart delivers. + * null when the span is invisible (#1977: routine/recommended stay silent). */ +export function updateBannerPayload(v: UpdateVisibility & { visible: boolean }): { kind: "available" | "ready"; version: string; summary: string } | null { + if (!v.visible) return null; + const criticals = v.span.filter((e) => e.tier === "critical"); + const first = criticals[0]; + const newest = criticals[criticals.length - 1] ?? first; + if (first === undefined || newest === undefined) return null; // defensive: visible implies a critical, but stay total + if (v.pendingRestart && v.diskVersion !== undefined) { + return { kind: "ready", version: v.diskVersion, summary: newest.summary }; + } + return { kind: "available", version: first.version, summary: first.summary }; +} + function throttleFile(): string { return path.join(cacheDir(), ".release-notes-check"); } diff --git a/src/web/client.ts b/src/web/client.ts index 0f11d900e2..56addc9893 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -490,8 +490,13 @@ export const WEB_CLIENT = `(function () { // while stale-banner stays the generic disk-vs-running restart cue. const ub = $("update-banner"); if (ub) { - const line = d.updateReady; - if (line) { + const u = d.updateReady; + if (u && typeof u === "object" && typeof u.version === "string") { + // compose per locale from kind/version/summary — "available" + // carries the MINIMUM fixed version, so each locale can say + // "v{version} 或更新版本" / "v{version} or newer" separately. + const vars = { version: u.version, summary: u.summary || "" }; + const line = u.kind === "ready" ? t("sys.update_ready", vars) : t("sys.update_available", vars); ub.hidden = false; ub.classList.add("show"); ub.innerHTML = "" + t("sys.update") + " " + escapeHtml(line); diff --git a/src/web/i18n.ts b/src/web/i18n.ts index e005f741a0..1fa559bdb2 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -101,6 +101,8 @@ export const MESSAGES: Record> = { "sys.inflight": "进行中请求", "sys.blind_tunnels": "MITM 盲隧道(CONNECT 后无 TLS)", "sys.update": "升级提醒:", + "sys.update_available": "发现 critical 修复,请升级到 v{version} 或更新版本 — {summary}", + "sys.update_ready": "critical 修复已就绪 v{version} — 重启 bili 即可生效", "sys.stale": "磁盘已有新版本 v{disk} —— 重启 bili 生效(当前运行 v{running})", "sys.stale_auto": "自动重启已启用,空闲时自动切换", "sys.stale_manual": "自动重启未启用(需要 --auto-restart-on-update)", @@ -538,6 +540,8 @@ export const MESSAGES: Record> = { "sys.inflight": "In-flight requests", "sys.blind_tunnels": "MITM blind tunnels (CONNECT without TLS)", "sys.update": "Update notice:", + "sys.update_available": "critical fix available — upgrade to v{version} or newer: {summary}", + "sys.update_ready": "critical fix ready (v{version}) — restart bili to apply", "sys.stale": "Newer version v{disk} on disk — restart bili to apply (running v{running})", "sys.stale_auto": "Auto-restart enabled — switches automatically when idle", "sys.stale_manual": "Auto-restart not enabled (needs --auto-restart-on-update)", diff --git a/tests/update-notes.test.ts b/tests/update-notes.test.ts index 8ccd2525cd..c14f8cfd60 100644 --- a/tests/update-notes.test.ts +++ b/tests/update-notes.test.ts @@ -23,6 +23,7 @@ import { spanNotes, getUpdateVisibility, describeUpdateReady, + updateBannerPayload, type ReleaseNoteEntry, } from "../src/update-notes.ts"; import { VERSION } from "../src/version.ts"; @@ -152,11 +153,17 @@ test("#1977 describeUpdateReady: critical wording + byte-stability", () => { assert.ok(line.startsWith("Critical update ready: 0.1.181 — restart to finish."), `pending-restart wording (got: ${line})`); assert.ok(line.includes("#1844"), "top critical summary carried"); assert.equal(line, describeUpdateReady(getUpdateVisibility("0.1.179")), "byte-stable for identical state"); + assert.deepEqual(updateBannerPayload(pending), { kind: "ready", version: "0.1.181", summary: "OpenCode WebSocket traffic intercepted again (#1844)" }, "wire payload (ready): names the disk version, newest critical summary"); _setReleaseNotesStateForTest({ entries: ENTRIES }); // no disk info - const rec = describeUpdateReady(getUpdateVisibility("0.1.179")); - assert.ok(rec.startsWith("Critical update available: 0.1.181 —"), `critical wording (got: ${rec})`); + const recVis = getUpdateVisibility("0.1.179"); + const rec = describeUpdateReady(recVis); + assert.ok(rec.startsWith("Critical update available: ≥ 0.1.180 —"), `critical wording names the MINIMUM fixed version (got: ${rec})`); assert.ok(!rec.includes("npm install"), "no install command — hosts differ (npm -g / opencode / dsh / pi)"); + // span = [0.1.180 critical, 0.1.181 routine] ascending: the payload must + // carry 0.1.180 (the minimum version WITH the fix), not 0.1.181 — the + // locales render "v{version} 或更新版本 / v{version} or newer" from it. + assert.deepEqual(updateBannerPayload(recVis), { kind: "available", version: "0.1.180", summary: "OpenCode WebSocket traffic intercepted again (#1844)" }, "wire payload (available): minimum fixed version, never the routine tail"); // Span with NO critical entry + no pending restart = invisible; the // routine-only branch exists for panel completeness only. diff --git a/tests/web-update-banner.test.ts b/tests/web-update-banner.test.ts index ab4db211da..9a01d8ba8d 100644 --- a/tests/web-update-banner.test.ts +++ b/tests/web-update-banner.test.ts @@ -3,15 +3,18 @@ // had the disk-vs-running stale banner, so a remote user on an old install // never learned a critical release existed (the exact gap the notes-package // staleout of 0.1.191-0.1.193 made visible). The fix shares one -// updateReadyLine() between /__bili/status and /__bili/overview; these tests -// pin the wire contract both banners/panels read: +// updateReadyPayload() between /__bili/status and /__bili/overview; these +// tests pin the wire contract both banners/panels read: // 1. PARITY (#2152 lesson): status and overview report byte-identical -// updateReady — null when invisible, the describeUpdateReady line when a -// critical span is pending. +// updateReady — null when invisible, a STRUCTURED payload when a +// critical span is pending. Structured, not a sentence: the client +// composes zh/en separately ("v{version} 或更新版本 / v{version} or +// newer"), and "available" carries the MINIMUM fixed version. // 2. #1977 silence: routine/recommended-only spans stay null on the wire // (the web banner must NOT become a routine-update nag). // 3. the page actually ships the banner element and the client references -// it + escapes the remote-doc line (registry text → innerHTML). +// it + composes the localized line and escapes it (registry text → +// innerHTML). import test from "node:test"; import assert from "node:assert/strict"; import http from "node:http"; @@ -44,7 +47,7 @@ async function freePort(): Promise { return port; } -type Wire = { updateReady: string | null }; +type Wire = { updateReady: { kind: "available" | "ready"; version: string; summary: string } | null }; async function fetchWire(port: number, path: string): Promise { const res = await fetch(`http://127.0.0.1:${port}${path}`); @@ -108,24 +111,23 @@ test("#1870 web surface: /__bili/overview and /__bili/status share one updateRea assert.equal(o.updateReady, null, "recommended/routine span stays invisible on the wire"); assert.deepEqual(o.updateReady, s.updateReady, "overview/status updateReady parity (invisible span)"); - // 3) critical span → the describeUpdateReady line on BOTH surfaces, - // byte-identical, carrying version + summary + install hint. - _setReleaseNotesStateForTest({ entries: [entry("99.0.2", "critical", "fixes cache corruption")] }); + // 3) critical span → the structured payload on BOTH surfaces, + // byte-identical, carrying the MINIMUM fixed version + summary; + // version selection is pinned so the locales can say "or newer". + _setReleaseNotesStateForTest({ entries: [entry("99.0.2", "critical", "fixes cache corruption"), entry("99.0.1", "critical", "earlier fix")] }); s = await fetchWire(port, "/__bili/status"); o = await fetchWire(port, "/__bili/overview"); - assert.ok(typeof o.updateReady === "string" && o.updateReady.length > 0, "critical span surfaces a line"); + assert.deepEqual(o.updateReady, { kind: "available", version: "99.0.1", summary: "earlier fix" }, "available payload: MINIMUM critical version, not the span tail"); assert.deepEqual(o.updateReady, s.updateReady, "overview/status updateReady parity (critical span)"); - assert.ok(o.updateReady!.includes("Critical update available:"), "carries the available wording"); - assert.ok(o.updateReady!.includes("99.0.2"), "names the version"); - assert.ok(!o.updateReady!.includes("npm install"), "no npm install prescription (hosts differ: npm -g / opencode / dsh / pi)"); + assert.ok(!JSON.stringify(o.updateReady).includes("npm install"), "no npm install prescription (hosts differ: npm -g / opencode / dsh / pi)"); - // 4) pending restart with a critical in span → the ready/restart branch. + // 4) pending restart with a critical in span → the ready/restart branch + // names the DISK version (what a restart delivers). _setReleaseNotesStateForTest({ entries: [entry("99.0.3", "critical", "fixes cache corruption")], diskVersion: "99.0.3" }); s = await fetchWire(port, "/__bili/status"); o = await fetchWire(port, "/__bili/overview"); + assert.deepEqual(o.updateReady, { kind: "ready", version: "99.0.3", summary: "fixes cache corruption" }, "ready payload: names the disk version"); assert.deepEqual(o.updateReady, s.updateReady, "overview/status updateReady parity (pending restart)"); - assert.ok(o.updateReady!.includes("Critical update ready:"), "carries the ready wording"); - assert.ok(o.updateReady!.includes("restart to finish"), "carries the restart instruction"); } finally { _resetReleaseNotesWatcherForTest(); await close(proxy); @@ -144,6 +146,9 @@ test("#1870 web surface: the page ships the banner element and the client render assert.ok(WEB_CLIENT.includes('"update-banner"'), "client targets the update-banner element"); assert.ok(WEB_CLIENT.includes("d.updateReady"), "client reads the wire field"); assert.ok(WEB_CLIENT.includes('t("sys.update")'), "client uses the localized label"); + // zh/en compose SEPARATELY from kind/version/summary (no server-baked sentence) + assert.ok(WEB_CLIENT.includes('t("sys.update_available"'), "client composes the available line per locale"); + assert.ok(WEB_CLIENT.includes('t("sys.update_ready"'), "client composes the ready line per locale"); // remote-doc text (registry summary) flows through innerHTML → must be escaped const m = /innerHTML = "" \+ t\("sys\.update"\) \+ "<\/strong> " \+ escapeHtml\(line\)/; assert.ok(m.test(WEB_CLIENT), "the update line is HTML-escaped before innerHTML");