fix(cli-tools): refresh Codex settings after apply (#4347)

This commit is contained in:
Beru
2026-09-26 16:20:48 +07:00
parent fdcba3e1b2
commit 8f20daac6b
6 changed files with 167 additions and 26 deletions

View File

@@ -0,0 +1,44 @@
import { describe, expect, it } from "vitest";
import { getCurrentCodexProviderBaseUrl, getCurrentCodexProviderSettings } from "../../src/app/(dashboard)/dashboard/cli-tools/components/codexConfig.js";
describe("Codex current provider base URL", () => {
it("uses the base URL from the configured model provider, not an earlier provider", () => {
const config = `model = "gpt-5"
model_provider = "9router"
[model_providers.omniroute]
base_url = "https://omniroute.example/v1"
[model_providers.9router]
base_url = "http://127.0.0.1:20128/v1"
`;
expect(getCurrentCodexProviderBaseUrl(config)).toBe("http://127.0.0.1:20128/v1");
});
it("reads the active provider URL and bearer key when another provider appears first", () => {
const config = `model_provider = "9router"
[model_providers.omniroute]
base_url = "https://omniroute.example/v1"
[model_providers.omniroute.http_headers]
Authorization = "Bearer placeholder-omniroute-key"
[model_providers.9router]
base_url = "https://9router.example/v1/"
[model_providers.9router.http_headers]
Authorization = "Bearer placeholder-9router-key"
`;
expect(getCurrentCodexProviderSettings(config)).toEqual({
baseUrl: "https://9router.example/v1/",
apiKey: "placeholder-9router-key",
});
});
it("returns empty settings when no active provider is configured", () => {
expect(getCurrentCodexProviderSettings("model = \"gpt-5\"\n")).toEqual({ baseUrl: "", apiKey: "" });
});
});

View File

@@ -0,0 +1,30 @@
import { readFile } from "node:fs/promises";
import { fileURLToPath } from "node:url";
import { describe, expect, it } from "vitest";
const readSource = (relativePath) =>
readFile(fileURLToPath(new URL(relativePath, import.meta.url)), "utf8");
describe("Codex settings refresh", () => {
it("bypasses cached status after applying a selected endpoint", async () => {
const [routeSource, cardSource] = await Promise.all([
readSource("../../src/app/api/cli-tools/codex-settings/route.js"),
readSource("../../src/app/(dashboard)/dashboard/cli-tools/components/CodexToolCard.js"),
]);
// Route Handlers already run on the server; a Server Action directive would reject this export.
expect(routeSource).not.toContain('"use server";');
expect(routeSource).toContain('export const dynamic = "force-dynamic";');
expect(cardSource).toContain('fetch("/api/cli-tools/codex-settings", { cache: "no-store" })');
expect(cardSource).toContain("setSelectedApiKey(apiKey);");
expect(cardSource).toContain("setCustomBaseUrl(baseUrl);");
});
it("keeps an unmatched active URL in the custom endpoint slot", async () => {
const selectorSource = await readSource("../../src/app/(dashboard)/dashboard/cli-tools/components/BaseUrlSelect.js");
expect(selectorSource).toContain("if (current) {");
expect(selectorSource).toContain("setCustomInput(current);");
expect(selectorSource).toContain("onChange(current);");
});
});