From 2a1f5697cc599ed70214ca94b2b36635a74351aa Mon Sep 17 00:00:00 2001 From: claude-code-best Date: Thu, 11 Jun 2026 16:15:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A2=9E=E5=BC=BA=20providers=20?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=9A=84=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E9=9A=94=E7=A6=BB=EF=BC=8C=E9=98=B2=E6=AD=A2=20mock=20?= =?UTF-8?q?=E6=B1=A1=E6=9F=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/model/__tests__/providers.test.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/utils/model/__tests__/providers.test.ts b/src/utils/model/__tests__/providers.test.ts index 6790a3e6f..445c3746b 100644 --- a/src/utils/model/__tests__/providers.test.ts +++ b/src/utils/model/__tests__/providers.test.ts @@ -1,4 +1,5 @@ import { describe, expect, test, beforeEach, afterEach } from 'bun:test' +import { isEnvTruthy } from '../../envUtils.js' const { getAPIProvider, isFirstPartyAnthropicBaseUrl } = await import( '../providers' @@ -12,11 +13,12 @@ describe('getAPIProvider', () => { 'CLAUDE_CODE_USE_FOUNDRY', 'CLAUDE_CODE_USE_OPENAI', 'CLAUDE_CODE_USE_GROK', + 'OPENAI_BASE_URL', + 'GEMINI_BASE_URL', ] as const const savedEnv: Record = {} beforeEach(() => { - // Save and clear environment variables for (const key of envKeys) { savedEnv[key] = process.env[key] delete process.env[key] @@ -24,7 +26,6 @@ describe('getAPIProvider', () => { }) afterEach(() => { - // Restore environment variables for (const key of envKeys) { if (savedEnv[key] !== undefined) { process.env[key] = savedEnv[key] @@ -67,6 +68,16 @@ describe('getAPIProvider', () => { expect(getAPIProvider({})).toBe('foundry') }) + test('returns "openai" when CLAUDE_CODE_USE_OPENAI is set', () => { + process.env.CLAUDE_CODE_USE_OPENAI = '1' + expect(getAPIProvider({})).toBe('openai') + }) + + test('returns "grok" when CLAUDE_CODE_USE_GROK is set', () => { + process.env.CLAUDE_CODE_USE_GROK = '1' + expect(getAPIProvider({})).toBe('grok') + }) + test('bedrock takes precedence over gemini', () => { process.env.CLAUDE_CODE_USE_BEDROCK = '1' process.env.CLAUDE_CODE_USE_GEMINI = '1' @@ -88,16 +99,19 @@ describe('getAPIProvider', () => { test('"true" is truthy', () => { process.env.CLAUDE_CODE_USE_BEDROCK = 'true' + expect(isEnvTruthy(process.env.CLAUDE_CODE_USE_BEDROCK)).toBe(true) expect(getAPIProvider({})).toBe('bedrock') }) test('"0" is not truthy', () => { process.env.CLAUDE_CODE_USE_BEDROCK = '0' + expect(isEnvTruthy(process.env.CLAUDE_CODE_USE_BEDROCK)).toBe(false) expect(getAPIProvider({})).toBe('firstParty') }) test('empty string is not truthy', () => { process.env.CLAUDE_CODE_USE_BEDROCK = '' + expect(isEnvTruthy(process.env.CLAUDE_CODE_USE_BEDROCK)).toBe(false) expect(getAPIProvider({})).toBe('firstParty') }) })