test(e2e): isolate ANTHROPIC_*MODEL env from the models-API fixtures

The models API derives its model list from ANTHROPIC_MODEL and the
ANTHROPIC_DEFAULT_{HAIKU,SONNET,OPUS}_MODEL env vars. A developer who exports
these for a custom provider (e.g. MiniMax) leaked them into the no-provider
fixture: the four collapsed to one model, the default model became the
custom one, and switched-model names fell back to the raw id — failing five
"available models" / "default model" assertions on that machine while passing
on clean CI.

Clear those four vars in the e2e setup and restore them in teardown, matching
the existing CLAUDE_CONFIG_DIR / CLAUDE_CLI_PATH isolation.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
程序员阿江(Relakkes) 2026-06-04 20:12:54 +08:00
parent 837337901d
commit 5688fe10a7
2 changed files with 38 additions and 0 deletions

View File

@ -20,7 +20,25 @@ const originalCliPath = process.env.CLAUDE_CLI_PATH
const originalDisableTerminalShellEnv = process.env.CC_HAHA_DISABLE_TERMINAL_SHELL_ENV
const mockSdkCliPath = fileURLToPath(new URL('../fixtures/mock-sdk-cli.ts', import.meta.url))
// The models API derives its model list from these env vars (see
// src/server/api/models.ts getEnvConfiguredAnthropicModels). A developer who
// exports them for a custom provider would otherwise leak them into the
// no-provider fixture and break the default-model assertions. Isolate them.
const MODEL_ENV_KEYS = [
'ANTHROPIC_MODEL',
'ANTHROPIC_DEFAULT_HAIKU_MODEL',
'ANTHROPIC_DEFAULT_SONNET_MODEL',
'ANTHROPIC_DEFAULT_OPUS_MODEL',
] as const
const originalModelEnv = Object.fromEntries(
MODEL_ENV_KEYS.map((key) => [key, process.env[key]]),
) as Record<(typeof MODEL_ENV_KEYS)[number], string | undefined>
function restoreEnv() {
for (const key of MODEL_ENV_KEYS) {
if (originalModelEnv[key] !== undefined) process.env[key] = originalModelEnv[key]
else delete process.env[key]
}
if (originalConfigDir !== undefined) {
process.env.CLAUDE_CONFIG_DIR = originalConfigDir
} else {
@ -47,6 +65,7 @@ async function startTestServer() {
process.env.CLAUDE_CONFIG_DIR = tmpDir
process.env.CLAUDE_CLI_PATH = mockSdkCliPath
process.env.CC_HAHA_DISABLE_TERMINAL_SHELL_ENV = '1'
for (const key of MODEL_ENV_KEYS) delete process.env[key]
await fs.mkdir(path.join(tmpDir, 'projects'), { recursive: true })
await fs.mkdir(path.join(tmpDir, 'agents'), { recursive: true })

View File

@ -18,7 +18,25 @@ const originalCliPath = process.env.CLAUDE_CLI_PATH
const originalDisableTerminalShellEnv = process.env.CC_HAHA_DISABLE_TERMINAL_SHELL_ENV
const mockSdkCliPath = fileURLToPath(new URL('../fixtures/mock-sdk-cli.ts', import.meta.url))
// The models API derives its model list from these env vars (see
// src/server/api/models.ts getEnvConfiguredAnthropicModels). A developer who
// exports them for a custom provider would otherwise leak them into the
// no-provider fixture and break the default-model assertions. Isolate them.
const MODEL_ENV_KEYS = [
'ANTHROPIC_MODEL',
'ANTHROPIC_DEFAULT_HAIKU_MODEL',
'ANTHROPIC_DEFAULT_SONNET_MODEL',
'ANTHROPIC_DEFAULT_OPUS_MODEL',
] as const
const originalModelEnv = Object.fromEntries(
MODEL_ENV_KEYS.map((key) => [key, process.env[key]]),
) as Record<(typeof MODEL_ENV_KEYS)[number], string | undefined>
function restoreEnv() {
for (const key of MODEL_ENV_KEYS) {
if (originalModelEnv[key] !== undefined) process.env[key] = originalModelEnv[key]
else delete process.env[key]
}
if (originalConfigDir !== undefined) {
process.env.CLAUDE_CONFIG_DIR = originalConfigDir
} else {
@ -46,6 +64,7 @@ async function startTestServer() {
process.env.CLAUDE_CONFIG_DIR = tmpDir
process.env.CLAUDE_CLI_PATH = mockSdkCliPath
process.env.CC_HAHA_DISABLE_TERMINAL_SHELL_ENV = '1'
for (const key of MODEL_ENV_KEYS) delete process.env[key]
// Create required directories
await fs.mkdir(path.join(tmpDir, 'projects'), { recursive: true })