Files
Huang-404-Q 34135632fc fix(tests): stop ANTHROPIC_BASE_URL from failing the Anthropic suites
A developer shell with ANTHROPIC_BASE_URL set reroutes the effective endpoint
away from official, switching off eager tool-input streaming, long cache
retention, the Cowork TLS profile, the Claude Code session header and priority
service tier. 14 tests across 6 files assert those behaviors and fail on a
clean checkout.

Add withOfficialAnthropicEndpoint(), a beforeEach/afterEach pair that removes
the variable and restores it, and call it from the six affected files.
2026-08-17 14:35:32 +08:00

28 lines
1008 B
TypeScript

import { afterEach, beforeEach } from "bun:test";
/**
* Neutralize `ANTHROPIC_BASE_URL` for the calling test file.
*
* The variable reroutes the effective Anthropic endpoint, and every
* "official endpoint" behavior — eager tool-input streaming, long cache
* retention, the Cowork TLS profile, the Claude Code session header — switches
* off once it points elsewhere. A contributor running a gateway, or running the
* suite from inside another agent, otherwise sees these tests fail on a clean
* checkout. Tests that exercise gateway routing set the variable explicitly
* with `withEnv` inside the test body, which still wins over this reset.
*/
export function withOfficialAnthropicEndpoint(): void {
let previous: string | undefined;
beforeEach(() => {
previous = Bun.env.ANTHROPIC_BASE_URL;
delete Bun.env.ANTHROPIC_BASE_URL;
});
afterEach(() => {
if (previous === undefined) {
delete Bun.env.ANTHROPIC_BASE_URL;
} else {
Bun.env.ANTHROPIC_BASE_URL = previous;
}
});
}