From 7576d8fa67f469be329e4f9210f42c9dffc15bc9 Mon Sep 17 00:00:00 2001 From: Framewrk CI Date: Wed, 11 Nov 2026 01:52:07 +0100 Subject: [PATCH] test: make safe-teardown suite hermetic like the other suites test/safe-teardown.test.js was the only suite that did not scrub OPENCODE_LLM_PROXY_* variables from the environment before each test. With a developer/CI shell that exports a token (OPENCODE_LLM_PROXY_TOKEN) every request in the suite got a 401, so seven tests failed for reasons unrelated to the code under test. Add the same beforeEach scrub used by stream-conformance, http-integration and tool-payload-fidelity. The two tests that need specific values still set them inside their own bodies, i.e. after the hook runs. --- test/safe-teardown.test.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/safe-teardown.test.js b/test/safe-teardown.test.js index 9b21f10..cb07d2e 100644 --- a/test/safe-teardown.test.js +++ b/test/safe-teardown.test.js @@ -1,10 +1,19 @@ import assert from "node:assert/strict" import { Buffer } from "node:buffer" import http from "node:http" -import test from "node:test" +import test, { beforeEach } from "node:test" import { createProxyFetchHandler, sweepStaleProxySessions } from "../index.js" +// Keep the suite hermetic: OPENCODE_LLM_PROXY_* variables from the developer's +// shell or CI (e.g. a token, host or port) must not change outcomes. Tests that +// need a specific value set it inside the test body, after this hook has run. +beforeEach(() => { + for (const name of Object.keys(process.env)) { + if (name.startsWith("OPENCODE_LLM_PROXY_")) delete process.env[name] + } +}) + const TOKENS = { input: 2, output: 1, reasoning: 0, cache: { read: 0, write: 0 } } function createMockClient({ promptMode = "hang", streamEvents = null } = {}) {