From 695c9c887bcd2e18ab41fce870d52a3e6d00ff8b Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 5 Apr 2026 14:53:07 +0100 Subject: [PATCH] test: speed up openai codex provider cases --- src/agents/models-config.e2e-harness.ts | 6 - ...dels-config.providers.openai-codex.test.ts | 126 ++++++++---------- 2 files changed, 56 insertions(+), 76 deletions(-) diff --git a/src/agents/models-config.e2e-harness.ts b/src/agents/models-config.e2e-harness.ts index 20276b4cbc5..1992a2ed7c1 100644 --- a/src/agents/models-config.e2e-harness.ts +++ b/src/agents/models-config.e2e-harness.ts @@ -299,12 +299,6 @@ async function inferImplicitProviderTestPluginIds(params: { providerIds.add(pluginId); } } - const legacyGrokApiKey = ( - params.config?.tools?.web?.search as { grok?: { apiKey?: unknown } } | undefined - )?.grok?.apiKey; - if (legacyGrokApiKey !== undefined) { - providerIds.add("xai"); - } if (providerIds.size === 0) { // No config/env/auth hints: keep ambient local auto-discovery focused on the // one provider that is expected to probe localhost in tests. diff --git a/src/agents/models-config.providers.openai-codex.test.ts b/src/agents/models-config.providers.openai-codex.test.ts index c641f02f773..e6515a0f576 100644 --- a/src/agents/models-config.providers.openai-codex.test.ts +++ b/src/agents/models-config.providers.openai-codex.test.ts @@ -1,17 +1,21 @@ import fs from "node:fs/promises"; import path from "node:path"; -import { describe, expect, it } from "vitest"; +import { describe, expect, it, vi } from "vitest"; +import { createConfigRuntimeEnv } from "../config/env-vars.js"; import { resolveOpenClawAgentDir } from "./agent-paths.js"; import { installModelsConfigTestHooks, MODELS_CONFIG_IMPLICIT_ENV_VARS, - resolveImplicitProvidersForTest, unsetEnv, withModelsTempHome, withTempEnv, } from "./models-config.e2e-harness.js"; -import { ensureOpenClawModelsJson } from "./models-config.js"; -import { readGeneratedModelsJson } from "./models-config.test-utils.js"; +import { planOpenClawModelsJson } from "./models-config.plan.js"; + +vi.mock("./cli-credentials.js", () => ({ + readCodexCliCredentialsCached: () => null, + readMiniMaxCliCredentialsCached: () => null, +})); installModelsConfigTestHooks(); @@ -43,61 +47,43 @@ async function writeCodexOauthProfile(agentDir: string) { } describe("openai-codex implicit provider", () => { - it("injects an implicit provider when Codex OAuth exists", async () => { - await withModelsTempHome(async () => { - await withTempEnv(MODELS_CONFIG_IMPLICIT_ENV_VARS, async () => { - unsetEnv(MODELS_CONFIG_IMPLICIT_ENV_VARS); - const agentDir = resolveOpenClawAgentDir(); - await writeCodexOauthProfile(agentDir); - - const providers = await resolveImplicitProvidersForTest({ agentDir }); - expect(providers?.["openai-codex"]).toMatchObject({ - baseUrl: "https://chatgpt.com/backend-api", - api: "openai-codex-responses", - models: [], - }); - expect(providers?.["openai-codex"]).not.toHaveProperty("apiKey"); - }); - }); - }); - it("normalizes generated openai-codex rows back to the Codex transport when oauth exists", async () => { await withModelsTempHome(async () => { await withTempEnv(MODELS_CONFIG_IMPLICIT_ENV_VARS, async () => { unsetEnv(MODELS_CONFIG_IMPLICIT_ENV_VARS); + process.env.OPENCLAW_TEST_ONLY_PROVIDER_PLUGIN_IDS = "openai-codex"; const agentDir = resolveOpenClawAgentDir(); await writeCodexOauthProfile(agentDir); - await fs.writeFile( - path.join(agentDir, "models.json"), - JSON.stringify( - { - providers: { - "openai-codex": { - baseUrl: "https://api.openai.com/v1", + const existingParsed = { + providers: { + "openai-codex": { + baseUrl: "https://api.openai.com/v1", + api: "openai-responses", + models: [ + { + id: "gpt-5.4", + name: "GPT-5.4", api: "openai-responses", - models: [ - { - id: "gpt-5.4", - name: "GPT-5.4", - api: "openai-responses", - contextWindow: 1_000_000, - maxTokens: 100_000, - }, - ], + contextWindow: 1_000_000, + maxTokens: 100_000, }, - }, + ], }, - null, - 2, - ), - "utf8", - ); + }, + }; + const plan = await planOpenClawModelsJson({ + cfg: {}, + sourceConfigForSecrets: {}, + agentDir, + env: createConfigRuntimeEnv({}), + existingRaw: `${JSON.stringify(existingParsed, null, 2)}\n`, + existingParsed, + }); - await ensureOpenClawModelsJson({}); - - const parsed = await readGeneratedModelsJson<{ + expect(plan.action).toBe("write"); + const parsed = JSON.parse((plan as { contents: string }).contents) as { providers: Record; - }>(); + }; expect(parsed.providers["openai-codex"]).toMatchObject({ baseUrl: "https://chatgpt.com/backend-api", api: "openai-codex-responses", @@ -110,27 +96,9 @@ describe("openai-codex implicit provider", () => { await withModelsTempHome(async () => { await withTempEnv(MODELS_CONFIG_IMPLICIT_ENV_VARS, async () => { unsetEnv(MODELS_CONFIG_IMPLICIT_ENV_VARS); + process.env.OPENCLAW_TEST_ONLY_PROVIDER_PLUGIN_IDS = "openai-codex"; const agentDir = resolveOpenClawAgentDir(); - await fs.mkdir(agentDir, { recursive: true }); - await fs.writeFile( - path.join(agentDir, "models.json"), - JSON.stringify( - { - providers: { - "openai-codex": { - baseUrl: "https://chatgpt.com/backend-api", - api: "openai-codex-responses", - models: [], - }, - }, - }, - null, - 2, - ), - "utf8", - ); - - await ensureOpenClawModelsJson({ + const cfg = { models: { mode: "merge", providers: { @@ -141,11 +109,29 @@ describe("openai-codex implicit provider", () => { }, }, }, + }; + const existingParsed = { + providers: { + "openai-codex": { + baseUrl: "https://chatgpt.com/backend-api", + api: "openai-codex-responses", + models: [], + }, + }, + }; + const plan = await planOpenClawModelsJson({ + cfg, + sourceConfigForSecrets: cfg, + agentDir, + env: createConfigRuntimeEnv(cfg), + existingRaw: `${JSON.stringify(existingParsed, null, 2)}\n`, + existingParsed, }); - const parsed = await readGeneratedModelsJson<{ + expect(plan.action).toBe("write"); + const parsed = JSON.parse((plan as { contents: string }).contents) as { providers: Record; - }>(); + }; expect(parsed.providers["openai-codex"]).toMatchObject({ baseUrl: "https://chatgpt.com/backend-api", api: "openai-codex-responses",