From cad928afdb5016ec9d38f0e2875ed969c036370c Mon Sep 17 00:00:00 2001 From: awork Date: Wed, 14 Oct 2026 22:00:47 +0800 Subject: [PATCH] test: kill idle keep-alive sockets on harness teardown (#3181) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test harnesses awaited server 'close' after only calling close(), leaving teardown completion to the client-side keep-alive timeout (~4s undici pool). In that window the event loop can drain and node:test cancels every pending test in the file ('Promise resolution is still pending but the event loop has already resolved', cancelledByParent cascade) — reproducible 3x on windows-22 for tests/plugin-fork.test.ts via PR #3166 CI. Fix: call closeIdleConnections() on proxy and upstream right after close() in every paired teardown (138 test files, ~400 sites), so the close event fires immediately. Tests-only; no product code touched. --- tests/absorb-plugin.test.ts | 2 ++ tests/anthropic-beta-window.test.ts | 2 ++ tests/cache-friendly-plugin.test.ts | 2 ++ tests/cache-seam-fuzz.test.ts | 1 + tests/cache-seam-probes.test.ts | 1 + tests/ccr-plugin.test.ts | 12 +++++++----- tests/claude-bridge-e2e.test.ts | 2 ++ tests/codex-compact-e2e.test.ts | 2 ++ tests/codex-local-compaction.test.ts | 2 ++ tests/codex-window-align.test.ts | 2 ++ tests/compaction-trigger-finality.test.ts | 2 ++ tests/configured-window-outranks-registry.test.ts | 2 ++ tests/context-provenance-outbound.test.ts | 2 +- tests/dsh-fork-adopt.test.ts | 2 +- tests/dsh-persona-continuity.test.ts | 2 ++ tests/dsh-persona-fingerprint.test.ts | 2 ++ tests/durable-tool-identity.test.ts | 2 ++ tests/e2e-anthropic.test.ts | 2 ++ tests/e2e-overflow-selfheal.test.ts | 6 ++++++ tests/e2e-relay-5xx-selfheal.test.ts | 6 ++++++ tests/e2e-responses-mid-developer.test.ts | 2 ++ tests/e2e-session-identity.test.ts | 1 + tests/e2e-tag-echo.test.ts | 2 ++ tests/e2e-trae-model-restamp.test.ts | 2 ++ tests/e2e/e2e-image-billing.test.ts | 4 ++++ tests/external-summary-badge.test.ts | 2 ++ tests/fake-completion.test.ts | 4 ++++ tests/fallback-window-floor.test.ts | 4 ++++ tests/first-sight-drain-wire.test.ts | 2 ++ tests/fix-1001-history-rewrite.test.ts | 4 ++++ tests/fix-1075-side-request.test.ts | 2 ++ tests/fix-1117-passthrough.test.ts | 2 ++ tests/fix-1897-leaked-tools-side.test.ts | 2 ++ tests/fix-488-multimodal.test.ts | 1 + tests/fix-781-summary-images.test.ts | 1 + tests/fix-920-bypass-drop.test.ts | 2 ++ tests/fold-round2-shape.test.ts | 2 +- tests/fork-nudge-deadzone.test.ts | 2 +- tests/fork-replica-convergence.test.ts | 2 +- tests/headroom-output-fallback.test.ts | 2 ++ tests/host-usage-postfold.test.ts | 4 ++++ tests/issue-393-registry-window.test.ts | 2 ++ tests/issue1195-overflow-refold.test.ts | 8 ++++++++ tests/issue1204-rules-google-plugin.test.ts | 2 ++ tests/issue1307-side-snapshot.test.ts | 2 ++ tests/issue1320-thinking-mass.test.ts | 2 ++ tests/issue1321-tier-window-cap.test.ts | 2 ++ tests/issue1492-stale-estimate-view.test.ts | 2 ++ tests/issue1493-arm-outbound-payload.test.ts | 6 ++++++ tests/issue1569-window-stamp-and-anchor.test.ts | 2 ++ tests/issue1595-nudge-reanchor.test.ts | 2 ++ tests/issue1819-regurgitation-guard.test.ts | 2 +- tests/issue1820-post-rebuild-anchor.test.ts | 2 ++ tests/issue1841-preflight-futility.test.ts | 2 ++ tests/issue1843-learned-image-cost.test.ts | 2 ++ tests/issue1933-preflight-calibration.test.ts | 5 +++++ tests/issue1987-preflight-baseline-anchor.test.ts | 2 ++ tests/issue1993-preflight-400.test.ts | 2 +- tests/issue2096-clamp-headroom-window.test.ts | 2 ++ .../issue2117-context-estimate-provenance.test.ts | 2 ++ tests/issue2129-restart-measurement-state.test.ts | 2 ++ tests/issue2155-self-heal.test.ts | 7 +++++++ tests/issue2189-preflight-billing-block.test.ts | 8 ++++++++ tests/issue2218-relay-affinity-signal.test.ts | 2 ++ tests/issue2313-probe-forward.test.ts | 2 ++ tests/issue2317-route-miss-diagnostics.test.ts | 3 +++ tests/issue2347-dump-sse-plugin-lane.test.ts | 2 +- tests/issue2407-google-khat-lane.test.ts | 1 + tests/issue2419-dsh-skill-catalog.test.ts | 2 ++ tests/issue2432-dsh-local-compaction.test.ts | 2 ++ tests/issue2446-dsh-mcp-catalog.test.ts | 2 ++ .../issue2447-dsh-workspace-instructions.test.ts | 2 ++ tests/issue2451-dsh-responses-compaction.test.ts | 2 ++ tests/issue2481-dsh-runtime-context.test.ts | 2 ++ tests/issue2490-ledger-floor-doomed-probe.test.ts | 2 ++ tests/issue2499-anthropic-round2-cache.test.ts | 2 ++ tests/issue2601-persona-fork-lineage.test.ts | 2 ++ ...ue2658-dsh-anthropic-google-compaction.test.ts | 4 ++++ tests/issue2672-preflight-blocked-split.test.ts | 2 ++ tests/issue2678-preflight-batch-fold.test.ts | 12 ++++++++++++ ...issue2709-passthrough-compaction-guard.test.ts | 2 ++ tests/issue2733-preflight-codex-shape.test.ts | 4 ++++ ...ssue2832-preflight-deterministic-empty.test.ts | 4 ++++ .../issue2847-doomed-nonretryable-status.test.ts | 2 ++ tests/issue3004-nudge-decide-selfheal.test.ts | 2 ++ tests/issue453-backstop.test.ts | 2 ++ tests/issue496-forward-once-learn.test.ts | 2 ++ tests/issue532-panel-system-tokens.test.ts | 2 ++ tests/issue767-pixel-billing.test.ts | 12 ++++++++++++ tests/issue833-panel-effective-config.test.ts | 2 ++ tests/issue903-request-cost-log.test.ts | 2 ++ tests/main-path-transport-retry.test.ts | 9 +++++++++ tests/mode-upgrade-proof.test.ts | 2 ++ tests/native-compact-terminal.test.ts | 2 ++ tests/nudge-model-decided.test.ts | 2 ++ tests/opencode-fork-adopt.test.ts | 2 +- tests/pi-omp-fork-adopt.test.ts | 2 +- tests/pi-subagent-channel.test.ts | 2 ++ tests/plugin-bypass.test.ts | 2 ++ tests/plugin-fork.test.ts | 2 +- tests/plugin-nudge-injection.test.ts | 2 ++ tests/plugin-protocol.test.ts | 2 ++ tests/plugin-status-provenance.test.ts | 2 +- tests/plugin-terminal-usage.test.ts | 2 +- tests/preflight-client-abort.test.ts | 2 ++ tests/preflight-codex-headroom.test.ts | 2 ++ tests/preflight-compress-responses.test.ts | 2 ++ tests/preflight-compress.test.ts | 8 ++++++++ tests/preflight-covered-ranges.test.ts | 1 + tests/preflight-empty-summary.test.ts | 12 ++++++++++++ tests/preflight-fail-fast.test.ts | 15 +++++++++++++++ tests/preflight-fork-estimate.test.ts | 4 ++++ tests/preflight-google-summary.test.ts | 4 ++++ tests/preflight-hold.test.ts | 8 ++++++++ tests/preflight-incomplete-json.test.ts | 2 +- tests/preflight-max-output-tokens.test.ts | 12 ++++++++++++ tests/preflight-multi-range.test.ts | 6 ++++++ tests/preflight-nonstream-400-probe.test.ts | 2 +- tests/preflight-round-budget.test.ts | 4 ++++ tests/preflight-stream-summary-config.test.ts | 2 +- tests/preflight-stream-summary.test.ts | 6 ++++++ tests/preflight-summary-cap.test.ts | 1 + tests/preflight-summary-length-budget.test.ts | 1 + tests/preflight-transient-empty-retry.test.ts | 4 ++++ tests/preflight-transport-recovery.test.ts | 1 + tests/preflight-window-clamp.test.ts | 2 ++ tests/proxy-noinject-tag-strip.test.ts | 2 ++ tests/responses-plugin-dev-position.test.ts | 2 ++ tests/rules-wire.test.ts | 12 ++++++++++++ tests/runtime-info.test.ts | 2 ++ tests/session-continuity-proof.test.ts | 2 +- tests/session-lock-concurrency.test.ts | 2 ++ tests/side-request-isolation.test.ts | 4 ++++ tests/store-marker-gate.test.ts | 2 ++ tests/stream-keepalive.test.ts | 4 ++++ tests/websearch-side-request.test.ts | 2 ++ tests/wire-exit-gap-cells.test.ts | 6 ++++++ tests/wire-exit-matrix.test.ts | 12 ++++++++++++ 138 files changed, 419 insertions(+), 22 deletions(-) diff --git a/tests/absorb-plugin.test.ts b/tests/absorb-plugin.test.ts index b645e28a45..9d6a26c010 100644 --- a/tests/absorb-plugin.test.ts +++ b/tests/absorb-plugin.test.ts @@ -180,8 +180,10 @@ async function startRig(baseCompress: Record, routeCompress?: R async function closeRig(rig: Rig): Promise { rig.proxy.close(); + rig.proxy.closeIdleConnections?.(); await once(rig.proxy, "close"); rig.upstream.close(); + rig.upstream.closeIdleConnections?.(); await once(rig.upstream, "close"); } diff --git a/tests/anthropic-beta-window.test.ts b/tests/anthropic-beta-window.test.ts index 029a5a0d78..5ed3a338c9 100644 --- a/tests/anthropic-beta-window.test.ts +++ b/tests/anthropic-beta-window.test.ts @@ -125,8 +125,10 @@ function hasEmergencyNudge(body: string): boolean { async function closeRig(rig: Rig): Promise { rig.proxy.close(); + rig.proxy.closeIdleConnections?.(); await once(rig.proxy, "close"); rig.upstream.close(); + rig.upstream.closeIdleConnections?.(); await once(rig.upstream, "close"); } diff --git a/tests/cache-friendly-plugin.test.ts b/tests/cache-friendly-plugin.test.ts index 37d9d70250..fd3d16c7b0 100644 --- a/tests/cache-friendly-plugin.test.ts +++ b/tests/cache-friendly-plugin.test.ts @@ -542,8 +542,10 @@ async function driveWire(wire: Wire, steps: Step[], opts?: DriveOpts): Promise { } async function closeServer(srv: http.Server): Promise { srv.close(); + srv.closeIdleConnections?.(); await Promise.race([once(srv, "close"), new Promise((r) => setTimeout(r, 2000))]); } diff --git a/tests/cache-seam-probes.test.ts b/tests/cache-seam-probes.test.ts index 8db910861b..446fe23c43 100644 --- a/tests/cache-seam-probes.test.ts +++ b/tests/cache-seam-probes.test.ts @@ -55,6 +55,7 @@ function listen(srv: http.Server): Promise { } async function closeServer(srv: http.Server): Promise { srv.close(); + srv.closeIdleConnections?.(); await Promise.race([once(srv, "close"), new Promise((r) => setTimeout(r, 2000))]); } diff --git a/tests/ccr-plugin.test.ts b/tests/ccr-plugin.test.ts index 0d6a063a1c..1b96271f30 100644 --- a/tests/ccr-plugin.test.ts +++ b/tests/ccr-plugin.test.ts @@ -247,11 +247,13 @@ test("native retrieval bridge preserves proxy compression ownership", async () = } }); -async function closeRig(rig: Rig): Promise { - rig.proxy.close(); - await once(rig.proxy, "close"); - rig.upstream.close(); - await once(rig.upstream, "close"); +async function closeRig(rig: Rig): Promise { + rig.proxy.close(); + rig.proxy.closeIdleConnections?.(); + await once(rig.proxy, "close"); + rig.upstream.close(); + rig.upstream.closeIdleConnections?.(); + await once(rig.upstream, "close"); } test("native retrieval exports preserve each session's original when refs collide", async () => { diff --git a/tests/claude-bridge-e2e.test.ts b/tests/claude-bridge-e2e.test.ts index 1f49fbc24c..e951237563 100644 --- a/tests/claude-bridge-e2e.test.ts +++ b/tests/claude-bridge-e2e.test.ts @@ -105,8 +105,10 @@ async function startRig(): Promise { scripts, close: async () => { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); }, }; diff --git a/tests/codex-compact-e2e.test.ts b/tests/codex-compact-e2e.test.ts index 72beffd8e9..c5762929b0 100644 --- a/tests/codex-compact-e2e.test.ts +++ b/tests/codex-compact-e2e.test.ts @@ -172,8 +172,10 @@ async function withHarness(opts: { mode?: string; firstTurnTokens: number; stric await fn(h); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); delete process.env.BILI_CODEX_COMPACT; } diff --git a/tests/codex-local-compaction.test.ts b/tests/codex-local-compaction.test.ts index 6aa355eb7a..824bfc8c92 100644 --- a/tests/codex-local-compaction.test.ts +++ b/tests/codex-local-compaction.test.ts @@ -141,8 +141,10 @@ async function startHarness(): Promise { bodies, close: async () => { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); }, }; diff --git a/tests/codex-window-align.test.ts b/tests/codex-window-align.test.ts index feec056257..c451b2bd09 100644 --- a/tests/codex-window-align.test.ts +++ b/tests/codex-window-align.test.ts @@ -106,8 +106,10 @@ function effectiveLimit(session: string): number | undefined { async function closeRig(rig: Rig): Promise { rig.proxy.close(); + rig.proxy.closeIdleConnections?.(); await once(rig.proxy, "close"); rig.upstream.close(); + rig.upstream.closeIdleConnections?.(); await once(rig.upstream, "close"); } diff --git a/tests/compaction-trigger-finality.test.ts b/tests/compaction-trigger-finality.test.ts index 58bde5c71a..176d573bb3 100644 --- a/tests/compaction-trigger-finality.test.ts +++ b/tests/compaction-trigger-finality.test.ts @@ -137,8 +137,10 @@ test("e2e #280r2 (Responses): trailing compaction_trigger stays final — nudge assert.ok(bodies[bodies.length - 1].includes("Context limit reached"), "nudge still injected on a normal request"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); diff --git a/tests/configured-window-outranks-registry.test.ts b/tests/configured-window-outranks-registry.test.ts index bc4c927d57..6efbce28ad 100644 --- a/tests/configured-window-outranks-registry.test.ts +++ b/tests/configured-window-outranks-registry.test.ts @@ -93,8 +93,10 @@ function url(rig: Rig): string { async function closeRig(rig: Rig): Promise { rig.proxy.close(); + rig.proxy.closeIdleConnections?.(); await once(rig.proxy, "close"); rig.upstream.close(); + rig.upstream.closeIdleConnections?.(); await once(rig.upstream, "close"); } diff --git a/tests/context-provenance-outbound.test.ts b/tests/context-provenance-outbound.test.ts index 07bde7850c..8aabeeaecd 100644 --- a/tests/context-provenance-outbound.test.ts +++ b/tests/context-provenance-outbound.test.ts @@ -78,7 +78,7 @@ async function harness(wire: Wire) { assert.equal(r.status, 200); return await r.json() as Status; }; - return { send, status, forwarded, setUsage: (value: boolean) => { usage = value; }, setFail: () => { fail = true; }, close: async () => { store.cancelAll(); proxy.close(); upstream.close(); await Promise.all([once(proxy, "close"), once(upstream, "close")]); } }; + return { send, status, forwarded, setUsage: (value: boolean) => { usage = value; }, setFail: () => { fail = true; }, close: async () => { store.cancelAll(); proxy.close(); proxy.closeIdleConnections?.(); upstream.close(); upstream.closeIdleConnections?.(); await Promise.all([once(proxy, "close"), once(upstream, "close")]); } }; } for (const wire of ["anthropic", "openai", "responses", "google"] as const) { diff --git a/tests/dsh-fork-adopt.test.ts b/tests/dsh-fork-adopt.test.ts index ad0eed8d39..5bc78d09fe 100644 --- a/tests/dsh-fork-adopt.test.ts +++ b/tests/dsh-fork-adopt.test.ts @@ -365,7 +365,7 @@ async function fullChainHarness() { await once(proxy, "listening"); const paddr = proxy.address(); assert(paddr && typeof paddr === "object"); - return { store, upstreamUrl, origin: `http://127.0.0.1:${paddr.port}`, close: async () => { store.cancelAll(); proxy.close(); upstream.close(); await Promise.all([once(proxy, "close"), once(upstream, "close")]); } }; + return { store, upstreamUrl, origin: `http://127.0.0.1:${paddr.port}`, close: async () => { store.cancelAll(); proxy.close(); proxy.closeIdleConnections?.(); upstream.close(); upstream.closeIdleConnections?.(); await Promise.all([once(proxy, "close"), once(upstream, "close")]); } }; } test("full chain: dsh fork child adopts the parent state and its replay is accepted (#2399)", async () => { diff --git a/tests/dsh-persona-continuity.test.ts b/tests/dsh-persona-continuity.test.ts index 41fe57f1da..3cf242d797 100644 --- a/tests/dsh-persona-continuity.test.ts +++ b/tests/dsh-persona-continuity.test.ts @@ -221,8 +221,10 @@ async function startRig(): Promise { async function closeRig(rig: Rig): Promise { rig.proxy.close(); + rig.proxy.closeIdleConnections?.(); await once(rig.proxy, "close"); rig.upstream.close(); + rig.upstream.closeIdleConnections?.(); await once(rig.upstream, "close"); } diff --git a/tests/dsh-persona-fingerprint.test.ts b/tests/dsh-persona-fingerprint.test.ts index a49323256c..57eb6875bc 100644 --- a/tests/dsh-persona-fingerprint.test.ts +++ b/tests/dsh-persona-fingerprint.test.ts @@ -129,8 +129,10 @@ async function startRig(upstreamHandler: UpstreamHandler = chatCompletionUpstrea async function closeRig(rig: Rig): Promise { rig.proxy.close(); + rig.proxy.closeIdleConnections?.(); await once(rig.proxy, "close"); rig.upstream.close(); + rig.upstream.closeIdleConnections?.(); await once(rig.upstream, "close"); } diff --git a/tests/durable-tool-identity.test.ts b/tests/durable-tool-identity.test.ts index 2db384e347..2add4d9d6f 100644 --- a/tests/durable-tool-identity.test.ts +++ b/tests/durable-tool-identity.test.ts @@ -149,8 +149,10 @@ async function startRig(compress?: CompressSettings): Promise { async function closeRig(rig: Rig): Promise { rig.proxy.close(); + rig.proxy.closeIdleConnections?.(); await once(rig.proxy, "close"); rig.upstream.close(); + rig.upstream.closeIdleConnections?.(); await once(rig.upstream, "close"); } diff --git a/tests/e2e-anthropic.test.ts b/tests/e2e-anthropic.test.ts index f31e65db44..f5b98bde51 100644 --- a/tests/e2e-anthropic.test.ts +++ b/tests/e2e-anthropic.test.ts @@ -205,8 +205,10 @@ async function startHarness(scripts: string[][]): Promise { captured, close: async () => { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); }, }; diff --git a/tests/e2e-overflow-selfheal.test.ts b/tests/e2e-overflow-selfheal.test.ts index 363269daee..08170ef714 100644 --- a/tests/e2e-overflow-selfheal.test.ts +++ b/tests/e2e-overflow-selfheal.test.ts @@ -185,8 +185,10 @@ test("e2e #987/#1195 T1: a stated-window overflow arms the one-shot shrink, lear assert.equal(s2?.metadata.confirmedContextLimits, undefined, "still nothing learned after recovery"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -256,8 +258,10 @@ test("e2e #987 T2: an overflow WITHOUT a window number arms at the declared wind assert.equal(summaryCalls, 0, "no fold"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -333,8 +337,10 @@ test("e2e #987 T3: with a CORRECT declared window, an oversized turn still recov assert.ok(lastForward.includes(SUMMARY_TEXT), "the forwarded body carries the fold summary"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); diff --git a/tests/e2e-relay-5xx-selfheal.test.ts b/tests/e2e-relay-5xx-selfheal.test.ts index 03615dd8e5..5298ac779b 100644 --- a/tests/e2e-relay-5xx-selfheal.test.ts +++ b/tests/e2e-relay-5xx-selfheal.test.ts @@ -247,8 +247,10 @@ test("e2e #604: relay 5xx on near-window payload → arm → next retry truncate assert.equal(s2?.stats.lastInputTokens, 5000, "real usage report overwrote the armed value"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); relay.server.close(); + relay.server.closeIdleConnections?.(); await once(relay.server, "close"); } }); @@ -302,8 +304,10 @@ test("e2e #604: network-level failure arms the emergency shrink too", async () = assert.equal(s2?.stats.lastInputTokens, 5000, "real usage report overwrote the armed value"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); relay.server.close(); + relay.server.closeIdleConnections?.(); await once(relay.server, "close"); } }); @@ -333,8 +337,10 @@ test("e2e #604: 4xx (auth) must NOT arm — no distortion of the usage signal", assert.equal(s!.stats.lastInputTokens, 0, "4xx must not raise lastInputTokens (no usage signal distortion)"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); relay.server.close(); + relay.server.closeIdleConnections?.(); await once(relay.server, "close"); } }); diff --git a/tests/e2e-responses-mid-developer.test.ts b/tests/e2e-responses-mid-developer.test.ts index 400c79b1b1..16bec84dab 100644 --- a/tests/e2e-responses-mid-developer.test.ts +++ b/tests/e2e-responses-mid-developer.test.ts @@ -201,8 +201,10 @@ async function withHarness(handler: (raw: string, bodies: string[]) => string, f await fn(h); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } } diff --git a/tests/e2e-session-identity.test.ts b/tests/e2e-session-identity.test.ts index 992668e11d..289709ff7d 100644 --- a/tests/e2e-session-identity.test.ts +++ b/tests/e2e-session-identity.test.ts @@ -160,6 +160,7 @@ async function startHarness(upstreamCount = 1): Promise { upstreams, close: async () => { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); await Promise.all(upstreams.map((u) => u.close())); }, diff --git a/tests/e2e-tag-echo.test.ts b/tests/e2e-tag-echo.test.ts index bbf4010749..33f536a8b3 100644 --- a/tests/e2e-tag-echo.test.ts +++ b/tests/e2e-tag-echo.test.ts @@ -82,8 +82,10 @@ function startHarness(scripts: string[][]): Promise { captured, close: async () => { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); }, }; diff --git a/tests/e2e-trae-model-restamp.test.ts b/tests/e2e-trae-model-restamp.test.ts index ffa3b134dd..527170f368 100644 --- a/tests/e2e-trae-model-restamp.test.ts +++ b/tests/e2e-trae-model-restamp.test.ts @@ -240,7 +240,9 @@ test("proxy e2e: model-switch history re-stamp re-attaches the anonymous session } finally { setLogCapture(null); proxy.close(); + proxy.closeIdleConnections?.(); relay.close(); + relay.closeIdleConnections?.(); await Promise.allSettled([once(proxy, "close"), once(relay, "close")]); } }); diff --git a/tests/e2e/e2e-image-billing.test.ts b/tests/e2e/e2e-image-billing.test.ts index 6dd9646aab..e0450a773e 100644 --- a/tests/e2e/e2e-image-billing.test.ts +++ b/tests/e2e/e2e-image-billing.test.ts @@ -408,8 +408,10 @@ test("e2e real payload: bytes route 743x-poisoned, learned cost rescues, baselin assert.notEqual(baseline, WINDOW - 2_000, "stale stamped baseline replaced"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -443,8 +445,10 @@ test("e2e default route: auto->pixels de-poisoned, malformed image rides along, assert.equal(entry?.fp, "pixels:0", "default route learns under the pixels fingerprint"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); diff --git a/tests/external-summary-badge.test.ts b/tests/external-summary-badge.test.ts index 58974b49bd..66f0181334 100644 --- a/tests/external-summary-badge.test.ts +++ b/tests/external-summary-badge.test.ts @@ -134,8 +134,10 @@ async function startHarness(): Promise { upstreamPort, close: async () => { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); }, }; diff --git a/tests/fake-completion.test.ts b/tests/fake-completion.test.ts index c526b2e8d1..4122ef4515 100644 --- a/tests/fake-completion.test.ts +++ b/tests/fake-completion.test.ts @@ -220,8 +220,10 @@ function startHarness(scripts: string[][], extra?: Partial): Promi captured, close: async () => { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); }, }; @@ -435,8 +437,10 @@ test("e2e #1900: role learned mid-request (400 → hop) — hinted retry carries assert.ok(!raw.includes("/fake/completion/marker"), "fake-completion text must not leak to the client"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); diff --git a/tests/fallback-window-floor.test.ts b/tests/fallback-window-floor.test.ts index b3dc874fb7..769d7f1624 100644 --- a/tests/fallback-window-floor.test.ts +++ b/tests/fallback-window-floor.test.ts @@ -124,8 +124,10 @@ test("e2e: fallback-derived window is floored at 100k after output-headroom rese assert.equal(received[1].length, 30, "turn 2 appends no nudge at 50% of the floored 100k window (would be 31 at 78% of the unfloored 64k)"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -216,8 +218,10 @@ test("e2e: per-route context declaration is operator-owned and never floored", a assert.equal(received[1].length, 31, "operator-declared window is not floored: nudge appended at 78% of 64k"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); diff --git a/tests/first-sight-drain-wire.test.ts b/tests/first-sight-drain-wire.test.ts index 083ec7c236..8f935274ad 100644 --- a/tests/first-sight-drain-wire.test.ts +++ b/tests/first-sight-drain-wire.test.ts @@ -149,8 +149,10 @@ const NUDGE_HINT = "ONE call, ONE string"; // rides every rendered nudge (ONE_CA async function closeRig(rig: Rig): Promise { rig.proxy.close(); + rig.proxy.closeIdleConnections?.(); await once(rig.proxy, "close"); rig.upstream.close(); + rig.upstream.closeIdleConnections?.(); await once(rig.upstream, "close"); } diff --git a/tests/fix-1001-history-rewrite.test.ts b/tests/fix-1001-history-rewrite.test.ts index f0ec555e9c..1213a40c30 100644 --- a/tests/fix-1001-history-rewrite.test.ts +++ b/tests/fix-1001-history-rewrite.test.ts @@ -235,8 +235,10 @@ test("#1001 e2e openai-wire: silent client history rewrite → boundary marked, assert.equal(new Set(refVals3).size, refVals3.length, "still no duplicate refs after the prune"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -358,8 +360,10 @@ test("#1001/#2598 e2e google-wire: silent client history rewrite → boundary ma assert.equal(new Set(refVals3).size, refVals3.length, "still no duplicate refs after the prune"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); diff --git a/tests/fix-1075-side-request.test.ts b/tests/fix-1075-side-request.test.ts index 4d7ea1c276..4bbe18ee14 100644 --- a/tests/fix-1075-side-request.test.ts +++ b/tests/fix-1075-side-request.test.ts @@ -211,8 +211,10 @@ test("#1075 e2e openai-wire: 1-message side request neither wipes ref maps nor i assert.ok(fwd3.raw.includes("MORE_99_payload"), "new tail survives in the payload"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); diff --git a/tests/fix-1117-passthrough.test.ts b/tests/fix-1117-passthrough.test.ts index f14437c474..dced45a09d 100644 --- a/tests/fix-1117-passthrough.test.ts +++ b/tests/fix-1117-passthrough.test.ts @@ -77,8 +77,10 @@ async function startHarness(injectTool: boolean): Promise<{ proxyPort: number; u captured, async close() { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); }, }; diff --git a/tests/fix-1897-leaked-tools-side.test.ts b/tests/fix-1897-leaked-tools-side.test.ts index 89703a9b1c..4c0afbcbd5 100644 --- a/tests/fix-1897-leaked-tools-side.test.ts +++ b/tests/fix-1897-leaked-tools-side.test.ts @@ -164,8 +164,10 @@ async function startRig(): Promise { async function closeRig(rig: Rig): Promise { rig.proxy.close(); + rig.proxy.closeIdleConnections?.(); await once(rig.proxy, "close"); rig.upstream.close(); + rig.upstream.closeIdleConnections?.(); await once(rig.upstream, "close"); } diff --git a/tests/fix-488-multimodal.test.ts b/tests/fix-488-multimodal.test.ts index b7008fea4e..4f694be45e 100644 --- a/tests/fix-488-multimodal.test.ts +++ b/tests/fix-488-multimodal.test.ts @@ -313,6 +313,7 @@ test("e2e #488-A2 (Responses): image tokens count toward the output-budget clamp async function closeAll(...servers: http.Server[]): Promise { for (const s of servers) { s.close(); + s.closeIdleConnections?.(); await once(s, "close"); } } diff --git a/tests/fix-781-summary-images.test.ts b/tests/fix-781-summary-images.test.ts index 7ada8caaea..41c7deb9ce 100644 --- a/tests/fix-781-summary-images.test.ts +++ b/tests/fix-781-summary-images.test.ts @@ -209,6 +209,7 @@ async function startProxy(upstreamPort: number, model: string, path: string): Pr async function closeAll(...servers: http.Server[]): Promise { for (const s of servers) { s.close(); + s.closeIdleConnections?.(); await once(s, "close"); } } diff --git a/tests/fix-920-bypass-drop.test.ts b/tests/fix-920-bypass-drop.test.ts index 8bd06a74cf..9a9605b1d1 100644 --- a/tests/fix-920-bypass-drop.test.ts +++ b/tests/fix-920-bypass-drop.test.ts @@ -73,8 +73,10 @@ async function startHarness(injectTool: boolean): Promise<{ proxyPort: number; u captured, close: async () => { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); }, }; diff --git a/tests/fold-round2-shape.test.ts b/tests/fold-round2-shape.test.ts index 7a7693e192..0a8bd58e48 100644 --- a/tests/fold-round2-shape.test.ts +++ b/tests/fold-round2-shape.test.ts @@ -127,7 +127,7 @@ test("#1592 chat fold round-2 renders the next turn's shape (no run separators, hist.push({ role: "tool", tool_call_id: `call_t${t}`, content: `total 8\n` + FILLER(200 + t, 9) }); } } finally { - server.close(); upstream.close(); + server.close(); server.closeIdleConnections?.(); upstream.close(); upstream.closeIdleConnections?.(); await Promise.allSettled([once(server, "close"), once(upstream, "close")]); } diff --git a/tests/fork-nudge-deadzone.test.ts b/tests/fork-nudge-deadzone.test.ts index 2f202f6f74..6cb9e7018f 100644 --- a/tests/fork-nudge-deadzone.test.ts +++ b/tests/fork-nudge-deadzone.test.ts @@ -120,7 +120,7 @@ async function harness() { const prefix = ordered.slice(0, messageCount); return request("/__bili/plugin/fork", { protocolVersion: 1, parentConversationId: parent, childConversationId: child, parentRevision: snapshot.body.parentRevision as string, branchPoint: { messageCount, orderHash: hash(prefix) }, orderedMessages: prefix, idempotencyKey: `fork-${child}` }); }; - return { request, seedParent, forkAt, dir, upstreamUrl, origin, close: async () => { store.cancelAll(); proxy.close(); upstream.close(); await Promise.all([once(proxy, "close"), once(upstream, "close")]); } }; + return { request, seedParent, forkAt, dir, upstreamUrl, origin, close: async () => { store.cancelAll(); proxy.close(); proxy.closeIdleConnections?.(); upstream.close(); upstream.closeIdleConnections?.(); await Promise.all([once(proxy, "close"), once(upstream, "close")]); } }; } test("mid-history fork seeds the nudge sizing baseline (dsh fork dead-zone repro)", async () => { diff --git a/tests/fork-replica-convergence.test.ts b/tests/fork-replica-convergence.test.ts index ecf1ad427f..7f4841745c 100644 --- a/tests/fork-replica-convergence.test.ts +++ b/tests/fork-replica-convergence.test.ts @@ -65,7 +65,7 @@ async function harness(persist: boolean) { assert.equal(r.status, 200); await r.text(); }; - return { request, seed, messages, dir, store, upstreamUrl, origin, close: async () => { store.closeQuietly(); proxy.close(); upstream.close(); await Promise.all([once(proxy, "close"), once(upstream, "close")]); } }; + return { request, seed, messages, dir, store, upstreamUrl, origin, close: async () => { store.closeQuietly(); proxy.close(); proxy.closeIdleConnections?.(); upstream.close(); upstream.closeIdleConnections?.(); await Promise.all([once(proxy, "close"), once(upstream, "close")]); } }; } test("fork receipts cut pinned fork_base checkpoints that survive session deletion (#2960 ②)", async () => { diff --git a/tests/headroom-output-fallback.test.ts b/tests/headroom-output-fallback.test.ts index 8f0074a164..84203c95b4 100644 --- a/tests/headroom-output-fallback.test.ts +++ b/tests/headroom-output-fallback.test.ts @@ -136,8 +136,10 @@ async function turn2MessageCount(s: Scenario): Promise { return (received[1] as unknown[]).length; } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } } diff --git a/tests/host-usage-postfold.test.ts b/tests/host-usage-postfold.test.ts index 88d4bbe21e..950b9dbf4c 100644 --- a/tests/host-usage-postfold.test.ts +++ b/tests/host-usage-postfold.test.ts @@ -816,8 +816,10 @@ mitm: { enabled: false, domains: [] }, await fn(h); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } } @@ -962,8 +964,10 @@ mitm: { enabled: false, domains: [] }, await fn(h); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } } diff --git a/tests/issue-393-registry-window.test.ts b/tests/issue-393-registry-window.test.ts index fb6990c10e..85bbf6dd6c 100644 --- a/tests/issue-393-registry-window.test.ts +++ b/tests/issue-393-registry-window.test.ts @@ -108,8 +108,10 @@ async function startRig(inputTokens = 500, log = false): Promise { function closeRig(rig: Rig): Promise { rig.proxy.close(); + rig.proxy.closeIdleConnections?.(); return once(rig.proxy, "close").then(() => { rig.upstream.close(); + rig.upstream.closeIdleConnections?.(); return once(rig.upstream, "close"); }) as Promise; } diff --git a/tests/issue1195-overflow-refold.test.ts b/tests/issue1195-overflow-refold.test.ts index d87dcd3ac0..6c70b5a166 100644 --- a/tests/issue1195-overflow-refold.test.ts +++ b/tests/issue1195-overflow-refold.test.ts @@ -163,8 +163,10 @@ test("e2e #1195 A: stated-window overflow is rescued within the SAME request — const proxyPort = (proxy.address() as { port: number }).port; t.after(async () => { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.server.close(); + upstream.server.closeIdleConnections?.(); await once(upstream.server, "close"); }); @@ -204,8 +206,10 @@ test("e2e #1195 B: an unfoldable payload passes the ORIGINAL overflow 400 throug const proxyPort = (proxy.address() as { port: number }).port; t.after(async () => { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.server.close(); + upstream.server.closeIdleConnections?.(); await once(upstream.server, "close"); }); @@ -243,8 +247,10 @@ test("#2777: an internal failed-compress continuation retains the accepted overf const proxyPort = (proxy.address() as { port: number }).port; t.after(async () => { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.server.close(); + upstream.server.closeIdleConnections?.(); await once(upstream.server, "close"); }); const response = await fetch(`http://127.0.0.1:${proxyPort}/bili/http://127.0.0.1:${upstream.port}/v1/messages`, { @@ -283,8 +289,10 @@ test("e2e #1195 C: when the folded retry is ALSO rejected, the client sees the R const proxyPort = (proxy.address() as { port: number }).port; t.after(async () => { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.server.close(); + upstream.server.closeIdleConnections?.(); await once(upstream.server, "close"); }); diff --git a/tests/issue1204-rules-google-plugin.test.ts b/tests/issue1204-rules-google-plugin.test.ts index 466700ac95..23d4f606c4 100644 --- a/tests/issue1204-rules-google-plugin.test.ts +++ b/tests/issue1204-rules-google-plugin.test.ts @@ -76,8 +76,10 @@ async function startHarness(routeCompress?: Record): Promise { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); }, }; diff --git a/tests/issue1307-side-snapshot.test.ts b/tests/issue1307-side-snapshot.test.ts index bdde19a7c2..0a2582c52b 100644 --- a/tests/issue1307-side-snapshot.test.ts +++ b/tests/issue1307-side-snapshot.test.ts @@ -122,8 +122,10 @@ async function startRig(): Promise { async function closeRig(rig: Rig): Promise { rig.proxy.close(); + rig.proxy.closeIdleConnections?.(); await once(rig.proxy, "close"); rig.upstream.close(); + rig.upstream.closeIdleConnections?.(); await once(rig.upstream, "close"); } diff --git a/tests/issue1320-thinking-mass.test.ts b/tests/issue1320-thinking-mass.test.ts index 1281244a67..2bf859d1a4 100644 --- a/tests/issue1320-thinking-mass.test.ts +++ b/tests/issue1320-thinking-mass.test.ts @@ -258,8 +258,10 @@ async function startHarness(): Promise { upstreamPort, close: async () => { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); }, }; diff --git a/tests/issue1321-tier-window-cap.test.ts b/tests/issue1321-tier-window-cap.test.ts index 60a2ce5bf4..48b39949a1 100644 --- a/tests/issue1321-tier-window-cap.test.ts +++ b/tests/issue1321-tier-window-cap.test.ts @@ -133,8 +133,10 @@ function hasEmergencyNudge(body: string): boolean { async function closeRig(rig: Rig): Promise { rig.proxy.close(); + rig.proxy.closeIdleConnections?.(); await once(rig.proxy, "close"); rig.upstream.close(); + rig.upstream.closeIdleConnections?.(); await once(rig.upstream, "close"); } diff --git a/tests/issue1492-stale-estimate-view.test.ts b/tests/issue1492-stale-estimate-view.test.ts index f6fa17056b..b7bfbccb97 100644 --- a/tests/issue1492-stale-estimate-view.test.ts +++ b/tests/issue1492-stale-estimate-view.test.ts @@ -192,8 +192,10 @@ async function runCase(sessionId: string, poisonSource: "usage" | "estimate", co } finally { setLogCapture(null); proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); relay.server.close(); + relay.server.closeIdleConnections?.(); await once(relay.server, "close"); } } diff --git a/tests/issue1493-arm-outbound-payload.test.ts b/tests/issue1493-arm-outbound-payload.test.ts index 3114c4a8b0..e7729f675a 100644 --- a/tests/issue1493-arm-outbound-payload.test.ts +++ b/tests/issue1493-arm-outbound-payload.test.ts @@ -186,8 +186,10 @@ test("#1493: network-level failure arms at the outbound payload (fits) → below assert.equal(s2?.stats.lastInputTokens, 5000, "real usage report overwrote the armed value"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); relay.server.close(); + relay.server.closeIdleConnections?.(); await once(relay.server, "close"); } }); @@ -218,8 +220,10 @@ test("#1493: relay 5xx arms at the outbound payload (fits) → below the emergen assert.equal(s2?.stats.lastInputTokens, 5000, "real usage report overwrote the armed value"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); relay.server.close(); + relay.server.closeIdleConnections?.(); await once(relay.server, "close"); } }); @@ -265,8 +269,10 @@ test("#1498-F2: transform-failure fallback arms at the RAW view, not wire overhe ); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); relay.server.close(); + relay.server.closeIdleConnections?.(); await once(relay.server, "close"); } }); diff --git a/tests/issue1569-window-stamp-and-anchor.test.ts b/tests/issue1569-window-stamp-and-anchor.test.ts index 2f1ab6e0da..8560c8cad5 100644 --- a/tests/issue1569-window-stamp-and-anchor.test.ts +++ b/tests/issue1569-window-stamp-and-anchor.test.ts @@ -453,8 +453,10 @@ async function runAnchorCase(sessionId: string, reportUsage: boolean): Promise<{ } finally { setLogCapture(null); proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); relay.server.close(); + relay.server.closeIdleConnections?.(); await once(relay.server, "close"); } } diff --git a/tests/issue1595-nudge-reanchor.test.ts b/tests/issue1595-nudge-reanchor.test.ts index e30d9bef8b..6118570086 100644 --- a/tests/issue1595-nudge-reanchor.test.ts +++ b/tests/issue1595-nudge-reanchor.test.ts @@ -263,8 +263,10 @@ async function withProxy(sessionId: string, streamBody: string, jsonBody: string } finally { setLogCapture(null); proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); relay.server.close(); + relay.server.closeIdleConnections?.(); await once(relay.server, "close"); } } diff --git a/tests/issue1819-regurgitation-guard.test.ts b/tests/issue1819-regurgitation-guard.test.ts index 0a2f8d9ba0..2aa5aea9f1 100644 --- a/tests/issue1819-regurgitation-guard.test.ts +++ b/tests/issue1819-regurgitation-guard.test.ts @@ -46,7 +46,7 @@ function startSummaryServer(replyText: string): Promise { return new Promise((resolve) => { server.once("listening", () => { const { port } = server.address() as { port: number }; - resolve({ port, bodies, close: async () => { server.close(); await once(server, "close"); } }); + resolve({ port, bodies, close: async () => { server.close(); server.closeIdleConnections?.(); await once(server, "close"); } }); }); }); } diff --git a/tests/issue1820-post-rebuild-anchor.test.ts b/tests/issue1820-post-rebuild-anchor.test.ts index 728d4aa6ab..cbf5577979 100644 --- a/tests/issue1820-post-rebuild-anchor.test.ts +++ b/tests/issue1820-post-rebuild-anchor.test.ts @@ -148,8 +148,10 @@ async function startHarness(sessionId: string, reportUsage: boolean): Promise<{ cleanup: async () => { setLogCapture(null); proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); relay.server.close(); + relay.server.closeIdleConnections?.(); await once(relay.server, "close"); }, }; diff --git a/tests/issue1841-preflight-futility.test.ts b/tests/issue1841-preflight-futility.test.ts index 605517530b..f0207c9e9b 100644 --- a/tests/issue1841-preflight-futility.test.ts +++ b/tests/issue1841-preflight-futility.test.ts @@ -122,8 +122,10 @@ async function boot(): Promise<{ proxyPort: number; upstreamPort: number; cleanu upstreamPort, cleanup: async () => { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); }, }; diff --git a/tests/issue1843-learned-image-cost.test.ts b/tests/issue1843-learned-image-cost.test.ts index aa6ed84f61..95e1b6251b 100644 --- a/tests/issue1843-learned-image-cost.test.ts +++ b/tests/issue1843-learned-image-cost.test.ts @@ -234,8 +234,10 @@ test("e2e #1843 L1: learned image cost rescues a session the bytes prior bricks" assert.equal(stats.summaryCalls, 0, "no folding was needed — text fit all along"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); diff --git a/tests/issue1933-preflight-calibration.test.ts b/tests/issue1933-preflight-calibration.test.ts index 79a904b8ae..52ac0be04e 100644 --- a/tests/issue1933-preflight-calibration.test.ts +++ b/tests/issue1933-preflight-calibration.test.ts @@ -325,8 +325,10 @@ test("e2e F1: a relay billing below the local estimator teaches k̂<1 — the ca assert.equal(calls.filter((c) => c.stream).length, 3, "all three turns were forwarded as-is"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -376,10 +378,13 @@ test("e2e F2: a route switch demotes the stale usage-baseline — the small post assert.equal(a.calls.filter((c) => c.summary).length, 0, "no preflight summarization on the original route either"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); a.server.close(); + a.server.closeIdleConnections?.(); await once(a.server, "close"); b.server.close(); + b.server.closeIdleConnections?.(); await once(b.server, "close"); } }); diff --git a/tests/issue1987-preflight-baseline-anchor.test.ts b/tests/issue1987-preflight-baseline-anchor.test.ts index 0e4a4a7f66..e031e405ef 100644 --- a/tests/issue1987-preflight-baseline-anchor.test.ts +++ b/tests/issue1987-preflight-baseline-anchor.test.ts @@ -147,8 +147,10 @@ test("e2e #1987: post-fold usage baseline anchors to the shipped payload, not th assert.equal(s.stats.lastInputTokensSource, "estimate", "no usage report lands on the converged turn, so the estimate of the shipped payload wins"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); diff --git a/tests/issue1993-preflight-400.test.ts b/tests/issue1993-preflight-400.test.ts index fbe4edb4ef..a86b4b2a15 100644 --- a/tests/issue1993-preflight-400.test.ts +++ b/tests/issue1993-preflight-400.test.ts @@ -151,7 +151,7 @@ async function driveResponses(proxyPort: number, upstreamPort: number, session: } async function closeAll(...servers: http.Server[]): Promise { - servers.forEach((s) => s.close()); + servers.forEach((s) => { s.close(); s.closeIdleConnections?.(); }); await new Promise((resolve, reject) => { void Promise.allSettled(servers.map((s) => once(s, "close"))).then(() => resolve(), reject); }); diff --git a/tests/issue2096-clamp-headroom-window.test.ts b/tests/issue2096-clamp-headroom-window.test.ts index fe68307ce1..45d497b8ca 100644 --- a/tests/issue2096-clamp-headroom-window.test.ts +++ b/tests/issue2096-clamp-headroom-window.test.ts @@ -147,7 +147,9 @@ test("#2096 e2e: [window] reports the base, [headroom] reports the enforced effe } finally { setLogCapture(null); h.proxy.close(); + h.proxy.closeIdleConnections?.(); h.upstream.close(); + h.upstream.closeIdleConnections?.(); await Promise.allSettled([once(h.proxy, "close"), once(h.upstream, "close")]); } }); diff --git a/tests/issue2117-context-estimate-provenance.test.ts b/tests/issue2117-context-estimate-provenance.test.ts index 65bc3180b2..67f65a5e94 100644 --- a/tests/issue2117-context-estimate-provenance.test.ts +++ b/tests/issue2117-context-estimate-provenance.test.ts @@ -356,8 +356,10 @@ test("e2e: forward() publishes both calibers; usage wins the display after settl assert.ok(s!.stats.contextEstimateTokens! < (s!.stats.localInputEstimate ?? 0) / 2, `calibrated estimate (${s!.stats.contextEstimateTokens}) must be far below the bound (${s!.stats.localInputEstimate})`); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); diff --git a/tests/issue2129-restart-measurement-state.test.ts b/tests/issue2129-restart-measurement-state.test.ts index b065aa1117..b147fbedaa 100644 --- a/tests/issue2129-restart-measurement-state.test.ts +++ b/tests/issue2129-restart-measurement-state.test.ts @@ -348,8 +348,10 @@ test("e2e: restart restores k̂ + usage anchor — the over-raw resend forwards assert.equal(calls.filter((c) => c.stream).length, 4, "all four requests were forwarded as-is"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); store.cancelAll(); store2?.cancelAll(); diff --git a/tests/issue2155-self-heal.test.ts b/tests/issue2155-self-heal.test.ts index f0e4a59d45..b1e4bb3a9a 100644 --- a/tests/issue2155-self-heal.test.ts +++ b/tests/issue2155-self-heal.test.ts @@ -282,8 +282,10 @@ test("integration: zombie plugin session degrades to proxy tool injection, then assert.equal(healed!.metadata.selfHeal, undefined, "self-heal cleared on recovery"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -313,8 +315,10 @@ test("integration: nudge-idle loop (non-plugin) suppresses the nudge after the w assert.ok(suppressed === before - 1, "nudge message gone once suppression armed (back to the un-nudged count)"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -435,8 +439,10 @@ test("integration: a 524 on the non-streaming summary flips the session to strea assert.ok(lastForward.includes(SUMMARY_TEXT), "the fold summary made it into the rescued body"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -467,6 +473,7 @@ test("unit: warnActivePluginSessions reports recent live sessions and stays sile if (prev === undefined) delete process.env.XDG_STATE_HOME; else process.env.XDG_STATE_HOME = prev; upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); fs.rmSync(dir, { recursive: true, force: true }); } diff --git a/tests/issue2189-preflight-billing-block.test.ts b/tests/issue2189-preflight-billing-block.test.ts index fc0f3e1173..3ee8f1f0e8 100644 --- a/tests/issue2189-preflight-billing-block.test.ts +++ b/tests/issue2189-preflight-billing-block.test.ts @@ -219,8 +219,10 @@ test("#2189 anthropic summary carries the client billing-attribution block at sy assert.ok(lastForward?.body.includes(BILLING_TEXT), "the MAIN forward still carries the client attribution block (main lane untouched)"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -251,8 +253,10 @@ test("#2189 legacy string system keeps the byte-identical summary shape", async } } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -293,8 +297,10 @@ test("#2189 bare-Error 429 fails fast after ONE attempt, retryable=false, arms t } finally { setLogCapture(null); proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -325,8 +331,10 @@ test("#2189 a genuine rate limit keeps the legacy 3-attempt replay and retryable } finally { setLogCapture(null); proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); diff --git a/tests/issue2218-relay-affinity-signal.test.ts b/tests/issue2218-relay-affinity-signal.test.ts index 3acd707aef..8cb909a440 100644 --- a/tests/issue2218-relay-affinity-signal.test.ts +++ b/tests/issue2218-relay-affinity-signal.test.ts @@ -82,8 +82,10 @@ async function startHarness(routes: ProxyOptions["routes"] | undefined): Promise captured, close: async () => { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); }, }; diff --git a/tests/issue2313-probe-forward.test.ts b/tests/issue2313-probe-forward.test.ts index fd68c105e7..3cdc538dd9 100644 --- a/tests/issue2313-probe-forward.test.ts +++ b/tests/issue2313-probe-forward.test.ts @@ -145,7 +145,9 @@ async function setup(firstRejectBody?: string): Promise<{ ctx: Ctx; calls: Call[ calls, close: async () => { proxy.close(); + proxy.closeIdleConnections?.(); upstream.close(); + upstream.closeIdleConnections?.(); await Promise.allSettled([once(proxy, "close"), once(upstream, "close")]); }, }; diff --git a/tests/issue2317-route-miss-diagnostics.test.ts b/tests/issue2317-route-miss-diagnostics.test.ts index 36f29bd81c..b4342086dd 100644 --- a/tests/issue2317-route-miss-diagnostics.test.ts +++ b/tests/issue2317-route-miss-diagnostics.test.ts @@ -229,8 +229,11 @@ test("#2317 e2e: a route-miss is loud in the log and a route-hit shows the match } finally { setLogCapture(null); h.proxy.close(); + h.proxy.closeIdleConnections?.(); h.upA.close(); + h.upA.closeIdleConnections?.(); h.upB.close(); + h.upB.closeIdleConnections?.(); await Promise.allSettled([once(h.proxy, "close"), once(h.upA, "close"), once(h.upB, "close")]); } }); diff --git a/tests/issue2347-dump-sse-plugin-lane.test.ts b/tests/issue2347-dump-sse-plugin-lane.test.ts index 20cd2ab36f..cc38ac15fe 100644 --- a/tests/issue2347-dump-sse-plugin-lane.test.ts +++ b/tests/issue2347-dump-sse-plugin-lane.test.ts @@ -66,7 +66,7 @@ async function harness(opts: { dumpDir?: string; injectTool: boolean }): Promise close: async () => { store.cancelAll(); const closed = Promise.all([once(proxy, "close"), once(upstream, "close")]); - proxy.close(); upstream.close(); + proxy.close(); proxy.closeIdleConnections?.(); upstream.close(); upstream.closeIdleConnections?.(); await closed; }, }; diff --git a/tests/issue2407-google-khat-lane.test.ts b/tests/issue2407-google-khat-lane.test.ts index a2fae98695..a917d4fe6f 100644 --- a/tests/issue2407-google-khat-lane.test.ts +++ b/tests/issue2407-google-khat-lane.test.ts @@ -37,6 +37,7 @@ type Item = Record; async function closeServer(srv?: http.Server): Promise { if (!srv) return; srv.close(); + srv.closeIdleConnections?.(); await once(srv, "close").catch(() => {}); } diff --git a/tests/issue2419-dsh-skill-catalog.test.ts b/tests/issue2419-dsh-skill-catalog.test.ts index b06a704757..601e06eaf8 100644 --- a/tests/issue2419-dsh-skill-catalog.test.ts +++ b/tests/issue2419-dsh-skill-catalog.test.ts @@ -97,8 +97,10 @@ async function startRig(): Promise { async function closeRig(rig: Rig): Promise { rig.proxy.close(); + rig.proxy.closeIdleConnections?.(); await once(rig.proxy, "close"); rig.upstream.close(); + rig.upstream.closeIdleConnections?.(); await once(rig.upstream, "close"); } diff --git a/tests/issue2432-dsh-local-compaction.test.ts b/tests/issue2432-dsh-local-compaction.test.ts index 13c5029a94..5d8836fd78 100644 --- a/tests/issue2432-dsh-local-compaction.test.ts +++ b/tests/issue2432-dsh-local-compaction.test.ts @@ -104,8 +104,10 @@ async function startRig(compress: { injectTool: boolean; injectNudge?: boolean } bodies, close: async () => { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); }, }; diff --git a/tests/issue2446-dsh-mcp-catalog.test.ts b/tests/issue2446-dsh-mcp-catalog.test.ts index 0bacaa3760..3252ecee51 100644 --- a/tests/issue2446-dsh-mcp-catalog.test.ts +++ b/tests/issue2446-dsh-mcp-catalog.test.ts @@ -113,8 +113,10 @@ async function startRig(): Promise { async function closeRig(rig: Rig): Promise { rig.proxy.close(); + rig.proxy.closeIdleConnections?.(); await once(rig.proxy, "close"); rig.upstream.close(); + rig.upstream.closeIdleConnections?.(); await once(rig.upstream, "close"); } diff --git a/tests/issue2447-dsh-workspace-instructions.test.ts b/tests/issue2447-dsh-workspace-instructions.test.ts index efcc62f2e7..b9221c50bd 100644 --- a/tests/issue2447-dsh-workspace-instructions.test.ts +++ b/tests/issue2447-dsh-workspace-instructions.test.ts @@ -103,8 +103,10 @@ async function startRig(): Promise { async function closeRig(rig: Rig): Promise { rig.proxy.close(); + rig.proxy.closeIdleConnections?.(); await once(rig.proxy, "close"); rig.upstream.close(); + rig.upstream.closeIdleConnections?.(); await once(rig.upstream, "close"); } diff --git a/tests/issue2451-dsh-responses-compaction.test.ts b/tests/issue2451-dsh-responses-compaction.test.ts index 8e98202f35..684a44adba 100644 --- a/tests/issue2451-dsh-responses-compaction.test.ts +++ b/tests/issue2451-dsh-responses-compaction.test.ts @@ -143,8 +143,10 @@ async function startHarness(modelFold = false): Promise { bodies, close: async () => { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); }, }; diff --git a/tests/issue2481-dsh-runtime-context.test.ts b/tests/issue2481-dsh-runtime-context.test.ts index baa64b27db..2710056884 100644 --- a/tests/issue2481-dsh-runtime-context.test.ts +++ b/tests/issue2481-dsh-runtime-context.test.ts @@ -110,8 +110,10 @@ async function startRig(): Promise { async function closeRig(rig: Rig): Promise { rig.proxy.close(); + rig.proxy.closeIdleConnections?.(); await once(rig.proxy, "close"); rig.upstream.close(); + rig.upstream.closeIdleConnections?.(); await once(rig.upstream, "close"); } diff --git a/tests/issue2490-ledger-floor-doomed-probe.test.ts b/tests/issue2490-ledger-floor-doomed-probe.test.ts index c563887f0d..d507ede57d 100644 --- a/tests/issue2490-ledger-floor-doomed-probe.test.ts +++ b/tests/issue2490-ledger-floor-doomed-probe.test.ts @@ -136,7 +136,9 @@ async function setup(): Promise<{ ctx: Ctx; calls: Call[]; close: () => Promise< calls, close: async () => { proxy.close(); + proxy.closeIdleConnections?.(); upstream.close(); + upstream.closeIdleConnections?.(); await Promise.allSettled([once(proxy, "close"), once(upstream, "close")]); }, }; diff --git a/tests/issue2499-anthropic-round2-cache.test.ts b/tests/issue2499-anthropic-round2-cache.test.ts index 3c4c61c29c..8d6fda6d65 100644 --- a/tests/issue2499-anthropic-round2-cache.test.ts +++ b/tests/issue2499-anthropic-round2-cache.test.ts @@ -136,8 +136,10 @@ async function startHarness(): Promise { captured, close: async () => { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); }, }; diff --git a/tests/issue2601-persona-fork-lineage.test.ts b/tests/issue2601-persona-fork-lineage.test.ts index 86fb283d45..ccf71bd8db 100644 --- a/tests/issue2601-persona-fork-lineage.test.ts +++ b/tests/issue2601-persona-fork-lineage.test.ts @@ -307,8 +307,10 @@ async function startRig(): Promise { async function stopRig(rig: Rig): Promise { rig.proxy.close(); + rig.proxy.closeIdleConnections?.(); await once(rig.proxy, "close"); rig.relay.close(); + rig.relay.closeIdleConnections?.(); await once(rig.relay, "close"); } diff --git a/tests/issue2658-dsh-anthropic-google-compaction.test.ts b/tests/issue2658-dsh-anthropic-google-compaction.test.ts index da0d3ff61b..4ec8dc77fe 100644 --- a/tests/issue2658-dsh-anthropic-google-compaction.test.ts +++ b/tests/issue2658-dsh-anthropic-google-compaction.test.ts @@ -124,8 +124,10 @@ async function startAnthropicRig(): Promise { bodies, close: async () => { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); }, }; @@ -159,8 +161,10 @@ async function startGoogleRig(): Promise { bodies, close: async () => { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); }, }; diff --git a/tests/issue2672-preflight-blocked-split.test.ts b/tests/issue2672-preflight-blocked-split.test.ts index 363daea74d..3968530918 100644 --- a/tests/issue2672-preflight-blocked-split.test.ts +++ b/tests/issue2672-preflight-blocked-split.test.ts @@ -275,7 +275,9 @@ test("#2672 halving midpoint on a protected message: halves snap past the BLOCKE assert.equal(sess?.metadata?.preflightDeadEnd, undefined, "successful preflight must not leave a dead-end marker"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); upstream.close(); + upstream.closeIdleConnections?.(); await Promise.all([once(proxy, "close"), once(upstream, "close")]); } }); diff --git a/tests/issue2678-preflight-batch-fold.test.ts b/tests/issue2678-preflight-batch-fold.test.ts index e55e544e6b..3b64722871 100644 --- a/tests/issue2678-preflight-batch-fold.test.ts +++ b/tests/issue2678-preflight-batch-fold.test.ts @@ -158,10 +158,13 @@ test("#2678: several preflight ranges fold in ONE external-summary batch that ru assert.ok(activeBlocks.length >= 2, `the batch must apply several ranges before re-judging (got ${activeBlocks.length} block(s))`); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); main.server.close(); + main.server.closeIdleConnections?.(); await once(main.server, "close"); sum.server.close(); + sum.server.closeIdleConnections?.(); await once(sum.server, "close"); } }); @@ -192,10 +195,13 @@ test("#2678: a batch-failed range is retried across later rounds instead of drop assert.ok(failedAttempts >= 2, `the failed range must be retried beyond its batch attempt (got ${failedAttempts} attempt(s))`); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); main.server.close(); + main.server.closeIdleConnections?.(); await once(main.server, "close"); sum.server.close(); + sum.server.closeIdleConnections?.(); await once(sum.server, "close"); } }); @@ -246,10 +252,13 @@ test("#2678: nomination picks the oldest chunk of a multi-chunk range without po assert.ok(activeBlocks.length >= 5, `the multi-chunk range must keep folding chunk by chunk (got ${activeBlocks.length} block(s))`); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); main.server.close(); + main.server.closeIdleConnections?.(); await once(main.server, "close"); sum.server.close(); + sum.server.closeIdleConnections?.(); await once(sum.server, "close"); } }); @@ -277,10 +286,13 @@ test("#2678: a batch-failed range is retried in later rounds while siblings keep assert.ok(failedAttempts >= 3, `the failed range must be retried across multiple rounds (got ${failedAttempts} attempt(s))`); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); main.server.close(); + main.server.closeIdleConnections?.(); await once(main.server, "close"); sum.server.close(); + sum.server.closeIdleConnections?.(); await once(sum.server, "close"); } }); diff --git a/tests/issue2709-passthrough-compaction-guard.test.ts b/tests/issue2709-passthrough-compaction-guard.test.ts index fcdd13df20..dac86d1583 100644 --- a/tests/issue2709-passthrough-compaction-guard.test.ts +++ b/tests/issue2709-passthrough-compaction-guard.test.ts @@ -95,8 +95,10 @@ async function startHarness(allowDshCompaction = false): Promise<{ proxyPort: nu captured, async close() { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); }, }; diff --git a/tests/issue2733-preflight-codex-shape.test.ts b/tests/issue2733-preflight-codex-shape.test.ts index 889a65d8cb..6676079a2b 100644 --- a/tests/issue2733-preflight-codex-shape.test.ts +++ b/tests/issue2733-preflight-codex-shape.test.ts @@ -152,8 +152,10 @@ test("#2733: codex client → summary payload carries the real CLI wire shape; s assert.ok((sess!.state.blocks ?? []).some((b) => b.active), "the preflight fold landed on the session"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -183,8 +185,10 @@ test("#2733: non-codex client → summary payload stays the legacy minimal shape `non-codex clients must keep the legacy minimal shape (no typed items, no include), got ${JSON.stringify(summaryCalls)}`); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); diff --git a/tests/issue2832-preflight-deterministic-empty.test.ts b/tests/issue2832-preflight-deterministic-empty.test.ts index fe8ffca237..40daf6ece4 100644 --- a/tests/issue2832-preflight-deterministic-empty.test.ts +++ b/tests/issue2832-preflight-deterministic-empty.test.ts @@ -282,7 +282,9 @@ test("#2832 systemic deterministic empties: bounded strikes, sticky verdict, one assert.equal(probeStateOf("s2832-dead")?.dead, true, "a failed canary keeps the verdict armed"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); upstream.close(); + upstream.closeIdleConnections?.(); await new Promise((resolve, reject) => { void Promise.allSettled([once(proxy, "close"), once(upstream, "close")]).then(() => resolve(), reject); }); @@ -315,7 +317,9 @@ test("#2832 self-healed relay: the canary clears the verdict and folding resumes assert.ok(okSummaries >= 1, "at least the canary summary succeeded"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); upstream.close(); + upstream.closeIdleConnections?.(); await new Promise((resolve, reject) => { void Promise.allSettled([once(proxy, "close"), once(upstream, "close")]).then(() => resolve(), reject); }); diff --git a/tests/issue2847-doomed-nonretryable-status.test.ts b/tests/issue2847-doomed-nonretryable-status.test.ts index 9bb4fe59e9..1736bf535c 100644 --- a/tests/issue2847-doomed-nonretryable-status.test.ts +++ b/tests/issue2847-doomed-nonretryable-status.test.ts @@ -126,7 +126,9 @@ async function setup(): Promise<{ ctx: Ctx; calls: Call[]; close: () => Promise< calls, close: async () => { proxy.close(); + proxy.closeIdleConnections?.(); upstream.close(); + upstream.closeIdleConnections?.(); await Promise.allSettled([once(proxy, "close"), once(upstream, "close")]); }, }; diff --git a/tests/issue3004-nudge-decide-selfheal.test.ts b/tests/issue3004-nudge-decide-selfheal.test.ts index 208e4d6896..eb0e3cc80d 100644 --- a/tests/issue3004-nudge-decide-selfheal.test.ts +++ b/tests/issue3004-nudge-decide-selfheal.test.ts @@ -242,8 +242,10 @@ async function startHarness(sessionId: string, modelDecided: boolean): Promise { h.proxy.close(); + h.proxy.closeIdleConnections?.(); await once(h.proxy, "close"); h.upstream.close(); + h.upstream.closeIdleConnections?.(); await once(h.upstream, "close"); } diff --git a/tests/issue453-backstop.test.ts b/tests/issue453-backstop.test.ts index 5382bb1894..bdf5841239 100644 --- a/tests/issue453-backstop.test.ts +++ b/tests/issue453-backstop.test.ts @@ -227,8 +227,10 @@ async function drive(o: DriveOpts): Promise<{ turn2Body: Record return { turn2Body, turn2MessageCount: ((turn2Body.messages ?? []) as unknown[]).length }; } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } } diff --git a/tests/issue496-forward-once-learn.test.ts b/tests/issue496-forward-once-learn.test.ts index fd526c9062..cdf3d3ca30 100644 --- a/tests/issue496-forward-once-learn.test.ts +++ b/tests/issue496-forward-once-learn.test.ts @@ -140,8 +140,10 @@ mitm: { enabled: false, domains: [] }, assert.deepEqual(streamForwards, [true], "still exactly one forward total (no re-forwarding loop)"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); diff --git a/tests/issue532-panel-system-tokens.test.ts b/tests/issue532-panel-system-tokens.test.ts index 4be8059a05..a2a1280a3e 100644 --- a/tests/issue532-panel-system-tokens.test.ts +++ b/tests/issue532-panel-system-tokens.test.ts @@ -178,8 +178,10 @@ async function startHarness(): Promise { upstreamPort, close: async () => { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); }, }; diff --git a/tests/issue767-pixel-billing.test.ts b/tests/issue767-pixel-billing.test.ts index 85485b2ac3..f8711ee09d 100644 --- a/tests/issue767-pixel-billing.test.ts +++ b/tests/issue767-pixel-billing.test.ts @@ -327,8 +327,10 @@ test("e2e #767: pixels billing recovers a stale-baseline session the bytes estim assert.equal(stats.imagesSeen, 4); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -363,8 +365,10 @@ test("e2e #767 control: explicit bytes route still fails fast — relay protecti assert.equal(stats.imagesSeen, 0, "over-window images never reached the upstream"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -403,8 +407,10 @@ test("e2e #1843: default route (auto→pixels) forwards an image-heavy payload t assert.ok(after.stats.lastInputTokens > 0 && after.stats.lastInputTokens < WINDOW, `baseline recovered to real usage (got ${after.stats.lastInputTokens})`); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -440,8 +446,10 @@ test("e2e #767: learned-limit-only variant also closes forward-once (explicit by assert.equal(stats.imagesSeen, 0); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -479,8 +487,10 @@ test("e2e #767: env BILI_IMAGE_BILLING beats per-provider route config", async ( assert.equal(stats.imagesSeen, 0); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -517,8 +527,10 @@ test("e2e #767: per-route imageBilling applies under a path-qualified provider k assert.ok(after.stats.lastInputTokens > 0 && after.stats.lastInputTokens < WINDOW, `baseline recovered to real usage (got ${after.stats.lastInputTokens})`); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); diff --git a/tests/issue833-panel-effective-config.test.ts b/tests/issue833-panel-effective-config.test.ts index 4209072ef3..943cb8069b 100644 --- a/tests/issue833-panel-effective-config.test.ts +++ b/tests/issue833-panel-effective-config.test.ts @@ -85,8 +85,10 @@ async function startHarness(opts: HarnessOpts): Promise { upstreamPort, close: async () => { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); }, }; diff --git a/tests/issue903-request-cost-log.test.ts b/tests/issue903-request-cost-log.test.ts index ac9e7c8e42..5791b42060 100644 --- a/tests/issue903-request-cost-log.test.ts +++ b/tests/issue903-request-cost-log.test.ts @@ -152,8 +152,10 @@ test("e2e: per-request cost line reports msg count, inbound wire size and local } finally { setLogCapture(null); proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); diff --git a/tests/main-path-transport-retry.test.ts b/tests/main-path-transport-retry.test.ts index 54b207519b..47380e8c06 100644 --- a/tests/main-path-transport-retry.test.ts +++ b/tests/main-path-transport-retry.test.ts @@ -76,6 +76,7 @@ test("#1688 unit: connect-refused is replayed and the recovered response is retu } finally { result?.clearTimer(); srv.close(); + srv.closeIdleConnections?.(); await once(srv, "close"); } assert.equal(retries.length, 1); @@ -106,6 +107,7 @@ test("#1688 unit: pre-response socket reset is replayed", async () => { } finally { result.clearTimer(); srv.close(); + srv.closeIdleConnections?.(); await once(srv, "close"); } assert.equal(retries.length, 1); @@ -148,6 +150,7 @@ test("#1688 unit: any HTTP verdict passes through untouched — never replayed, } finally { result.clearTimer(); srv.close(); + srv.closeIdleConnections?.(); await once(srv, "close"); } assert.equal(hits, 1, "a 4xx verdict goes straight back to the caller"); @@ -329,8 +332,10 @@ test("#1688 e2e: a pre-response reset mid-round is replayed transparently — th assert.equal(relay.streamingCalls(), 2, "exactly one transparent replay within the same request"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); relay.server.close(); + relay.server.closeIdleConnections?.(); await once(relay.server, "close"); } }); @@ -356,8 +361,10 @@ test("#1688 e2e: persistent transport failure exhausts the budget, then surfaces assert.equal(relay.streamingCalls(), 3, "exactly BILI_REPLAY_RETRY_MAX attempts, no unbounded storm"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); relay.server.close(); + relay.server.closeIdleConnections?.(); await once(relay.server, "close"); } }); @@ -382,8 +389,10 @@ test("#1688 e2e: an upstream 4xx verdict passes through verbatim without any rep assert.equal(relay.streamingCalls(), 1); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); relay.server.close(); + relay.server.closeIdleConnections?.(); await once(relay.server, "close"); } }); diff --git a/tests/mode-upgrade-proof.test.ts b/tests/mode-upgrade-proof.test.ts index ffbc309989..8243e947a0 100644 --- a/tests/mode-upgrade-proof.test.ts +++ b/tests/mode-upgrade-proof.test.ts @@ -272,8 +272,10 @@ test("mode-upgrade proof (chat wire): proxy->plugin flip keeps one session, one console.log(`proof[mode-upgrade] VERDICT bodies=${bodies.length} proxyFold=#${foldIdx} flip=#${flipBodyIdx} pair=#${pairIdx} blocks=${sess5.state.blocks.length} sticky=1 override=1`); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); if (prevXdg === undefined) delete process.env.XDG_STATE_HOME; else process.env.XDG_STATE_HOME = prevXdg; diff --git a/tests/native-compact-terminal.test.ts b/tests/native-compact-terminal.test.ts index 0ae201561e..9b8a7ca65c 100644 --- a/tests/native-compact-terminal.test.ts +++ b/tests/native-compact-terminal.test.ts @@ -194,8 +194,10 @@ test("e2e #321 PR-C: rebase only on completed; trigger request forwarded clean", assert.equal(pendingRebase("term-jsonok"), true, "JSON output response schedules the rebase"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); diff --git a/tests/nudge-model-decided.test.ts b/tests/nudge-model-decided.test.ts index 95c58654a6..a5df403036 100644 --- a/tests/nudge-model-decided.test.ts +++ b/tests/nudge-model-decided.test.ts @@ -147,8 +147,10 @@ async function runScenario(sessionId: string, modelDecided: boolean, verdict: st }; } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } } diff --git a/tests/opencode-fork-adopt.test.ts b/tests/opencode-fork-adopt.test.ts index 66c855e89f..18b76c09a6 100644 --- a/tests/opencode-fork-adopt.test.ts +++ b/tests/opencode-fork-adopt.test.ts @@ -57,7 +57,7 @@ async function harness() { await once(proxy, "listening"); const paddr = proxy.address(); assert(paddr && typeof paddr === "object"); - return { dir, store, upstreamUrl, origin: `http://127.0.0.1:${paddr.port}`, close: async () => { store.cancelAll(); proxy.close(); upstream.close(); await Promise.all([once(proxy, "close"), once(upstream, "close")]); } }; + return { dir, store, upstreamUrl, origin: `http://127.0.0.1:${paddr.port}`, close: async () => { store.cancelAll(); proxy.close(); proxy.closeIdleConnections?.(); upstream.close(); upstream.closeIdleConnections?.(); await Promise.all([once(proxy, "close"), once(upstream, "close")]); } }; } async function seedParent(h: Awaited>, conversationId: string) { diff --git a/tests/pi-omp-fork-adopt.test.ts b/tests/pi-omp-fork-adopt.test.ts index f7a54ab570..872f85cfde 100644 --- a/tests/pi-omp-fork-adopt.test.ts +++ b/tests/pi-omp-fork-adopt.test.ts @@ -319,7 +319,7 @@ async function harness() { await once(proxy, "listening"); const paddr = proxy.address(); assert(paddr && typeof paddr === "object"); - return { dir, store, upstreamUrl, origin: `http://127.0.0.1:${paddr.port}`, close: async () => { store.cancelAll(); proxy.close(); upstream.close(); await Promise.all([once(proxy, "close"), once(upstream, "close")]); } }; + return { dir, store, upstreamUrl, origin: `http://127.0.0.1:${paddr.port}`, close: async () => { store.cancelAll(); proxy.close(); proxy.closeIdleConnections?.(); upstream.close(); upstream.closeIdleConnections?.(); await Promise.all([once(proxy, "close"), once(upstream, "close")]); } }; } async function seedParent(h: Awaited>, conversationId: string) { diff --git a/tests/pi-subagent-channel.test.ts b/tests/pi-subagent-channel.test.ts index d7589e08d7..00f17bb453 100644 --- a/tests/pi-subagent-channel.test.ts +++ b/tests/pi-subagent-channel.test.ts @@ -317,8 +317,10 @@ test("#2268 server-level: tagged ACP-less delegate child gets proxy-style inject for (const n of CORE_ACP) assert.ok(!e.includes(n), `history-quoted marker must stay plugin mode (${n})`); } finally { rig.proxy.close(); + rig.proxy.closeIdleConnections?.(); await once(rig.proxy, "close"); rig.upstream.close(); + rig.upstream.closeIdleConnections?.(); await once(rig.upstream, "close"); } }); diff --git a/tests/plugin-bypass.test.ts b/tests/plugin-bypass.test.ts index e7c74c7211..0f39bc888d 100644 --- a/tests/plugin-bypass.test.ts +++ b/tests/plugin-bypass.test.ts @@ -70,7 +70,9 @@ mitm: { enabled: false, domains: [] }, captured, close: async () => { proxy.close(); + proxy.closeIdleConnections?.(); upstream.close(); + upstream.closeIdleConnections?.(); await Promise.allSettled([once(proxy, "close"), once(upstream, "close")]); }, }; diff --git a/tests/plugin-fork.test.ts b/tests/plugin-fork.test.ts index 297cf6d1bb..76616a99c3 100644 --- a/tests/plugin-fork.test.ts +++ b/tests/plugin-fork.test.ts @@ -112,7 +112,7 @@ async function harness(persist = false, seedParent = true, compressExtra: Record assert.equal(r.status, 200); await r.text(); } - return { request, messages, forwarded, dir, store, upstreamUrl, origin, close: async () => { store.cancelAll(); proxy.close(); upstream.close(); await Promise.all([once(proxy, "close"), once(upstream, "close")]); } }; + return { request, messages, forwarded, dir, store, upstreamUrl, origin, close: async () => { store.cancelAll(); proxy.close(); proxy.closeIdleConnections?.(); upstream.close(); upstream.closeIdleConnections?.(); await Promise.all([once(proxy, "close"), once(upstream, "close")]); } }; } test("plain proxy panel snapshots do not change raw-history persistence", async () => { diff --git a/tests/plugin-nudge-injection.test.ts b/tests/plugin-nudge-injection.test.ts index da1cb6096a..7c9b7e672a 100644 --- a/tests/plugin-nudge-injection.test.ts +++ b/tests/plugin-nudge-injection.test.ts @@ -117,8 +117,10 @@ async function forwardedTurn2Length(sessionId: string, extraHeaders: Record { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); }, }; diff --git a/tests/plugin-status-provenance.test.ts b/tests/plugin-status-provenance.test.ts index 719e7ddeca..07b0f802f8 100644 --- a/tests/plugin-status-provenance.test.ts +++ b/tests/plugin-status-provenance.test.ts @@ -83,7 +83,7 @@ async function harness() { const wait = new Promise((resolve) => { release = resolve; }); gate = { entered, wait }; return { waiting, release }; - }, close: async () => { store.cancelAll(); proxy.close(); upstream.close(); await Promise.all([once(proxy, "close"), once(upstream, "close")]); } }; + }, close: async () => { store.cancelAll(); proxy.close(); proxy.closeIdleConnections?.(); upstream.close(); upstream.closeIdleConnections?.(); await Promise.all([once(proxy, "close"), once(upstream, "close")]); } }; } test("HTTP usage -> compress -> decompress -> request keeps context provenance separate from billing", async (t) => { diff --git a/tests/plugin-terminal-usage.test.ts b/tests/plugin-terminal-usage.test.ts index 546a2c92fc..462ec8d445 100644 --- a/tests/plugin-terminal-usage.test.ts +++ b/tests/plugin-terminal-usage.test.ts @@ -111,7 +111,7 @@ async function harness(terminal: Record, late = "") { await drain(); store.cancelAll(); const closed = Promise.all([once(proxy, "close"), once(upstream, "close")]); - proxy.close(); upstream.close(); + proxy.close(); proxy.closeIdleConnections?.(); upstream.close(); upstream.closeIdleConnections?.(); await closed; }, }; diff --git a/tests/preflight-client-abort.test.ts b/tests/preflight-client-abort.test.ts index db66168141..3557253d1c 100644 --- a/tests/preflight-client-abort.test.ts +++ b/tests/preflight-client-abort.test.ts @@ -44,6 +44,7 @@ async function withUpstream(run: (url: string, mainCalls: () => number) => Promi } finally { const closed = once(server, "close"); server.close(); + server.closeIdleConnections?.(); server.closeAllConnections(); await closed; } @@ -163,6 +164,7 @@ for (const pluginMode of [false, true]) { client.destroy(); const closed = once(downstream, "close"); downstream.close(); + downstream.closeIdleConnections?.(); downstream.closeAllConnections(); await closed; } diff --git a/tests/preflight-codex-headroom.test.ts b/tests/preflight-codex-headroom.test.ts index e3e9ff4472..15d11d980e 100644 --- a/tests/preflight-codex-headroom.test.ts +++ b/tests/preflight-codex-headroom.test.ts @@ -85,8 +85,10 @@ async function withProxy(mode: "intercept" | "pass", run: (h: { }) }); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); if (previousMode === undefined) delete process.env.BILI_CODEX_COMPACT; else process.env.BILI_CODEX_COMPACT = previousMode; diff --git a/tests/preflight-compress-responses.test.ts b/tests/preflight-compress-responses.test.ts index c30127c54d..8b4e9b422d 100644 --- a/tests/preflight-compress-responses.test.ts +++ b/tests/preflight-compress-responses.test.ts @@ -175,8 +175,10 @@ test("e2e #280 (Responses): restored session with lastInputTokens=0 → prefligh assert.equal(sB!.stats.lastInputTokens, 1000, "the real usage report lands after the recovered forward"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); diff --git a/tests/preflight-compress.test.ts b/tests/preflight-compress.test.ts index 8dd69e950d..7d9d720688 100644 --- a/tests/preflight-compress.test.ts +++ b/tests/preflight-compress.test.ts @@ -183,8 +183,10 @@ test("e2e: model switch to a smaller window → preflight compresses before forw assert.equal(s2?.stats.lastInputTokens, 1000); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -272,8 +274,10 @@ test("e2e: no preflight when the context fits the (small) model window", async ( assert.equal((s?.state.blocks ?? []).filter((b) => b.active).length, 0, "no blocks created"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -377,8 +381,10 @@ test("e2e: fresh session (lastInputTokens=0) whose raw history overflows the win assert.equal(s?.stats.lastInputTokens, 1000); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -536,8 +542,10 @@ test("e2e: CJK stable session switch → preflight compresses (CJK-aware token a assert.ok(lastForward.body.includes(SUMMARY_TEXT), "the preflight summary is in the rebuilt payload"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); diff --git a/tests/preflight-covered-ranges.test.ts b/tests/preflight-covered-ranges.test.ts index b446cd740d..b24ab37ae8 100644 --- a/tests/preflight-covered-ranges.test.ts +++ b/tests/preflight-covered-ranges.test.ts @@ -61,6 +61,7 @@ async function runCoveredRange(protectLatest = false, pairBoundary = false, unkn } finally { const closed = once(upstream, "close"); upstream.close(); + upstream.closeIdleConnections?.(); upstream.closeAllConnections(); await closed; } diff --git a/tests/preflight-empty-summary.test.ts b/tests/preflight-empty-summary.test.ts index 5cd1f34c28..464fac939c 100644 --- a/tests/preflight-empty-summary.test.ts +++ b/tests/preflight-empty-summary.test.ts @@ -201,7 +201,9 @@ test("changed over-window content bypasses a previous dead-end cooldown", async assert.ok(calls.length > callsBefore, "changed content must retry preflight even at the same length/model/window"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); upstream.close(); + upstream.closeIdleConnections?.(); await Promise.all([once(proxy, "close"), once(upstream, "close")]); } }); @@ -238,7 +240,9 @@ test(`temporary summary HTTP ${status} failure does not cache a deterministic de assert.ok(calls > callsBefore, "next request must reach the upstream"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); upstream.close(); + upstream.closeIdleConnections?.(); await Promise.all([once(proxy, "close"), once(upstream, "close")]); } }); @@ -277,7 +281,9 @@ test("#726 size-driven empty summary: oversized chunk fails, halved chunk recove assert.equal(sess?.metadata?.preflightDeadEnd, undefined, "successful preflight must not leave a dead-end marker"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); upstream.close(); + upstream.closeIdleConnections?.(); await new Promise((resolve, reject) => { void Promise.allSettled([once(proxy, "close"), once(upstream, "close")]).then(() => resolve(), reject); }); @@ -332,7 +338,9 @@ test("#726 systemic empty summary: diagnosis surfaced, bounded calls, cooldown b assert.ok(calls.length > callsBeforeExpire, "after the cooldown expires the walk must run again"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); upstream.close(); + upstream.closeIdleConnections?.(); await new Promise((resolve, reject) => { void Promise.allSettled([once(proxy, "close"), once(upstream, "close")]).then(() => resolve(), reject); }); @@ -372,7 +380,9 @@ test("#726 dead-end cooldown must not block safe-forwards: fitting payload under assert.ok(calls.length > callsBeforeSmall && calls[calls.length - 1].summary === false, "the small payload was forwarded to the upstream"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); upstream.close(); + upstream.closeIdleConnections?.(); await new Promise((resolve, reject) => { void Promise.allSettled([once(proxy, "close"), once(upstream, "close")]).then(() => resolve(), reject); }); @@ -480,7 +490,9 @@ test("#780 truncated summary stream is unusable: diagnosis names truncation, bou assert.equal(calls.length, callsBeforeRetry, "cooldown must spend ZERO upstream calls"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); upstream.close(); + upstream.closeIdleConnections?.(); await new Promise((resolve, reject) => { void Promise.allSettled([once(proxy, "close"), once(upstream, "close")]).then(() => resolve(), reject); }); diff --git a/tests/preflight-fail-fast.test.ts b/tests/preflight-fail-fast.test.ts index 02f74bd672..74c66b74f5 100644 --- a/tests/preflight-fail-fast.test.ts +++ b/tests/preflight-fail-fast.test.ts @@ -149,8 +149,10 @@ test("e2e #301: overflow + summary upstream 429 → structured 503, over-window assert.ok(calls.filter((c) => !c.stream).length >= 1, "preflight attempted the (429'd) summarization call"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -215,8 +217,10 @@ test("e2e #301: payload fits the window + preflight 429 → request still forwar assert.equal(calls.filter((c) => c.stream).length, 2, "both requests were forwarded upstream"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -262,8 +266,10 @@ test("e2e #301: over-window payload with nothing compressible → structured 502 assert.equal(calls.filter((c) => c.stream).length, 0, "the over-window payload was NOT forwarded upstream"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -311,8 +317,10 @@ test("e2e #330: over-window payload whose only foldable content is in the protec assert.equal(calls.filter((c) => c.stream).length, 1, "the folded payload was forwarded upstream"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -358,8 +366,10 @@ test("e2e #470: system + tools overhead counts in the preflight trigger — text assert.ok(!forwarded.includes("A".repeat(100)), "the folded big message did NOT ride the forwarded payload"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -427,11 +437,14 @@ test("e2e #736: operator-shrunk window (compress.modelContextLimit below the mod const msg2 = (JSON.parse(await r2.text()) as { error?: { message?: string } }).error?.message ?? ""; assert.ok(!msg2.includes("full window"), `no shrink note when the window was not operator-shrunk (got: ${msg2})`); proxyPlain.close(); + proxyPlain.closeIdleConnections?.(); await once(proxyPlain, "close"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -491,8 +504,10 @@ test("e2e #737: output-headroom-shrunk window (non-Anthropic, no operator overri assert.equal(calls.length, 0, "no upstream call was spent on an incompressible payload"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); diff --git a/tests/preflight-fork-estimate.test.ts b/tests/preflight-fork-estimate.test.ts index a3a4bf6ed4..62ea6bdc22 100644 --- a/tests/preflight-fork-estimate.test.ts +++ b/tests/preflight-fork-estimate.test.ts @@ -203,8 +203,10 @@ test("e2e: fork/fresh session (lastInputTokens=0) with dense history that estima assert.equal(s?.stats.lastInputTokens, 1000); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -295,8 +297,10 @@ test("e2e: fresh session whose history genuinely fits the window → no prefligh assert.equal((s?.state.blocks ?? []).filter((b) => b.active).length, 0, "no blocks created"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); diff --git a/tests/preflight-google-summary.test.ts b/tests/preflight-google-summary.test.ts index 73034c0069..56ee02cf27 100644 --- a/tests/preflight-google-summary.test.ts +++ b/tests/preflight-google-summary.test.ts @@ -150,8 +150,10 @@ test("e2e preflight (#829): a Gemini summary reply that streams although the cal assert.ok(markers < 12 * 250, `the folded payload must drop raw marker text, still carried ${markers}`); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -184,8 +186,10 @@ test("e2e preflight (#829): the JSON summary of a non-streaming Gemini call is r assert.ok(body.includes("forwarded to the model"), `the model reply reached the client, got: ${body.slice(0, 300)}`); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); diff --git a/tests/preflight-hold.test.ts b/tests/preflight-hold.test.ts index a54bf895bb..5922bd7ae7 100644 --- a/tests/preflight-hold.test.ts +++ b/tests/preflight-hold.test.ts @@ -185,8 +185,10 @@ test("#568: stream + slow preflight → early 200 + SSE keep-alive, then the rea assert.ok(fwd.includes("MARKER_11_"), "recent protected messages remain in the payload"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -238,8 +240,10 @@ test("#568: stream + slow preflight 429 → early-committed 200 carries the erro assert.ok(calls.filter((c) => !c.raw.includes('"stream":true')).length >= 1, "the (slow, 429'd) summarization call happened"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -286,8 +290,10 @@ test("#568: Responses protocol + slow preflight 429 → early-committed 200, in- assert.equal(calls.filter((c) => !c.raw.includes('"stream":false')).length, 0, "nothing was forwarded"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -363,8 +369,10 @@ test("#568: non-stream + slow preflight → early 200 + whitespace keep-alive, t assert.ok(forwards[0]!.raw.includes(SUMMARY_TEXT), "the rebuilt payload carries the preflight summary"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); diff --git a/tests/preflight-incomplete-json.test.ts b/tests/preflight-incomplete-json.test.ts index a57313c5de..a5d8818fb1 100644 --- a/tests/preflight-incomplete-json.test.ts +++ b/tests/preflight-incomplete-json.test.ts @@ -139,7 +139,7 @@ async function drive(proxyPort: number, upstreamPort: number, session: string, m } async function closeAll(...servers: http.Server[]): Promise { - for (const s of servers) s.close(); + for (const s of servers) { s.close(); s.closeIdleConnections?.(); } await Promise.allSettled(servers.map((s) => once(s, "close"))); } diff --git a/tests/preflight-max-output-tokens.test.ts b/tests/preflight-max-output-tokens.test.ts index 8ec99d3897..317fb1930c 100644 --- a/tests/preflight-max-output-tokens.test.ts +++ b/tests/preflight-max-output-tokens.test.ts @@ -233,7 +233,9 @@ test("e2e #663 (order A, stream-first): learn both rejections, summary recovers, ); } finally { proxy.close(); + proxy.closeIdleConnections?.(); upstream.close(); + upstream.closeIdleConnections?.(); await new Promise((resolve, reject) => { void Promise.allSettled([once(proxy, "close"), once(upstream, "close")]).then(() => resolve(), reject); }); @@ -276,7 +278,9 @@ test("e2e #663 (order B, param-first): max_output_tokens rejected before stream assert.ok(calls.some((c) => !c.summary), "the folded payload was forwarded"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); upstream.close(); + upstream.closeIdleConnections?.(); await new Promise((resolve, reject) => { void Promise.allSettled([once(proxy, "close"), once(upstream, "close")]).then(() => resolve(), reject); }); @@ -330,7 +334,9 @@ test("e2e #663 (standard provider): max_output_tokens retained, no capability le assert.equal(sess?.metadata?.preflightStreamSummary, undefined, "no stream learning for a standard provider"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); upstream.close(); + upstream.closeIdleConnections?.(); await new Promise((resolve, reject) => { void Promise.allSettled([once(proxy, "close"), once(upstream, "close")]).then(() => resolve(), reject); }); @@ -391,7 +397,9 @@ test("e2e #663 (model scoping): rejection learned for model A keeps model B's 32 assert.equal(learned?.[learnKey(upstreamUrl, "gpt-6-standard")], undefined, "model B key NOT learned"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); upstream.close(); + upstream.closeIdleConnections?.(); await new Promise((resolve, reject) => { void Promise.allSettled([once(proxy, "close"), once(upstream, "close")]).then(() => resolve(), reject); }); @@ -461,7 +469,9 @@ test("e2e #663 (codex lite header): summary drops the Lite header, main request } } finally { proxy.close(); + proxy.closeIdleConnections?.(); upstream.close(); + upstream.closeIdleConnections?.(); await new Promise((resolve, reject) => { void Promise.allSettled([once(proxy, "close"), once(upstream, "close")]).then(() => resolve(), reject); }); @@ -546,7 +556,9 @@ test("e2e #663 (anthropic): header strip is a no-op — summary keeps auth, fold } } finally { proxy.close(); + proxy.closeIdleConnections?.(); upstream.close(); + upstream.closeIdleConnections?.(); await new Promise((resolve, reject) => { void Promise.allSettled([once(proxy, "close"), once(upstream, "close")]).then(() => resolve(), reject); }); diff --git a/tests/preflight-multi-range.test.ts b/tests/preflight-multi-range.test.ts index 138b1f6e42..1ecc7e9194 100644 --- a/tests/preflight-multi-range.test.ts +++ b/tests/preflight-multi-range.test.ts @@ -148,8 +148,10 @@ test("#574 regression: oldest range's summary unusable → preflight moves to th assert.ok(activeBlocks.length >= 1, `a later range was folded into a block (got ${activeBlocks.length})`); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -188,8 +190,10 @@ test("#574 truthful exhaustion: every range's summary unusable → honest 502 (f assert.equal(activeBlocks.length, 0, "no blocks created when nothing could be compressed"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -243,8 +247,10 @@ test("#574 budget cap: many unusable ranges → the base cap (entry overshoot < assert.equal(activeBlocks.length, 0, "no blocks created when nothing could be compressed"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); diff --git a/tests/preflight-nonstream-400-probe.test.ts b/tests/preflight-nonstream-400-probe.test.ts index 1b746bf620..03c6e32f04 100644 --- a/tests/preflight-nonstream-400-probe.test.ts +++ b/tests/preflight-nonstream-400-probe.test.ts @@ -118,7 +118,7 @@ async function driveChatPreflight(proxyPort: number, upstreamPort: number, sessi } async function closeAll(...servers: http.Server[]): Promise { - for (const s of servers) s.close(); + for (const s of servers) { s.close(); s.closeIdleConnections?.(); } await Promise.allSettled(servers.map((s) => once(s, "close"))); } diff --git a/tests/preflight-round-budget.test.ts b/tests/preflight-round-budget.test.ts index 1b22e18309..c01e77789e 100644 --- a/tests/preflight-round-budget.test.ts +++ b/tests/preflight-round-budget.test.ts @@ -140,8 +140,10 @@ test("e2e preflight: a payload that needs more folds than one round allows is st assert.ok(markers < MESSAGES * FILLER_REPEATS, `the fold must drop raw range text, still carried ${markers}`); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); @@ -186,8 +188,10 @@ test("e2e preflight: beyond the round budget the fail-fast reports the post-fold assert.equal(CALLS.filter((c) => c.raw.includes('"stream":true')).length, 0, "the over-window payload was NOT forwarded"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); diff --git a/tests/preflight-stream-summary-config.test.ts b/tests/preflight-stream-summary-config.test.ts index 84f81ff869..88781a81ad 100644 --- a/tests/preflight-stream-summary-config.test.ts +++ b/tests/preflight-stream-summary-config.test.ts @@ -120,7 +120,7 @@ async function driveResponsesPreflight(proxyPort: number, upstreamPort: number, function closeAll(servers: http.Server[]): Promise { return new Promise((resolve, reject) => { - void Promise.allSettled(servers.map((s) => { s.close(); return once(s, "close"); })).then(() => resolve(), reject); + void Promise.allSettled(servers.map((s) => { s.close(); s.closeIdleConnections?.(); return once(s, "close"); })).then(() => resolve(), reject); }); } diff --git a/tests/preflight-stream-summary.test.ts b/tests/preflight-stream-summary.test.ts index 96f7697004..3f402ae884 100644 --- a/tests/preflight-stream-summary.test.ts +++ b/tests/preflight-stream-summary.test.ts @@ -172,7 +172,9 @@ test("e2e #626 (Responses, delta SSE): stream-only upstream → learn on 400, su ); } finally { proxy.close(); + proxy.closeIdleConnections?.(); upstream.close(); + upstream.closeIdleConnections?.(); await new Promise((resolve, reject) => { void Promise.allSettled([once(proxy, "close"), once(upstream, "close")]).then(() => resolve(), reject); }); @@ -200,7 +202,9 @@ test("e2e #626 (Responses, completed-only SSE): summary extracted from response. assert.ok(forwardRaw.length > 0); } finally { proxy.close(); + proxy.closeIdleConnections?.(); upstream.close(); + upstream.closeIdleConnections?.(); await new Promise((resolve, reject) => { void Promise.allSettled([once(proxy, "close"), once(upstream, "close")]).then(() => resolve(), reject); }); @@ -293,7 +297,9 @@ test("e2e #626 (Anthropic): stream-only upstream → learn on 400, text_delta SS assert.equal(sess?.metadata?.preflightStreamSummary, true, "learned"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); upstream.close(); + upstream.closeIdleConnections?.(); await new Promise((resolve, reject) => { void Promise.allSettled([once(proxy, "close"), once(upstream, "close")]).then(() => resolve(), reject); }); diff --git a/tests/preflight-summary-cap.test.ts b/tests/preflight-summary-cap.test.ts index f749e687ec..8ca6217fa5 100644 --- a/tests/preflight-summary-cap.test.ts +++ b/tests/preflight-summary-cap.test.ts @@ -82,6 +82,7 @@ test("#853 summary output cap: 32k default, clamped to known model ceiling", asy } } finally { server.close(); + server.closeIdleConnections?.(); await once(server, "close"); } } diff --git a/tests/preflight-summary-length-budget.test.ts b/tests/preflight-summary-length-budget.test.ts index c2d21e1876..c5933447f3 100644 --- a/tests/preflight-summary-length-budget.test.ts +++ b/tests/preflight-summary-length-budget.test.ts @@ -68,6 +68,7 @@ async function runLengthBudget(opts: { fillerRepeats: number; summaryText: strin return { result, session, bodies, logs }; } finally { server.close(); + server.closeIdleConnections?.(); await once(server, "close"); } } diff --git a/tests/preflight-transient-empty-retry.test.ts b/tests/preflight-transient-empty-retry.test.ts index 88f570be17..8916390ad8 100644 --- a/tests/preflight-transient-empty-retry.test.ts +++ b/tests/preflight-transient-empty-retry.test.ts @@ -188,7 +188,9 @@ test("#1767 transient content_filter empties: same-span retries recover the turn assert.equal(sess?.metadata?.preflightDeadEnd, undefined, "successful preflight must not leave a dead-end marker"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); upstream.close(); + upstream.closeIdleConnections?.(); await new Promise((resolve, reject) => { void Promise.allSettled([once(proxy, "close"), once(upstream, "close")]).then(() => resolve(), reject); }); @@ -242,7 +244,9 @@ test("#1767 systemic content_filter: bounded summary calls, diagnosis surfaced, assert.equal(calls.length, callsBeforeRetry, "cooldown must spend ZERO upstream calls"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); upstream.close(); + upstream.closeIdleConnections?.(); await new Promise((resolve, reject) => { void Promise.allSettled([once(proxy, "close"), once(upstream, "close")]).then(() => resolve(), reject); }); diff --git a/tests/preflight-transport-recovery.test.ts b/tests/preflight-transport-recovery.test.ts index 130cb0cb8e..01a877af9c 100644 --- a/tests/preflight-transport-recovery.test.ts +++ b/tests/preflight-transport-recovery.test.ts @@ -72,6 +72,7 @@ async function withUpstream(handler: (res: http.ServerResponse, attempt: number) } finally { const closed = once(server, "close"); server.close(); + server.closeIdleConnections?.(); server.closeAllConnections(); await closed; } diff --git a/tests/preflight-window-clamp.test.ts b/tests/preflight-window-clamp.test.ts index f50f200286..1727995af9 100644 --- a/tests/preflight-window-clamp.test.ts +++ b/tests/preflight-window-clamp.test.ts @@ -78,6 +78,7 @@ test("#987 summary max_tokens clamped to window headroom on small windows", asyn assert.ok(sawClamp, "the clamp must actually engage on this window (some call below the 32k default)"); } finally { server.close(); + server.closeIdleConnections?.(); await once(server, "close"); } }); @@ -122,6 +123,7 @@ test("#987 summary max_tokens keeps the 32k default when headroom is ample", asy } } finally { server.close(); + server.closeIdleConnections?.(); await once(server, "close"); } }); diff --git a/tests/proxy-noinject-tag-strip.test.ts b/tests/proxy-noinject-tag-strip.test.ts index 0bc62d255e..f947c1be9d 100644 --- a/tests/proxy-noinject-tag-strip.test.ts +++ b/tests/proxy-noinject-tag-strip.test.ts @@ -82,8 +82,10 @@ async function startHarness(compress: { injectTool: boolean; injectNudge: boolea upstreamPort, close: async () => { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); }, }; diff --git a/tests/responses-plugin-dev-position.test.ts b/tests/responses-plugin-dev-position.test.ts index aa5c93e1c4..fda2565587 100644 --- a/tests/responses-plugin-dev-position.test.ts +++ b/tests/responses-plugin-dev-position.test.ts @@ -164,8 +164,10 @@ async function driveResponses(steps: Step[], mode: "plugin" | "proxy"): Promise< } } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); if (prevXdg === undefined) delete process.env.XDG_STATE_HOME; else process.env.XDG_STATE_HOME = prevXdg; diff --git a/tests/rules-wire.test.ts b/tests/rules-wire.test.ts index 2b582714dc..484faeadc5 100644 --- a/tests/rules-wire.test.ts +++ b/tests/rules-wire.test.ts @@ -116,8 +116,10 @@ test("#749 anthropic wire: acp_rule injected alongside ACP tools when rules enab assert.equal(names.filter((n) => n === "acp_rule").length, 1, "acp_rule appears exactly once"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); up.server.close(); + up.server.closeIdleConnections?.(); await once(up.server, "close"); } }); @@ -137,8 +139,10 @@ test("#1399 anthropic wire: acp_rule NOT injected when unset (opt-in)", async () assert.ok(!names.includes("acp_rule"), `acp_rule absent while unset — opt-in (got: ${names.join(", ")})`); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); up.server.close(); + up.server.closeIdleConnections?.(); await once(up.server, "close"); } }); @@ -158,8 +162,10 @@ test("#749 anthropic wire: acp_rule NOT injected when explicitly disabled", asyn assert.ok(!names.includes("acp_rule"), `acp_rule absent when disabled (got: ${names.join(", ")})`); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); up.server.close(); + up.server.closeIdleConnections?.(); await once(up.server, "close"); } }); @@ -186,8 +192,10 @@ test("#749 openai wire: acp_rule function tool injected when rules enabled", asy assert.equal(names.filter((n) => n === "acp_rule").length, 1, "acp_rule appears exactly once"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); up.server.close(); + up.server.closeIdleConnections?.(); await once(up.server, "close"); } }); @@ -209,8 +217,10 @@ test("#749 responses wire: acp_rule flat tool injected when rules enabled", asyn assert.equal(names.filter((n) => n === "acp_rule").length, 1, "acp_rule appears exactly once"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); up.server.close(); + up.server.closeIdleConnections?.(); await once(up.server, "close"); } }); @@ -238,8 +248,10 @@ test("#749 anthropic wire: client-supplied tools merge without duplicating acp_r assert.ok(names.includes("compress"), "missing ACP tools still appended"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); up.server.close(); + up.server.closeIdleConnections?.(); await once(up.server, "close"); } }); diff --git a/tests/runtime-info.test.ts b/tests/runtime-info.test.ts index 0c6782e393..65cdb1cf5c 100644 --- a/tests/runtime-info.test.ts +++ b/tests/runtime-info.test.ts @@ -300,7 +300,9 @@ async function startHarness(): Promise { upstreamPort, close: async () => { proxy.close(); + proxy.closeIdleConnections?.(); upstream.close(); + upstream.closeIdleConnections?.(); await Promise.allSettled([once(proxy, "close"), once(upstream, "close")]); if (prevStateHome === undefined) delete process.env.XDG_STATE_HOME; else process.env.XDG_STATE_HOME = prevStateHome; diff --git a/tests/session-continuity-proof.test.ts b/tests/session-continuity-proof.test.ts index 20effdb4a7..31c74b7cf6 100644 --- a/tests/session-continuity-proof.test.ts +++ b/tests/session-continuity-proof.test.ts @@ -149,7 +149,7 @@ async function harness(wire: Wire) { }; return { dshChat, pluginTool, snapshot, fork, forwarded, store, - close: async () => { store.cancelAll(); proxy.close(); upstream.close(); await Promise.all([once(proxy, "close"), once(upstream, "close")]); }, + close: async () => { store.cancelAll(); proxy.close(); proxy.closeIdleConnections?.(); upstream.close(); upstream.closeIdleConnections?.(); await Promise.all([once(proxy, "close"), once(upstream, "close")]); }, }; } diff --git a/tests/session-lock-concurrency.test.ts b/tests/session-lock-concurrency.test.ts index 7eacac3605..ee61317ccf 100644 --- a/tests/session-lock-concurrency.test.ts +++ b/tests/session-lock-concurrency.test.ts @@ -129,8 +129,10 @@ test("#970: concurrent requests on the same session id forward concurrently (no assert.equal(peekSession(SESSION)!.stats.requests, 3, "follow-up must land on the same session"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); diff --git a/tests/side-request-isolation.test.ts b/tests/side-request-isolation.test.ts index 9f262d1402..97d7905e04 100644 --- a/tests/side-request-isolation.test.ts +++ b/tests/side-request-isolation.test.ts @@ -455,8 +455,10 @@ mitm: { enabled: false, domains: [] }, async function closeRig(rig: Rig): Promise { rig.proxy.close(); + rig.proxy.closeIdleConnections?.(); await once(rig.proxy, "close"); rig.upstream.close(); + rig.upstream.closeIdleConnections?.(); await once(rig.upstream, "close"); } @@ -986,8 +988,10 @@ test("e2e: google-lane dsh side request resolves verbatim — no kernel state, n assert.equal(peekSession(fork), undefined, "still no forked session after the main turn"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); diff --git a/tests/store-marker-gate.test.ts b/tests/store-marker-gate.test.ts index 3385725b9d..561147b066 100644 --- a/tests/store-marker-gate.test.ts +++ b/tests/store-marker-gate.test.ts @@ -78,8 +78,10 @@ async function startHarness(marker: boolean): Promise { captured, close: async () => { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); }, }; diff --git a/tests/stream-keepalive.test.ts b/tests/stream-keepalive.test.ts index b3856e107b..14b7d00a9c 100644 --- a/tests/stream-keepalive.test.ts +++ b/tests/stream-keepalive.test.ts @@ -96,6 +96,7 @@ async function startHarness(upstreamPort: number): Promise { proxyPort: (proxy.address() as { port: number }).port, close: async () => { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); }, }; @@ -138,6 +139,7 @@ test("#1647 slow prefill: keep-alive comments hold the client through ping-only delete process.env.BILI_STREAM_KEEPALIVE_MS; up.server.closeAllConnections?.(); up.server.close(); + up.server.closeIdleConnections?.(); await once(up.server, "close"); await h.close(); } @@ -157,6 +159,7 @@ test("#1647 fast stream: no spurious keep-alive injection", async () => { delete process.env.BILI_STREAM_KEEPALIVE_MS; up.server.closeAllConnections?.(); up.server.close(); + up.server.closeIdleConnections?.(); await once(up.server, "close"); await h.close(); } @@ -175,6 +178,7 @@ test("#1647 BILI_STREAM_KEEPALIVE_MS=0 disables the hold", async () => { delete process.env.BILI_STREAM_KEEPALIVE_MS; up.server.closeAllConnections?.(); up.server.close(); + up.server.closeIdleConnections?.(); await once(up.server, "close"); await h.close(); } diff --git a/tests/websearch-side-request.test.ts b/tests/websearch-side-request.test.ts index 698ee02877..82772cde17 100644 --- a/tests/websearch-side-request.test.ts +++ b/tests/websearch-side-request.test.ts @@ -190,8 +190,10 @@ async function startRig(): Promise { async function closeRig(rig: Rig): Promise { rig.proxy.close(); + rig.proxy.closeIdleConnections?.(); await once(rig.proxy, "close"); rig.upstream.close(); + rig.upstream.closeIdleConnections?.(); await once(rig.upstream, "close"); } diff --git a/tests/wire-exit-gap-cells.test.ts b/tests/wire-exit-gap-cells.test.ts index ff33ab13d2..0bacfd14ac 100644 --- a/tests/wire-exit-gap-cells.test.ts +++ b/tests/wire-exit-gap-cells.test.ts @@ -247,8 +247,10 @@ test("gap 3: non-stream + preflight 429 after early commit → structured JSON e assert.equal(up.forwards(), 0, "the over-window payload was NOT forwarded"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); up.server.close(); + up.server.closeIdleConnections?.(); await once(up.server, "close"); } }); @@ -269,8 +271,10 @@ test("gap 4: non-stream + upstream 400 after early commit → verbatim upstream assert.equal(up.forwards(), 1); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); up.server.close(); + up.server.closeIdleConnections?.(); await once(up.server, "close"); } }); @@ -317,8 +321,10 @@ test("gap 5: repeated client aborts on proxy-openai-sse → upstream destroyed, assert.equal(_liveUpstreamTimersForTest(), 0, "no accumulated timers after the storm"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); upstream.close(); + upstream.closeIdleConnections?.(); await once(upstream, "close"); } }); diff --git a/tests/wire-exit-matrix.test.ts b/tests/wire-exit-matrix.test.ts index e03abd6978..6986f91d62 100644 --- a/tests/wire-exit-matrix.test.ts +++ b/tests/wire-exit-matrix.test.ts @@ -214,8 +214,10 @@ test("abort x proxy-openai-sse: client abort mid-stream destroys the upstream re assert.equal(up.requests(), 1, "exactly one upstream request"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); up.server.close(); + up.server.closeIdleConnections?.(); await once(up.server, "close"); } }); @@ -232,8 +234,10 @@ test("abort x proxy-anthropic-sse: client abort mid-stream destroys the upstream assert.ok(up.socketsClosed() >= 1, `upstream socket(s) destroyed after client abort (closed=${up.socketsClosed()})`); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); up.server.close(); + up.server.closeIdleConnections?.(); await once(up.server, "close"); } }); @@ -250,8 +254,10 @@ test("abort x proxy-responses-sse: client abort mid-stream destroys the upstream assert.ok(up.socketsClosed() >= 1, `upstream socket(s) destroyed after client abort (closed=${up.socketsClosed()})`); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); up.server.close(); + up.server.closeIdleConnections?.(); await once(up.server, "close"); } }); @@ -268,8 +274,10 @@ test("abort x proxy-json: client abort while the JSON is buffering destroys the assert.ok(up.socketsClosed() >= 1, `upstream socket(s) destroyed after client abort (closed=${up.socketsClosed()})`); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); up.server.close(); + up.server.closeIdleConnections?.(); await once(up.server, "close"); } }); @@ -310,8 +318,10 @@ test("error-delivery x proxy-openai-sse: upstream 429 AFTER the early 200 commit assert.ok(!r.body.includes('"choices":[{"index":0,"message"'), "no fabricated model content after the failure"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); up.server.close(); + up.server.closeIdleConnections?.(); await once(up.server, "close"); } }); @@ -345,8 +355,10 @@ test("error-delivery x proxy-openai-sse: preflight failure after the early commi assert.equal(up.requests(), 1, "the failed preflight means no forward happened"); } finally { proxy.close(); + proxy.closeIdleConnections?.(); await once(proxy, "close"); up.server.close(); + up.server.closeIdleConnections?.(); await once(up.server, "close"); } });