Files
cc-switch/tests/utils/codexConfigUtils.baseUrl.test.ts
SaladDay ea420cc070 refactor(codex): split Codex TOML editing out of providerConfigUtils (#9795)
* refactor(codex): rename providerConfigUtils to codexConfigUtils

Of providerConfigUtils.ts's 1795 lines, 1567 are Codex config.toml editing
(base_url, wire_api, model, model_provider, [agents], top-level ints) and 22 of
its 26 importers only use those. Rename the file (and its tests) to say what
it is. Pure rename plus import paths; the next commit moves the four
API-key helpers back out.

* refactor: move API-key template helpers back to providerConfigUtils

getApiKeyFromConfig, applyTemplateValues, hasApiKeyField and setApiKeyInConfig
serve Claude, Codex and Gemini forms alike, so they stay in
providerConfigUtils.ts; codexConfigUtils.ts keeps only Codex TOML editing.
Code moves verbatim.
2026-11-21 19:21:22 -08:00

54 lines
1.6 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { extractProviderBaseUrl } from "@/utils/codexConfigUtils";
describe("extractProviderBaseUrl", () => {
it.each([
[
"claude / claude-desktop",
{ env: { ANTHROPIC_BASE_URL: "https://claude.example.com" } },
"https://claude.example.com",
],
[
"gemini",
{ env: { GOOGLE_GEMINI_BASE_URL: "https://gemini.example.com" } },
"https://gemini.example.com",
],
[
"codex / grokbuild",
{
auth: {},
config: [
'model_provider = "custom"',
"",
"[model_providers.custom]",
'base_url = "https://codex.example.com/v1"',
].join("\n"),
},
"https://codex.example.com/v1",
],
[
"opencode / mcode",
{ options: { baseURL: "https://opencode.example.com/v1" } },
"https://opencode.example.com/v1",
],
[
"openclaw / pi",
{ baseUrl: "https://openclaw.example.com/v1" },
"https://openclaw.example.com/v1",
],
[
"hermes",
{ base_url: "https://hermes.example.com/v1" },
"https://hermes.example.com/v1",
],
])("reads the %s shape", (_app, settingsConfig, expected) => {
expect(extractProviderBaseUrl(settingsConfig)).toBe(expected);
});
it("returns undefined for official providers without an address", () => {
expect(extractProviderBaseUrl({ env: {} })).toBeUndefined();
expect(extractProviderBaseUrl({ auth: {}, config: "" })).toBeUndefined();
expect(extractProviderBaseUrl(undefined)).toBeUndefined();
});
});