diff --git a/frontend/src/utils/__tests__/ccswitchImport.spec.ts b/frontend/src/utils/__tests__/ccswitchImport.spec.ts index aa3ee36ca0..6f23c1aa3b 100644 --- a/frontend/src/utils/__tests__/ccswitchImport.spec.ts +++ b/frontend/src/utils/__tests__/ccswitchImport.spec.ts @@ -27,28 +27,12 @@ describe('ccswitchImport utils', () => { usageScript: 'return true' } - it('adds the Codex model parameter for OpenAI imports', () => { - const params = paramsFromDeeplink( - buildCcSwitchImportDeeplink({ - ...baseInput, - platform: 'openai', - clientType: 'claude' - }) - ) - - expect(params.get('resource')).toBe('provider') - expect(params.get('app')).toBe('codex') - expect(params.get('endpoint')).toBe(`${baseInput.baseUrl}/v1`) - expect(params.get('model')).toBe(OPENAI_CC_SWITCH_CODEX_MODEL) - expect(atob(params.get('usageScript') || '')).toBe(baseInput.usageScript) - }) - it.each([ - 'https://api.example.com', - 'https://api.example.com/', - 'https://api.example.com/v1', - 'https://api.example.com/v1/' - ])('imports Codex with exactly one /v1 suffix for base URL %s', (baseUrl) => { + ['https://api.example.com', 'https://api.example.com'], + ['https://api.example.com/', 'https://api.example.com'], + ['https://api.example.com/v1', 'https://api.example.com/v1'], + ['https://api.example.com/v1/', 'https://api.example.com/v1'] + ])('keeps Codex imports on the configured endpoint for base URL %s', (baseUrl, endpoint) => { const params = paramsFromDeeplink( buildCcSwitchImportDeeplink({ ...baseInput, @@ -58,7 +42,11 @@ describe('ccswitchImport utils', () => { }) ) - expect(params.get('endpoint')).toBe('https://api.example.com/v1') + expect(params.get('resource')).toBe('provider') + expect(params.get('app')).toBe('codex') + expect(params.get('endpoint')).toBe(endpoint) + expect(params.get('model')).toBe(OPENAI_CC_SWITCH_CODEX_MODEL) + expect(atob(params.get('usageScript') || '')).toBe(baseInput.usageScript) }) it.each([ diff --git a/frontend/src/utils/ccswitchImport.ts b/frontend/src/utils/ccswitchImport.ts index 96b602041a..f9ca257349 100644 --- a/frontend/src/utils/ccswitchImport.ts +++ b/frontend/src/utils/ccswitchImport.ts @@ -25,6 +25,10 @@ function withV1Endpoint(baseUrl: string): string { return normalizedBaseUrl.endsWith('/v1') ? normalizedBaseUrl : `${normalizedBaseUrl}/v1` } +function withoutTrailingSlashes(baseUrl: string): string { + return baseUrl.replace(/\/+$/, '') +} + export function resolveCcSwitchImportConfig( platform: GroupPlatform | undefined | null, clientType: CcSwitchClientType, @@ -39,7 +43,9 @@ export function resolveCcSwitchImportConfig( case 'openai': return { app: 'codex', - endpoint: withV1Endpoint(baseUrl), + // CC Switch's Codex provider appends the OpenAI-compatible path itself. + // Passing /v1 here can make the client request /v1/v1/.... + endpoint: withoutTrailingSlashes(baseUrl), model: OPENAI_CC_SWITCH_CODEX_MODEL } case 'gemini':