Compare commits
4 Commits
main
...
fix/provid
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b5dbb71a44 | ||
|
|
b2cabdd950 | ||
|
|
139610950c | ||
|
|
65dd19cf87 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -10,3 +10,4 @@ GEMINI.md
|
|||||||
package-lock.json
|
package-lock.json
|
||||||
/.claude
|
/.claude
|
||||||
coverage/
|
coverage/
|
||||||
|
.worktrees/
|
||||||
|
|||||||
@@ -238,6 +238,7 @@ import { usePromptsFromClaudeInChrome } from 'src/hooks/usePromptsFromClaudeInCh
|
|||||||
import { getTipToShowOnSpinner, recordShownTip } from 'src/services/tips/tipScheduler.js';
|
import { getTipToShowOnSpinner, recordShownTip } from 'src/services/tips/tipScheduler.js';
|
||||||
import type { Theme } from 'src/utils/theme.js';
|
import type { Theme } from 'src/utils/theme.js';
|
||||||
import { isPromptTypingSuppressionActive } from './replInputSuppression.js';
|
import { isPromptTypingSuppressionActive } from './replInputSuppression.js';
|
||||||
|
import { shouldStartStartupChecks } from './replStartupGates.js';
|
||||||
import { checkAndDisableBypassPermissionsIfNeeded, checkAndDisableAutoModeIfNeeded, useKickOffCheckAndDisableBypassPermissionsIfNeeded, useKickOffCheckAndDisableAutoModeIfNeeded } from 'src/utils/permissions/bypassPermissionsKillswitch.js';
|
import { checkAndDisableBypassPermissionsIfNeeded, checkAndDisableAutoModeIfNeeded, useKickOffCheckAndDisableBypassPermissionsIfNeeded, useKickOffCheckAndDisableAutoModeIfNeeded } from 'src/utils/permissions/bypassPermissionsKillswitch.js';
|
||||||
import { SandboxManager } from 'src/utils/sandbox/sandbox-adapter.js';
|
import { SandboxManager } from 'src/utils/sandbox/sandbox-adapter.js';
|
||||||
import { SANDBOX_NETWORK_ACCESS_TOOL_NAME } from 'src/cli/structuredIO.js';
|
import { SANDBOX_NETWORK_ACCESS_TOOL_NAME } from 'src/cli/structuredIO.js';
|
||||||
@@ -784,19 +785,6 @@ export function REPL({
|
|||||||
});
|
});
|
||||||
const tasksV2 = useTasksV2WithCollapseEffect();
|
const tasksV2 = useTasksV2WithCollapseEffect();
|
||||||
|
|
||||||
// Start background plugin installations
|
|
||||||
|
|
||||||
// SECURITY: This code is guaranteed to run ONLY after the "trust this folder" dialog
|
|
||||||
// has been confirmed by the user. The trust dialog is shown in cli.tsx (line ~387)
|
|
||||||
// before the REPL component is rendered. The dialog blocks execution until the user
|
|
||||||
// accepts, and only then is the REPL component mounted and this effect runs.
|
|
||||||
// This ensures that plugin installations from repository and user settings only
|
|
||||||
// happen after explicit user consent to trust the current working directory.
|
|
||||||
useEffect(() => {
|
|
||||||
if (isRemoteSession) return;
|
|
||||||
void performStartupChecks(setAppState);
|
|
||||||
}, [setAppState, isRemoteSession]);
|
|
||||||
|
|
||||||
// Allow Claude in Chrome MCP to send prompts through MCP notifications
|
// Allow Claude in Chrome MCP to send prompts through MCP notifications
|
||||||
// and sync permission mode changes to the Chrome extension
|
// and sync permission mode changes to the Chrome extension
|
||||||
usePromptsFromClaudeInChrome(isRemoteSession ? EMPTY_MCP_CLIENTS : mcpClients, toolPermissionContext.mode);
|
usePromptsFromClaudeInChrome(isRemoteSession ? EMPTY_MCP_CLIENTS : mcpClients, toolPermissionContext.mode);
|
||||||
@@ -1337,6 +1325,7 @@ export function REPL({
|
|||||||
const [inputValue, setInputValueRaw] = useState(() => consumeEarlyInput());
|
const [inputValue, setInputValueRaw] = useState(() => consumeEarlyInput());
|
||||||
const inputValueRef = useRef(inputValue);
|
const inputValueRef = useRef(inputValue);
|
||||||
inputValueRef.current = inputValue;
|
inputValueRef.current = inputValue;
|
||||||
|
const startupChecksStartedRef = useRef(false);
|
||||||
const promptTypingSuppressionActive = isPromptTypingSuppressionActive(isPromptInputActive, inputValue);
|
const promptTypingSuppressionActive = isPromptTypingSuppressionActive(isPromptInputActive, inputValue);
|
||||||
const insertTextRef = useRef<{
|
const insertTextRef = useRef<{
|
||||||
insert: (text: string) => void;
|
insert: (text: string) => void;
|
||||||
@@ -1344,6 +1333,24 @@ export function REPL({
|
|||||||
cursorOffset: number;
|
cursorOffset: number;
|
||||||
} | null>(null);
|
} | null>(null);
|
||||||
|
|
||||||
|
// Start background plugin installations after the initial input window is idle.
|
||||||
|
// SECURITY: This still runs only after the "trust this folder" dialog has been
|
||||||
|
// confirmed because the REPL is not mounted until that dialog completes.
|
||||||
|
useEffect(() => {
|
||||||
|
if (
|
||||||
|
!shouldStartStartupChecks({
|
||||||
|
isRemoteSession,
|
||||||
|
promptTypingSuppressionActive,
|
||||||
|
startupChecksStarted: startupChecksStartedRef.current,
|
||||||
|
})
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
startupChecksStartedRef.current = true;
|
||||||
|
void performStartupChecks(setAppState);
|
||||||
|
}, [isRemoteSession, promptTypingSuppressionActive, setAppState]);
|
||||||
|
|
||||||
// Wrap setInputValue to co-locate suppression state updates.
|
// Wrap setInputValue to co-locate suppression state updates.
|
||||||
// Both setState calls happen in the same synchronous context so React
|
// Both setState calls happen in the same synchronous context so React
|
||||||
// batches them into a single render, eliminating the extra render that
|
// batches them into a single render, eliminating the extra render that
|
||||||
|
|||||||
44
src/screens/replStartupGates.test.ts
Normal file
44
src/screens/replStartupGates.test.ts
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
import { describe, expect, test } from 'bun:test'
|
||||||
|
import { shouldStartStartupChecks } from './replStartupGates.js'
|
||||||
|
|
||||||
|
describe('shouldStartStartupChecks', () => {
|
||||||
|
test('returns false for remote sessions', () => {
|
||||||
|
expect(
|
||||||
|
shouldStartStartupChecks({
|
||||||
|
isRemoteSession: true,
|
||||||
|
promptTypingSuppressionActive: false,
|
||||||
|
startupChecksStarted: false,
|
||||||
|
}),
|
||||||
|
).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('returns false while prompt typing suppression is active', () => {
|
||||||
|
expect(
|
||||||
|
shouldStartStartupChecks({
|
||||||
|
isRemoteSession: false,
|
||||||
|
promptTypingSuppressionActive: true,
|
||||||
|
startupChecksStarted: false,
|
||||||
|
}),
|
||||||
|
).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('returns true once local startup is idle and checks have not started', () => {
|
||||||
|
expect(
|
||||||
|
shouldStartStartupChecks({
|
||||||
|
isRemoteSession: false,
|
||||||
|
promptTypingSuppressionActive: false,
|
||||||
|
startupChecksStarted: false,
|
||||||
|
}),
|
||||||
|
).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('returns false after startup checks have already started', () => {
|
||||||
|
expect(
|
||||||
|
shouldStartStartupChecks({
|
||||||
|
isRemoteSession: false,
|
||||||
|
promptTypingSuppressionActive: false,
|
||||||
|
startupChecksStarted: true,
|
||||||
|
}),
|
||||||
|
).toBe(false)
|
||||||
|
})
|
||||||
|
})
|
||||||
11
src/screens/replStartupGates.ts
Normal file
11
src/screens/replStartupGates.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
export function shouldStartStartupChecks(options: {
|
||||||
|
isRemoteSession: boolean
|
||||||
|
promptTypingSuppressionActive: boolean
|
||||||
|
startupChecksStarted: boolean
|
||||||
|
}): boolean {
|
||||||
|
return (
|
||||||
|
!options.isRemoteSession &&
|
||||||
|
!options.promptTypingSuppressionActive &&
|
||||||
|
!options.startupChecksStarted
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
} from './managedEnvConstants.js'
|
} from './managedEnvConstants.js'
|
||||||
import { clearMTLSCache } from './mtls.js'
|
import { clearMTLSCache } from './mtls.js'
|
||||||
import { clearProxyCache, configureGlobalAgents } from './proxy.js'
|
import { clearProxyCache, configureGlobalAgents } from './proxy.js'
|
||||||
|
import { filterSettingsEnvForExplicitProvider } from './providerEnvSelection.js'
|
||||||
import { applyActiveProviderProfileFromConfig } from './providerProfiles.js'
|
import { applyActiveProviderProfileFromConfig } from './providerProfiles.js'
|
||||||
import { isSettingSourceEnabled } from './settings/constants.js'
|
import { isSettingSourceEnabled } from './settings/constants.js'
|
||||||
import {
|
import {
|
||||||
@@ -87,7 +88,9 @@ function filterSettingsEnv(
|
|||||||
env: Record<string, string> | undefined,
|
env: Record<string, string> | undefined,
|
||||||
): Record<string, string> {
|
): Record<string, string> {
|
||||||
return withoutCcdSpawnEnvKeys(
|
return withoutCcdSpawnEnvKeys(
|
||||||
withoutHostManagedProviderVars(withoutSSHTunnelVars(env)),
|
filterSettingsEnvForExplicitProvider(
|
||||||
|
withoutHostManagedProviderVars(withoutSSHTunnelVars(env)),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
116
src/utils/providerEnvSelection.test.ts
Normal file
116
src/utils/providerEnvSelection.test.ts
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
import { afterEach, beforeEach, describe, expect, test } from 'bun:test'
|
||||||
|
import { filterSettingsEnvForExplicitProvider } from './providerEnvSelection.js'
|
||||||
|
|
||||||
|
const originalEnv = { ...process.env }
|
||||||
|
|
||||||
|
const RESET_KEYS = [
|
||||||
|
'CLAUDE_CODE_EXPLICIT_PROVIDER',
|
||||||
|
'CLAUDE_CODE_USE_OPENAI',
|
||||||
|
'CLAUDE_CODE_USE_GEMINI',
|
||||||
|
'CLAUDE_CODE_USE_GITHUB',
|
||||||
|
'CLAUDE_CODE_USE_BEDROCK',
|
||||||
|
'CLAUDE_CODE_USE_VERTEX',
|
||||||
|
'CLAUDE_CODE_USE_FOUNDRY',
|
||||||
|
] as const
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
for (const key of RESET_KEYS) {
|
||||||
|
delete process.env[key]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
for (const key of RESET_KEYS) {
|
||||||
|
if (originalEnv[key] === undefined) delete process.env[key]
|
||||||
|
else process.env[key] = originalEnv[key]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('filterSettingsEnvForExplicitProvider', () => {
|
||||||
|
test('does not treat plain provider flags as an explicit CLI override', () => {
|
||||||
|
process.env.CLAUDE_CODE_USE_GITHUB = '1'
|
||||||
|
|
||||||
|
expect(
|
||||||
|
filterSettingsEnvForExplicitProvider({
|
||||||
|
CLAUDE_CODE_USE_OPENAI: '1',
|
||||||
|
OPENAI_MODEL: 'gpt-4o',
|
||||||
|
OTHER: 'keep-me',
|
||||||
|
}),
|
||||||
|
).toEqual({
|
||||||
|
CLAUDE_CODE_USE_OPENAI: '1',
|
||||||
|
OPENAI_MODEL: 'gpt-4o',
|
||||||
|
OTHER: 'keep-me',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
test('strips settings-sourced provider flags when CLI provider is explicit', () => {
|
||||||
|
process.env.CLAUDE_CODE_EXPLICIT_PROVIDER = 'openai'
|
||||||
|
|
||||||
|
expect(
|
||||||
|
filterSettingsEnvForExplicitProvider({
|
||||||
|
CLAUDE_CODE_USE_GITHUB: '1',
|
||||||
|
CLAUDE_CODE_USE_OPENAI: '1',
|
||||||
|
OTHER: 'keep-me',
|
||||||
|
}),
|
||||||
|
).toEqual({ OTHER: 'keep-me' })
|
||||||
|
})
|
||||||
|
|
||||||
|
test('strips a stale GitHub model when explicit provider is not github', () => {
|
||||||
|
process.env.CLAUDE_CODE_EXPLICIT_PROVIDER = 'openai'
|
||||||
|
|
||||||
|
expect(
|
||||||
|
filterSettingsEnvForExplicitProvider({
|
||||||
|
OPENAI_MODEL: 'github:copilot',
|
||||||
|
OTHER: 'keep-me',
|
||||||
|
}),
|
||||||
|
).toEqual({ OTHER: 'keep-me' })
|
||||||
|
})
|
||||||
|
|
||||||
|
test('keeps a normal OpenAI model when explicit provider is openai', () => {
|
||||||
|
process.env.CLAUDE_CODE_EXPLICIT_PROVIDER = 'openai'
|
||||||
|
|
||||||
|
expect(
|
||||||
|
filterSettingsEnvForExplicitProvider({
|
||||||
|
OPENAI_MODEL: 'gpt-4o',
|
||||||
|
OTHER: 'keep-me',
|
||||||
|
}),
|
||||||
|
).toEqual({ OPENAI_MODEL: 'gpt-4o', OTHER: 'keep-me' })
|
||||||
|
})
|
||||||
|
|
||||||
|
test('strips a non-GitHub OpenAI model when explicit provider is github', () => {
|
||||||
|
process.env.CLAUDE_CODE_EXPLICIT_PROVIDER = 'github'
|
||||||
|
|
||||||
|
expect(
|
||||||
|
filterSettingsEnvForExplicitProvider({
|
||||||
|
OPENAI_MODEL: 'gpt-4o',
|
||||||
|
OTHER: 'keep-me',
|
||||||
|
}),
|
||||||
|
).toEqual({ OTHER: 'keep-me' })
|
||||||
|
})
|
||||||
|
|
||||||
|
test('preserves anthropic startup intent by stripping stale GitHub/OpenAI settings', () => {
|
||||||
|
process.env.CLAUDE_CODE_EXPLICIT_PROVIDER = 'anthropic'
|
||||||
|
|
||||||
|
expect(
|
||||||
|
filterSettingsEnvForExplicitProvider({
|
||||||
|
CLAUDE_CODE_USE_GITHUB: '1',
|
||||||
|
CLAUDE_CODE_USE_OPENAI: '1',
|
||||||
|
OPENAI_MODEL: 'github:copilot',
|
||||||
|
OTHER: 'keep-me',
|
||||||
|
}),
|
||||||
|
).toEqual({ OTHER: 'keep-me' })
|
||||||
|
})
|
||||||
|
|
||||||
|
test('preserves explicit ollama startup intent by stripping OpenAI routing settings', () => {
|
||||||
|
process.env.CLAUDE_CODE_EXPLICIT_PROVIDER = 'ollama'
|
||||||
|
|
||||||
|
expect(
|
||||||
|
filterSettingsEnvForExplicitProvider({
|
||||||
|
OPENAI_BASE_URL: 'https://api.openai.com/v1',
|
||||||
|
OPENAI_MODEL: 'gpt-4o',
|
||||||
|
OPENAI_API_KEY: 'sk-test',
|
||||||
|
OTHER: 'keep-me',
|
||||||
|
}),
|
||||||
|
).toEqual({ OTHER: 'keep-me' })
|
||||||
|
})
|
||||||
|
})
|
||||||
63
src/utils/providerEnvSelection.ts
Normal file
63
src/utils/providerEnvSelection.ts
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
export const EXPLICIT_PROVIDER_ENV_VAR = 'CLAUDE_CODE_EXPLICIT_PROVIDER'
|
||||||
|
|
||||||
|
const PROVIDER_FLAG_KEYS = [
|
||||||
|
'CLAUDE_CODE_USE_OPENAI',
|
||||||
|
'CLAUDE_CODE_USE_GEMINI',
|
||||||
|
'CLAUDE_CODE_USE_GITHUB',
|
||||||
|
'CLAUDE_CODE_USE_BEDROCK',
|
||||||
|
'CLAUDE_CODE_USE_VERTEX',
|
||||||
|
'CLAUDE_CODE_USE_FOUNDRY',
|
||||||
|
] as const
|
||||||
|
|
||||||
|
export function clearProviderSelectionFlags(
|
||||||
|
env: NodeJS.ProcessEnv = process.env,
|
||||||
|
): void {
|
||||||
|
for (const key of PROVIDER_FLAG_KEYS) {
|
||||||
|
delete env[key]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getExplicitProvider(processEnv: NodeJS.ProcessEnv): string | undefined {
|
||||||
|
return processEnv[EXPLICIT_PROVIDER_ENV_VAR]?.trim() || undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
function isGithubModel(model: string | undefined): boolean {
|
||||||
|
return (model ?? '').trim().toLowerCase().startsWith('github:')
|
||||||
|
}
|
||||||
|
|
||||||
|
export function filterSettingsEnvForExplicitProvider(
|
||||||
|
env: Record<string, string> | undefined,
|
||||||
|
processEnv: NodeJS.ProcessEnv = process.env,
|
||||||
|
): Record<string, string> {
|
||||||
|
if (!env) return {}
|
||||||
|
|
||||||
|
const explicitProvider = getExplicitProvider(processEnv)
|
||||||
|
if (!explicitProvider) {
|
||||||
|
return env
|
||||||
|
}
|
||||||
|
|
||||||
|
const filtered = { ...env }
|
||||||
|
for (const key of PROVIDER_FLAG_KEYS) {
|
||||||
|
delete filtered[key]
|
||||||
|
}
|
||||||
|
|
||||||
|
if (explicitProvider === 'ollama') {
|
||||||
|
delete filtered.OPENAI_BASE_URL
|
||||||
|
delete filtered.OPENAI_MODEL
|
||||||
|
delete filtered.OPENAI_API_KEY
|
||||||
|
return filtered
|
||||||
|
}
|
||||||
|
|
||||||
|
if (explicitProvider === 'github') {
|
||||||
|
if (!isGithubModel(filtered.OPENAI_MODEL)) {
|
||||||
|
delete filtered.OPENAI_MODEL
|
||||||
|
}
|
||||||
|
return filtered
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isGithubModel(filtered.OPENAI_MODEL)) {
|
||||||
|
delete filtered.OPENAI_MODEL
|
||||||
|
}
|
||||||
|
|
||||||
|
return filtered
|
||||||
|
}
|
||||||
@@ -9,11 +9,13 @@ import {
|
|||||||
const originalEnv = { ...process.env }
|
const originalEnv = { ...process.env }
|
||||||
|
|
||||||
const RESET_KEYS = [
|
const RESET_KEYS = [
|
||||||
|
'CLAUDE_CODE_EXPLICIT_PROVIDER',
|
||||||
'CLAUDE_CODE_USE_OPENAI',
|
'CLAUDE_CODE_USE_OPENAI',
|
||||||
'CLAUDE_CODE_USE_GEMINI',
|
'CLAUDE_CODE_USE_GEMINI',
|
||||||
'CLAUDE_CODE_USE_GITHUB',
|
'CLAUDE_CODE_USE_GITHUB',
|
||||||
'CLAUDE_CODE_USE_BEDROCK',
|
'CLAUDE_CODE_USE_BEDROCK',
|
||||||
'CLAUDE_CODE_USE_VERTEX',
|
'CLAUDE_CODE_USE_VERTEX',
|
||||||
|
'CLAUDE_CODE_USE_FOUNDRY',
|
||||||
'OPENAI_BASE_URL',
|
'OPENAI_BASE_URL',
|
||||||
'OPENAI_API_KEY',
|
'OPENAI_API_KEY',
|
||||||
'OPENAI_MODEL',
|
'OPENAI_MODEL',
|
||||||
@@ -83,6 +85,16 @@ describe('applyProviderFlag - openai', () => {
|
|||||||
applyProviderFlag('openai', ['--model', 'gpt-4o'])
|
applyProviderFlag('openai', ['--model', 'gpt-4o'])
|
||||||
expect(process.env.OPENAI_MODEL).toBe('gpt-4o')
|
expect(process.env.OPENAI_MODEL).toBe('gpt-4o')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('clears a previously persisted GitHub flag', () => {
|
||||||
|
process.env.CLAUDE_CODE_USE_GITHUB = '1'
|
||||||
|
|
||||||
|
const result = applyProviderFlag('openai', [])
|
||||||
|
|
||||||
|
expect(result.error).toBeUndefined()
|
||||||
|
expect(process.env.CLAUDE_CODE_USE_GITHUB).toBeUndefined()
|
||||||
|
expect(process.env.CLAUDE_CODE_USE_OPENAI).toBe('1')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('applyProviderFlag - gemini', () => {
|
describe('applyProviderFlag - gemini', () => {
|
||||||
@@ -104,6 +116,16 @@ describe('applyProviderFlag - github', () => {
|
|||||||
expect(result.error).toBeUndefined()
|
expect(result.error).toBeUndefined()
|
||||||
expect(process.env.CLAUDE_CODE_USE_GITHUB).toBe('1')
|
expect(process.env.CLAUDE_CODE_USE_GITHUB).toBe('1')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('clears a previously set OpenAI flag', () => {
|
||||||
|
process.env.CLAUDE_CODE_USE_OPENAI = '1'
|
||||||
|
|
||||||
|
const result = applyProviderFlag('github', [])
|
||||||
|
|
||||||
|
expect(result.error).toBeUndefined()
|
||||||
|
expect(process.env.CLAUDE_CODE_USE_OPENAI).toBeUndefined()
|
||||||
|
expect(process.env.CLAUDE_CODE_USE_GITHUB).toBe('1')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('applyProviderFlag - bedrock', () => {
|
describe('applyProviderFlag - bedrock', () => {
|
||||||
@@ -151,6 +173,19 @@ describe('applyProviderFlag - invalid provider', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('applyProviderFlag - anthropic', () => {
|
||||||
|
test('clears third-party provider flags', () => {
|
||||||
|
process.env.CLAUDE_CODE_USE_GITHUB = '1'
|
||||||
|
process.env.CLAUDE_CODE_USE_OPENAI = '1'
|
||||||
|
|
||||||
|
const result = applyProviderFlag('anthropic', [])
|
||||||
|
|
||||||
|
expect(result.error).toBeUndefined()
|
||||||
|
expect(process.env.CLAUDE_CODE_USE_GITHUB).toBeUndefined()
|
||||||
|
expect(process.env.CLAUDE_CODE_USE_OPENAI).toBeUndefined()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('applyProviderFlagFromArgs', () => {
|
describe('applyProviderFlagFromArgs', () => {
|
||||||
test('applies ollama provider and model from argv in one step', () => {
|
test('applies ollama provider and model from argv in one step', () => {
|
||||||
const result = applyProviderFlagFromArgs([
|
const result = applyProviderFlagFromArgs([
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
import {
|
||||||
|
clearProviderSelectionFlags,
|
||||||
|
EXPLICIT_PROVIDER_ENV_VAR,
|
||||||
|
} from './providerEnvSelection.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* --provider CLI flag support.
|
* --provider CLI flag support.
|
||||||
*
|
*
|
||||||
@@ -77,6 +82,9 @@ export function applyProviderFlag(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clearProviderSelectionFlags()
|
||||||
|
process.env[EXPLICIT_PROVIDER_ENV_VAR] = provider
|
||||||
|
|
||||||
const model = parseModelFlag(args)
|
const model = parseModelFlag(args)
|
||||||
|
|
||||||
switch (provider as ProviderFlagName) {
|
switch (provider as ProviderFlagName) {
|
||||||
|
|||||||
@@ -485,6 +485,26 @@ test('buildStartupEnvFromProfile leaves explicit provider selections untouched',
|
|||||||
assert.equal(env.OPENAI_API_KEY, undefined)
|
assert.equal(env.OPENAI_API_KEY, undefined)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('buildStartupEnvFromProfile preserves explicit anthropic startup selection', async () => {
|
||||||
|
const processEnv = {
|
||||||
|
CLAUDE_CODE_EXPLICIT_PROVIDER: 'anthropic',
|
||||||
|
}
|
||||||
|
|
||||||
|
const env = await buildStartupEnvFromProfile({
|
||||||
|
persisted: profile('openai', {
|
||||||
|
CLAUDE_CODE_USE_GITHUB: '1',
|
||||||
|
OPENAI_MODEL: 'github:copilot',
|
||||||
|
}),
|
||||||
|
processEnv,
|
||||||
|
})
|
||||||
|
|
||||||
|
assert.equal(env, processEnv)
|
||||||
|
assert.equal(env.CLAUDE_CODE_EXPLICIT_PROVIDER, 'anthropic')
|
||||||
|
assert.equal(env.CLAUDE_CODE_USE_OPENAI, undefined)
|
||||||
|
assert.equal(env.CLAUDE_CODE_USE_GITHUB, undefined)
|
||||||
|
assert.equal(env.OPENAI_MODEL, undefined)
|
||||||
|
})
|
||||||
|
|
||||||
test('buildStartupEnvFromProfile leaves profile-managed env untouched', async () => {
|
test('buildStartupEnvFromProfile leaves profile-managed env untouched', async () => {
|
||||||
const processEnv = {
|
const processEnv = {
|
||||||
CLAUDE_CODE_PROVIDER_PROFILE_ENV_APPLIED: '1',
|
CLAUDE_CODE_PROVIDER_PROFILE_ENV_APPLIED: '1',
|
||||||
|
|||||||
@@ -412,6 +412,10 @@ export function hasExplicitProviderSelection(
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (processEnv.CLAUDE_CODE_EXPLICIT_PROVIDER?.trim()) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
processEnv.CLAUDE_CODE_USE_OPENAI !== undefined ||
|
processEnv.CLAUDE_CODE_USE_OPENAI !== undefined ||
|
||||||
processEnv.CLAUDE_CODE_USE_GITHUB !== undefined ||
|
processEnv.CLAUDE_CODE_USE_GITHUB !== undefined ||
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ async function importFreshProvidersModule() {
|
|||||||
const originalEnv = { ...process.env }
|
const originalEnv = { ...process.env }
|
||||||
|
|
||||||
const RESTORED_KEYS = [
|
const RESTORED_KEYS = [
|
||||||
|
'CLAUDE_CODE_EXPLICIT_PROVIDER',
|
||||||
'CLAUDE_CODE_PROVIDER_PROFILE_ENV_APPLIED',
|
'CLAUDE_CODE_PROVIDER_PROFILE_ENV_APPLIED',
|
||||||
'CLAUDE_CODE_PROVIDER_PROFILE_ENV_APPLIED_ID',
|
'CLAUDE_CODE_PROVIDER_PROFILE_ENV_APPLIED_ID',
|
||||||
'CLAUDE_CODE_USE_OPENAI',
|
'CLAUDE_CODE_USE_OPENAI',
|
||||||
@@ -142,6 +143,29 @@ describe('applyProviderProfileToProcessEnv', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('applyActiveProviderProfileFromConfig', () => {
|
describe('applyActiveProviderProfileFromConfig', () => {
|
||||||
|
test('does not override explicit anthropic startup selection', async () => {
|
||||||
|
const { applyActiveProviderProfileFromConfig } =
|
||||||
|
await importFreshProviderProfileModules()
|
||||||
|
process.env.CLAUDE_CODE_EXPLICIT_PROVIDER = 'anthropic'
|
||||||
|
|
||||||
|
const applied = applyActiveProviderProfileFromConfig({
|
||||||
|
providerProfiles: [
|
||||||
|
buildProfile({
|
||||||
|
id: 'saved_github',
|
||||||
|
baseUrl: 'https://api.githubcopilot.com',
|
||||||
|
model: 'github:copilot',
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
activeProviderProfileId: 'saved_github',
|
||||||
|
} as any)
|
||||||
|
|
||||||
|
expect(applied).toBeUndefined()
|
||||||
|
expect(process.env.CLAUDE_CODE_EXPLICIT_PROVIDER).toBe('anthropic')
|
||||||
|
expect(process.env.CLAUDE_CODE_USE_OPENAI).toBeUndefined()
|
||||||
|
expect(process.env.CLAUDE_CODE_USE_GITHUB).toBeUndefined()
|
||||||
|
expect(process.env.OPENAI_MODEL).toBeUndefined()
|
||||||
|
})
|
||||||
|
|
||||||
test('does not override explicit startup provider selection', async () => {
|
test('does not override explicit startup provider selection', async () => {
|
||||||
const { applyActiveProviderProfileFromConfig } =
|
const { applyActiveProviderProfileFromConfig } =
|
||||||
await importFreshProviderProfileModules()
|
await importFreshProviderProfileModules()
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
type ProviderProfile,
|
type ProviderProfile,
|
||||||
} from './config.js'
|
} from './config.js'
|
||||||
import type { ModelOption } from './model/modelOptions.js'
|
import type { ModelOption } from './model/modelOptions.js'
|
||||||
|
import { EXPLICIT_PROVIDER_ENV_VAR } from './providerEnvSelection.js'
|
||||||
|
|
||||||
export type ProviderPreset =
|
export type ProviderPreset =
|
||||||
| 'anthropic'
|
| 'anthropic'
|
||||||
@@ -256,6 +257,7 @@ function hasProviderSelectionFlags(
|
|||||||
processEnv: NodeJS.ProcessEnv = process.env,
|
processEnv: NodeJS.ProcessEnv = process.env,
|
||||||
): boolean {
|
): boolean {
|
||||||
return (
|
return (
|
||||||
|
processEnv[EXPLICIT_PROVIDER_ENV_VAR] !== undefined ||
|
||||||
processEnv.CLAUDE_CODE_USE_OPENAI !== undefined ||
|
processEnv.CLAUDE_CODE_USE_OPENAI !== undefined ||
|
||||||
processEnv.CLAUDE_CODE_USE_GEMINI !== undefined ||
|
processEnv.CLAUDE_CODE_USE_GEMINI !== undefined ||
|
||||||
processEnv.CLAUDE_CODE_USE_GITHUB !== undefined ||
|
processEnv.CLAUDE_CODE_USE_GITHUB !== undefined ||
|
||||||
|
|||||||
Reference in New Issue
Block a user