Compare commits

...
Author SHA1 Message Date
Garry TanandClaude Fable 5 8cf817865d fix(test): reset AI gateway after adaptive-embed-batch suite — cross-file config leak
The file's final test configures the gateway with a remote provider and a
fake key, and its afterEach only clears the mock transport. With no
afterAll, the poisoned global config survives the file boundary; the next
test file in the shard that triggers an embed makes a real HTTP call and
fails. Surfaced on master when #3022's new test file reshuffled shard
composition (shard 6: synthesize-concepts-progress failed twice with a
live Google embed rejection). The legacy-embedding preload can't catch
this: it only re-applies defaults when the gateway slot is empty.

One-line root-cause fix at the leaker. A repo-wide guard for the class
(~70 files call configureGateway without a final reset) is filed as a
follow-up.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-21 11:55:00 -07:00
+10 -1
View File
@@ -28,7 +28,7 @@
* (excluding the OpenAI canonical fast-path recipe).
*/
import { afterEach, beforeEach, describe, expect, mock, test } from 'bun:test';
import { afterAll, afterEach, beforeEach, describe, expect, mock, test } from 'bun:test';
import {
configureGateway,
resetGateway,
@@ -40,6 +40,15 @@ import {
} from '../../src/core/ai/gateway.ts';
import { AIConfigError, AITransientError } from '../../src/core/ai/errors.ts';
// The last test in this file leaves the gateway configured with a remote
// provider + fake key and a REAL embed transport. Without a final reset,
// that config leaks into whichever test file the shard runs next — the
// first downstream embed then makes a live HTTP call (broke master shard 6
// when #3022's new test file reshuffled shard composition). The bunfig
// legacy-embedding preload only re-applies its default when the gateway is
// UNCONFIGURED, so a configured-but-stale slot survives file boundaries.
afterAll(() => resetGateway());
// --------- Test helpers ---------
/**