From eec048bfd0b144173b3cd0581443b8312a52cbd2 Mon Sep 17 00:00:00 2001 From: awork Date: Sat, 17 Oct 2026 02:45:07 +0800 Subject: [PATCH 1/2] fix: register PUT /__bili/external-summary/credential in the admin router (#3443) --- src/server/admin.ts | 4 ++- tests/web-routing.test.ts | 67 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/src/server/admin.ts b/src/server/admin.ts index 434b8982f0..7d599397a8 100644 --- a/src/server/admin.ts +++ b/src/server/admin.ts @@ -28,7 +28,7 @@ import { clearUpstreamAlertsForHost, getUpstreamAlerts } from "../upstream-alert import { formatUpstreamError, getUpstreamConnectionStatus, proxyDispatcher, recordUpstreamConnection, resetProxyCache, resolveProxyDecision } from "../upstream-proxy.js"; import { detectStaleInstall } from "../update.js"; import { PACKAGE_NAME, VERSION, BUILD_COMMIT } from "../version.js"; -import { buildOverview, buildSessionDetail, buildSessionList, buildSessionPage, handleConfigGet, handleConfigPut, hiddenEmptyCount, renderUI } from "../web/index.js"; +import { buildOverview, buildSessionDetail, buildSessionList, buildSessionPage, handleConfigGet, handleConfigPut, handleSummaryCredentialPut, hiddenEmptyCount, renderUI } from "../web/index.js"; import { buildSessionReportMd, buildSessionReportSvg } from "../web/report.js"; import { queryLogLines } from "../web/logs-query.js"; import { buildDiagnostics } from "../web/diagnostics.js"; @@ -262,6 +262,8 @@ export async function handleAdminRoute(req: http.IncomingMessage, res: http.Serv Object.assign(opts.namedProviders, loadNamedProviders()); }, opts.port); } + // #3443: Web UI Save Key — this route was dropped when the admin surface moved here (#1440 P2 cut 1). + if (req.method === "PUT" && req.url === "/__bili/external-summary/credential") return handleSummaryCredentialPut(req, res); if (req.method === "POST" && req.url === "/__bili/config/reload") return handleConfigReload(opts, res, log); // #2102: wipe the diagnostic conflict ledgers (global, or one session via // ?session=). Loopback + trusted-origin gated like every /__bili/ path. diff --git a/tests/web-routing.test.ts b/tests/web-routing.test.ts index 0db61044d2..b443207b92 100644 --- a/tests/web-routing.test.ts +++ b/tests/web-routing.test.ts @@ -160,6 +160,73 @@ test("PUT /__bili/config with providers takes effect without a separate reload c } }); +test("PUT /__bili/external-summary/credential routes to the private store (#3443)", async () => { + _setStoreForTest(new SessionStore({ enabled: false })); + setRegistryForTest({}); + const root = path.join(tmpdir(), `bili-summary-cred-${process.pid}-${Date.now()}`); + mkdirSync(root, { recursive: true }); + const biliConfig = path.join(root, "billion-context.json"); + writeFileSync(biliConfig, JSON.stringify({ providers: { deepseek: { baseUrl: "https://api.deepseek.com", api: "openai", credentialRef: "primary", models: { "deepseek-chat": {} } } }, compress: { externalSummary: { enabled: true, targets: ["deepseek/deepseek-chat"] } } }), "utf8"); + const prevConfig = process.env.BILI_CONFIG_FILE; + process.env.BILI_CONFIG_FILE = biliConfig; + const opts: ProxyOptions = { + port: 0, + host: "127.0.0.1", + upstream: "http://127.0.0.1:1", + routes: {}, + proxy: "", + proxyMode: "direct", + proxySource: "direct", + modelContextLimit: 400_000, + kernelConfig: defaultConfig(400_000), + compress: { injectTool: true, injectNudge: true }, + promptCache: { routing: "auto" }, + sessionHeader: "x-acp-session", + log: false, + debug: false, + passthrough: false, + passthroughSource: null, + autoUpdate: false, + autoRestartOnUpdate: false, + updateTag: "latest", + advisoryCheck: false, + releaseNotesCheck: false, + compat: { roles: {} }, + streamErrorShape: "protocol", + mitm: { enabled: false, domains: [] }, + }; + const proxy = await startServer(opts); + if (!proxy.listening) await once(proxy, "listening"); + const port = (proxy.address() as { port: number }).port; + const base = `http://127.0.0.1:${port}`; + try { + const put = (body: unknown) => fetch(`${base}/__bili/external-summary/credential`, { + method: "PUT", + headers: { "content-type": "application/json" }, + body: JSON.stringify(body), + }); + const malformed = await put({ name: "primary" }); + assert.equal(malformed.status, 400); + assert.match(await malformed.text(), /expected name and key/); + const key = "test-route-never-echoed-key"; + const savedRaw = await (await put({ name: "primary", key })).text(); + assert.equal(savedRaw.includes(key), false); + assert.deepEqual(JSON.parse(savedRaw), { ok: true, configured: true }); + const storePath = `${biliConfig}.summary-credentials.json`; + assert.ok(readFileSync(storePath, "utf8").includes(key), "routed handler wrote the private store file"); + const view = await (await fetch(`${base}/__bili/config`)).json() as { externalSummaryCredentials: Record }; + assert.equal(view.externalSummaryCredentials["secret:primary"], true); + const deletedRaw = await (await put({ name: "primary", key: null })).text(); + assert.deepEqual(JSON.parse(deletedRaw), { ok: true, configured: false }); + const afterDelete = await (await fetch(`${base}/__bili/config`)).json() as { externalSummaryCredentials: Record }; + assert.equal(afterDelete.externalSummaryCredentials["secret:primary"], false); + } finally { + await close(proxy); + if (prevConfig === undefined) delete process.env.BILI_CONFIG_FILE; else process.env.BILI_CONFIG_FILE = prevConfig; + rmrf(root); + } +}); + test("parseCompressSettings round-trips prompts overrides (#155 + #157 interplay)", () => { const withPrompts = { nudgeGrowthTokens: 4000, From aef3fa28cbc3d5457d908fe2c2a95b468c236982 Mon Sep 17 00:00:00 2001 From: awork Date: Sat, 17 Oct 2026 02:45:07 +0800 Subject: [PATCH 2/2] refactor: drop dead web-handler imports left by the admin route extraction --- src/server.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/server.ts b/src/server.ts index c9e672efc3..1079855f36 100644 --- a/src/server.ts +++ b/src/server.ts @@ -88,7 +88,6 @@ import { buildDecisionPrompt, buildDirectiveText, consumeFallback, DEFAULT_DECID import { gcConfigFromEnv, gcSessionFiles } from "./session-gc.js"; import { countImagesInParsedBody, countImagesInRawBody, imageTokensInRawBody, imageTokensInParsedBody, resolveImageBilling, upstreamHost, type ResolvedImageBilling } from "./image-tokens.js"; import { APIG_RESIGN_HEADER, APIG_RESIGN_CREDENTIAL_HEADER, APIG_RESIGN_SCHEME, KNOWN_SIGNATURE_SCHEMES, clearSignedRefusal, decodeApigCredential, inboundSignedScheme, readPendingRefusals, recordSignedRefusal, resignApig, signedRefusal, unresolvedRefusals, type ApigCredential } from "./apig-resign.js"; -import { renderUI, handleConfigGet, handleConfigPut, handleSummaryCredentialPut, buildOverview, buildSessionList, buildSessionPage, buildSessionDetail, hiddenEmptyCount } from "./web/index.js"; import { reapOrphanBlocks } from "./orphan-gc.js"; import { conflictScanEnabled, isDesignBenign, scanClientPlugins, sniffScanClient } from "./thirdparty-scan.js"; import { clearConflictEvents, recordConflict, summarizeConflicts } from "./conflict-watch.js";