fix(codex): normalize CLIProxy responses routes (#1605)

Normalize Codex Responses base URLs so CCS-backed Codex launches use /backend-api/codex on the original CLIProxy backend. Share the Codex Responses route builder with ccsxp provider repair, and repair stale native Codex provider auth blocks when env_key token injection is used.
This commit is contained in:
Thieu Nguyen authored and GitHub committed 2026-06-26 15:41:15 -04:00
1 parent 36ea9064e7
commit ba0e768fbf
6 files changed
+100 -23

No files matched your search

+4 -1
View File
@@ -128,7 +128,7 @@ describe('CodexAdapter', () => {
profileType: 'cliproxy',
creds: {
profile: 'codex',
baseUrl: 'http://127.0.0.1:8317/api/provider/codex',
baseUrl: 'http://127.0.0.1:8317',
apiKey: 'cliproxy-token',
model: 'gpt-5.4',
reasoningOverride: 'high',
@@ -143,6 +143,9 @@ describe('CodexAdapter', () => {
expect(args).toContain('-c');
expect(args).toContain('model_provider="ccs_runtime"');
expect(args).toContain(
'model_providers.ccs_runtime.base_url="http://127.0.0.1:8317/backend-api/codex"'
);
expect(args).toContain('model_providers.ccs_runtime.env_key="CCS_CODEX_API_KEY"');
expect(args).toContain('model="gpt-5.4"');
expect(args).toContain(
@@ -55,9 +55,7 @@ describe('codex cliproxy provider config repair', () => {
// original CLIProxy backend serves the Codex Responses API only under the
// "/backend-api/codex" alias, never at the bare root. Returning the root here
// makes Codex call "http://127.0.0.1:8317/responses" -> 404 (issue #1597).
expect(buildCodexCliproxyProviderBaseUrl(8317)).toBe(
'http://127.0.0.1:8317/backend-api/codex'
);
expect(buildCodexCliproxyProviderBaseUrl(8317)).toBe('http://127.0.0.1:8317/backend-api/codex');
});
it('produces a Codex Responses endpoint the original backend actually serves (regression #1597)', () => {
@@ -135,6 +133,36 @@ wire_api = "responses"
expect(rawText).toContain('supports_websockets = false');
});
it('removes native provider auth when ccsxp injects the token through env_key', async () => {
fs.mkdirSync(codexHome, { recursive: true });
fs.writeFileSync(
configPath,
`[model_providers.cliproxy]
name = "CLIProxy Codex"
base_url = "http://127.0.0.1:8317/backend-api/codex"
env_key = "CLIPROXY_API_KEY"
wire_api = "responses"
requires_openai_auth = false
supports_websockets = false
[model_providers.cliproxy.auth]
command = "/tmp/cliproxy-token"
timeout_ms = 5000
refresh_interval_ms = 300000
`,
'utf8'
);
const result = await ensureCodexCliproxyProviderConfig(8317, env);
expect(result.changed).toBe(true);
expect(result.envKey).toBe('CLIPROXY_API_KEY');
const rawText = fs.readFileSync(configPath, 'utf8');
expect(rawText).toContain('env_key = "CLIPROXY_API_KEY"');
expect(rawText).not.toContain('[model_providers.cliproxy.auth]');
expect(rawText).not.toContain('cliproxy-token');
});
it('preserves custom cliproxy provider values while repairing other fields', async () => {
fs.mkdirSync(codexHome, { recursive: true });
fs.writeFileSync(
@@ -124,21 +124,26 @@ exit 0
const argsLog = fs.readFileSync(codexArgsLogPath, 'utf8');
expect(argsLog).toContain('model_provider="ccs_runtime"');
expect(argsLog).toContain('model_providers.ccs_runtime.base_url="http://127.0.0.1:8317/api/provider/codex"');
expect(argsLog).toContain(
'model_providers.ccs_runtime.base_url="http://127.0.0.1:8317/backend-api/codex"'
);
expect(argsLog).toContain('model_reasoning_effort="high"');
expect(argsLog).not.toContain('mcp_servers.ccs_browser.command=');
expect(argsLog).not.toContain('mcp_servers.ccs_browser.args=["-y","@playwright/mcp@0.0.70"]');
expect(argsLog).toContain('smoke');
expect(fs.readFileSync(codexEnvLogPath, 'utf8')).toBe('bridge-token');
});
}, 15000);
it('rejects native Codex profile flags when CCS manages the bridge runtime', () => {
if (process.platform === 'win32') return;
const result = runCcs(['codex-api', '--target', 'codex', '--profile', 'other', 'smoke'], baseEnv);
const result = runCcs(
['codex-api', '--target', 'codex', '--profile', 'other', 'smoke'],
baseEnv
);
expect(result.status).toBe(1);
expect(result.stderr).toContain('does not allow --profile/-p');
expect(fs.existsSync(codexArgsLogPath)).toBe(false);
});
}, 15000);
});