Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test(preload): a scoped resetGateway() no longer leaks its provider key into later tests and files
garrytan7b04743a1255
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 1b61e463ff..162b964be3 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,6 +10,21 @@ credits are retained; no result has been reassigned to another provider. Originaidentifiers and attribution are available in the pre-removal Git revision`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).+## [0.60.404.0] - 2026-10-23++**The managed Gmail recent-first test no longer fails depending on which test files share its bun process.** A provider key that one file set for its own scope leaked into the AI gateway of every later file, so chat looked available and the Gmail loops catch-up ran where the test expects it skipped. No product code changes; the catch-up's thread read was correct behavior.++### What changed++| Situation | Before | Now |+|---|---|---|+| A test calls `resetGateway()` inside a `withEnv` scope that sets a provider key | the preload's reset baseline kept that key after the scope ended, for every later test and file in the process (`test (13, 14)`: g5-single-page-generations, then google-gmail-recent-first saw `17aa00000000b001` fetched again by the loops catch-up) | before each test, the preload re-applies its baseline when the installed baseline's env no longer matches `process.env` |++### Itemized changes++- `test/helpers/legacy-embedding-preload.ts`: the reset baseline remembers the env it snapshotted; `beforeEach` re-applies the baseline when that snapshot is the live gateway env and differs from `process.env`. A config a file installed itself is left alone.+- `test/gateway-reset-baseline-scope.test.ts`: forced probe. A scoped reset sees its key, and the next test sees chat unavailable (failed before the fix).+## [0.60.403.0] - 2026-10-23**A Windows backup whose PowerShell starts too slowly now says so instead of blaming the destination's permissions, and a post-compaction SessionStart whose serve did not answer in time now says so in its heartbeat.** Three CI flakes behind these are fixed without loosening any bound, and the nightly race hunt runs every file again.diff --git a/test/gateway-reset-baseline-scope.test.ts b/test/gateway-reset-baseline-scope.test.tsnew file mode 100644index 0000000000..f29cb9a6ff--- /dev/null+++ b/test/gateway-reset-baseline-scope.test.ts@@ -0,0 +1,23 @@+/**+ * The test preload's reset baseline (test/helpers/legacy-embedding-preload.ts)+ * snapshots process.env. A resetGateway() inside a withEnv scope that sets a+ * provider key used to leave that key in the gateway after the scope ended, so+ * every later test file in the same bun process saw chat as available. In CI+ * that let test/pathological/g5-single-page-generations.test.ts turn on the+ * Gmail loops catch-up in test/google-gmail-recent-first.test.ts.+ */+import { expect, test } from 'bun:test';+import { isAvailable, resetGateway } from '../src/core/ai/gateway.ts';+import { withEnv } from './helpers/with-env.ts';++test('a reset inside a scoped provider key uses that key', async () => {+ await withEnv({ ANTHROPIC_API_KEY: 'sk-ant-scoped-probe' }, async () => {+ resetGateway();+ expect(isAvailable('chat')).toBe(true);+ });+});++test('the next test does not inherit the key the scoped reset snapshotted', () => {+ expect(process.env.ANTHROPIC_API_KEY).toBeUndefined();+ expect(isAvailable('chat')).toBe(false);+});diff --git a/test/helpers/legacy-embedding-preload.ts b/test/helpers/legacy-embedding-preload.tsindex 966c50d404..4e9fe597db 100644--- a/test/helpers/legacy-embedding-preload.ts+++ b/test/helpers/legacy-embedding-preload.ts@@ -1,6 +1,7 @@import {configureGateway,getEmbeddingDimensions,+ requireConfig,__setGatewayResetBaselineForTests,} from '../../src/core/ai/gateway.ts';import { beforeEach } from 'bun:test';@@ -9,14 +10,26 @@ import { beforeEach } from 'bun:test';// fixture is baked under the exact shape this preload pins.import { LEGACY_EMBEDDING_CONFIG as LEGACY_CONFIG } from './legacy-embedding-config.ts';+// The env snapshot of the last baseline this preload installed. A reset inside+// a withEnv scope snapshots that scope's keys; once the scope restores+// process.env, the snapshot is stale and must not reach later tests or files.+let baselineEnv: Record<string, string | undefined> | undefined;+function legacyGatewayConfig() {+ baselineEnv = { ...process.env };return {embedding_model: LEGACY_CONFIG.embedding_model,embedding_dimensions: LEGACY_CONFIG.embedding_dimensions,- env: { ...process.env },+ env: baselineEnv,};}+function staleBaseline(): boolean {+ const live = requireConfig().env;+ if (live !== baselineEnv) return false;+ return [...new Set([...Object.keys(live), ...Object.keys(process.env)])].some((k) => live[k] !== process.env[k]);+}+function applyLegacy() {configureGateway(legacyGatewayConfig());}@@ -56,6 +69,7 @@ beforeEach(() => {// own beforeAll get to keep it — we only restore the legacy// default when the slot is empty.getEmbeddingDimensions();+ if (staleBaseline()) applyLegacy();} catch {applyLegacy();}