test(claude-code): isolate ambient Anthropic model env
This commit is contained in:
@@ -17,7 +17,7 @@ import type {
|
|||||||
SDKSystemMessage,
|
SDKSystemMessage,
|
||||||
} from '@anthropic-ai/claude-agent-sdk'
|
} from '@anthropic-ai/claude-agent-sdk'
|
||||||
import { Context } from '@deepseek-ai/cordis'
|
import { Context } from '@deepseek-ai/cordis'
|
||||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from 'vitest'
|
||||||
import type { Agent } from '@deepseek-ai/dsh-agent'
|
import type { Agent } from '@deepseek-ai/dsh-agent'
|
||||||
import SubagentRuntime from '@deepseek-ai/dsh-subagent'
|
import SubagentRuntime from '@deepseek-ai/dsh-subagent'
|
||||||
import type { SubprocessHandle, SubprocessSpawnSpec } from '@deepseek-ai/dsh-subprocess'
|
import type { SubprocessHandle, SubprocessSpawnSpec } from '@deepseek-ai/dsh-subprocess'
|
||||||
@@ -87,6 +87,22 @@ const roots: string[] = []
|
|||||||
const fixtures: MessagesFixture[] = []
|
const fixtures: MessagesFixture[] = []
|
||||||
const contexts: Context[] = []
|
const contexts: Context[] = []
|
||||||
|
|
||||||
|
// Ambient Anthropic model env leaks into the real CLI and overrides the
|
||||||
|
// fixture settings.json on developer machines; delete it for this file and
|
||||||
|
// restore it after, like the workspace-context USERPROFILE isolation.
|
||||||
|
const ambientAnthropicModel = process.env.ANTHROPIC_MODEL
|
||||||
|
const ambientAnthropicSmallFastModel = process.env.ANTHROPIC_SMALL_FAST_MODEL
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
delete process.env.ANTHROPIC_MODEL
|
||||||
|
delete process.env.ANTHROPIC_SMALL_FAST_MODEL
|
||||||
|
})
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
if (ambientAnthropicModel !== undefined) process.env.ANTHROPIC_MODEL = ambientAnthropicModel
|
||||||
|
if (ambientAnthropicSmallFastModel !== undefined) process.env.ANTHROPIC_SMALL_FAST_MODEL = ambientAnthropicSmallFastModel
|
||||||
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
await Promise.all(contexts.splice(0).map(ctx => ctx.fiber.dispose()))
|
await Promise.all(contexts.splice(0).map(ctx => ctx.fiber.dispose()))
|
||||||
await Promise.all(fixtures.splice(0).map(fixture => fixture.close()))
|
await Promise.all(fixtures.splice(0).map(fixture => fixture.close()))
|
||||||
|
|||||||
Reference in New Issue
Block a user