From d65bbc3cfc901c785c46707486ffe6054c938f07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=BA=91=E5=91=A8?= <154221037+YunzhouLi-hub@users.noreply.github.com> Date: Mon, 12 Oct 2026 15:51:29 +0800 Subject: [PATCH 1/2] test: guard log-mask #255 dead-upstream ports with holder+assertPortDead (#2889) --- tests/log-mask.test.ts | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/tests/log-mask.test.ts b/tests/log-mask.test.ts index 51576e3be7..518ff8ece0 100644 --- a/tests/log-mask.test.ts +++ b/tests/log-mask.test.ts @@ -393,13 +393,21 @@ test("proxy error log: connection failure to non-public upstream leaks nothing ( setRegistryForTest({}); let proxy: http.Server | undefined; try { + // #2889: grab a proven-free port instead of hardcoding 59999 — a + // squatter on a hardcoded port turns the expected refusal into a + // 403/200 (#1689 family) and false-reds this test. + const holder = http.createServer(); + holder.listen(0, "127.0.0.1"); + await once(holder, "listening"); + const deadPort = (holder.address() as { port: number }).port; + await close(holder); const opts: ProxyOptions = { port: 0, host: "127.0.0.1", upstream: "http://127.0.0.1", proxy: "", routes: { - "http://127.0.0.1:59999": { models: { "gpt-test": { context: 400_000 } } }, + [`http://127.0.0.1:${deadPort}`]: { models: { "gpt-test": { context: 400_000 } } }, }, modelContextLimit: 400_000, kernelConfig: defaultConfig(400_000), @@ -422,7 +430,10 @@ mitm: { enabled: false, domains: [] }, proxy = await startServer(opts); await once(proxy, "listening"); const proxyPort = (proxy.address() as { port: number }).port; - const resp = await fetch(`http://127.0.0.1:${proxyPort}/bili/http://127.0.0.1:59999/v1/chat/completions`, { + // #1689/#2889: prove the freed port is actually dead right before the + // dial — a squatter would turn the expected refusal into a 403/200. + await assertPortDead(deadPort); + const resp = await fetch(`http://127.0.0.1:${proxyPort}/bili/http://127.0.0.1:${deadPort}/v1/chat/completions`, { method: "POST", headers: { "content-type": "application/json", "x-acp-session": "log-mask-err" }, body: JSON.stringify({ model: "gpt-test", messages: [{ role: "user", content: "hi" }] }), @@ -430,7 +441,7 @@ mitm: { enabled: false, domains: [] }, assert.equal(resp.status, 502); await resp.text(); const all = captured.map((c) => c.msg).join("\n"); - assert.ok(!all.includes("127.0.0.1:59999"), `non-public upstream origin leaked into error log:\n${all}`); + assert.ok(!all.includes(`127.0.0.1:${deadPort}`), `non-public upstream origin leaked into error log:\n${all}`); const errLine = captured.find((c) => c.msg.includes("upstream request failed")); assert.ok(errLine, `error log missing:\n${all}`); assert.ok(errLine.msg.includes(""), errLine.msg); @@ -530,13 +541,21 @@ test("ws upgrade rejection: host header scrubbed from log (#255)", async () => { setRegistryForTest({}); let proxy: http.Server | undefined; try { + // #2889: grab a proven-free port instead of hardcoding 59999 — a + // squatter on a hardcoded port turns the expected refusal into a + // 403/200 (#1689 family) and false-reds this test. + const holder = http.createServer(); + holder.listen(0, "127.0.0.1"); + await once(holder, "listening"); + const deadPort = (holder.address() as { port: number }).port; + await close(holder); const opts: ProxyOptions = { port: 0, host: "127.0.0.1", upstream: "http://127.0.0.1", proxy: "", routes: { - "http://127.0.0.1:59999": { models: { "gpt-test": { context: 400_000 } } }, + [`http://127.0.0.1:${deadPort}`]: { models: { "gpt-test": { context: 400_000 } } }, }, modelContextLimit: 400_000, kernelConfig: defaultConfig(400_000), From 2b7f7ec3537e546862e413f04d7500fb79aa83a9 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Mon, 12 Oct 2026 16:48:44 +0800 Subject: [PATCH 2/2] fix(ci): register issue2752 spawner suite in LIVE_FILES (#2816) tests/issue2752-forward-partial-outcome.test.ts (added by c81be81ee, merged via #2782) spawns the real MCP shim over stdio but was never registered in the #2816 tripwire, so every test job died at startup before running a single test since 467b0f648. Concurrency review for c=4: all HTTP servers bind listen(0) dynamic ports; the spawned shim is killed in afterEach; BILI_MCP_PROXY/BILI_CONVERSATION_ID are passed in the child env at spawn time; src/mcp.ts itself binds no port and writes no state. Registered after review per the tripwire contract. --- scripts/run-ci-tests.mjs | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/run-ci-tests.mjs b/scripts/run-ci-tests.mjs index c573dbe4c1..1f01221e44 100644 --- a/scripts/run-ci-tests.mjs +++ b/scripts/run-ci-tests.mjs @@ -39,6 +39,7 @@ const LIVE_FILES = [ "tests/hook-command.test.ts", "tests/index-entry-guard.test.ts", "tests/issue1958-routed-warn.test.ts", + "tests/issue2752-forward-partial-outcome.test.ts", "tests/issue760-percall-conversation.test.ts", "tests/issue927-opencode-install.test.ts", "tests/kimi-native.test.ts",