From 3a13d1e0be684bc5b091214fc6abd99749713fc0 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 17 May 2026 01:17:22 +0800 Subject: [PATCH] test: bind Codex live API key lane through OpenAI --- scripts/test-live-codex-harness-docker.sh | 1 + src/gateway/gateway-codex-bind.live.test.ts | 26 ++++++++++++++++--- .../test-live-codex-harness-docker.test.ts | 8 ++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/scripts/test-live-codex-harness-docker.sh b/scripts/test-live-codex-harness-docker.sh index ccb719b8dcc..c814e2038f9 100644 --- a/scripts/test-live-codex-harness-docker.sh +++ b/scripts/test-live-codex-harness-docker.sh @@ -314,6 +314,7 @@ DOCKER_RUN_ARGS=(docker run --rm -t \ -e OPENCLAW_LIVE_CODEX_TRUSTED_HARNESS_DIR="$DOCKER_TRUSTED_HARNESS_CONTAINER_DIR" \ -e OPENCLAW_LIVE_CODEX_BIND="${OPENCLAW_LIVE_CODEX_BIND:-}" \ -e OPENCLAW_LIVE_CODEX_BIND_MODEL="${OPENCLAW_LIVE_CODEX_BIND_MODEL:-}" \ + -e OPENCLAW_LIVE_CODEX_BIND_PROVIDER="${OPENCLAW_LIVE_CODEX_BIND_PROVIDER:-}" \ -e OPENCLAW_LIVE_CODEX_TEST_FILES="${OPENCLAW_LIVE_CODEX_TEST_FILES:-}" \ -e OPENCLAW_LIVE_TEST=1 \ -e OPENCLAW_VITEST_FS_MODULE_CACHE=0) diff --git a/src/gateway/gateway-codex-bind.live.test.ts b/src/gateway/gateway-codex-bind.live.test.ts index f186a80f5a3..7855a753612 100644 --- a/src/gateway/gateway-codex-bind.live.test.ts +++ b/src/gateway/gateway-codex-bind.live.test.ts @@ -319,10 +319,12 @@ async function writePluginBindingApproval(params: { async function writeGatewayConfig(params: { configPath: string; model: string; + modelProvider?: string; port: number; token: string; workspace: string; }): Promise { + const modelProvider = params.modelProvider?.trim() || "codex"; const cfg: OpenClawConfig = { gateway: { mode: "local", @@ -348,7 +350,7 @@ async function writeGatewayConfig(params: { defaults: { workspace: params.workspace, agentRuntime: { id: "codex" }, - model: { primary: `codex/${params.model}` }, + model: { primary: `${modelProvider}/${params.model}` }, skipBootstrap: true, heartbeat: { every: "0m" }, sandbox: { mode: "off" }, @@ -358,6 +360,14 @@ async function writeGatewayConfig(params: { await fs.writeFile(params.configPath, `${JSON.stringify(cfg, null, 2)}\n`); } +function resolveCodexBindModelProvider(): string | undefined { + const configured = process.env.OPENCLAW_LIVE_CODEX_BIND_PROVIDER?.trim(); + if (configured) { + return configured; + } + return process.env.OPENCLAW_LIVE_CODEX_HARNESS_AUTH === "api-key" ? "openai" : undefined; +} + describeLive("gateway live (native Codex conversation binding)", () => { it( "binds a Slack DM to Codex app-server, updates controls, and forwards image media paths", @@ -386,6 +396,7 @@ describeLive("gateway live (native Codex conversation binding)", () => { const conversationId = `user:${slackUserId}`; const bindModel = process.env.OPENCLAW_LIVE_CODEX_BIND_MODEL?.trim() || DEFAULT_CODEX_BIND_MODEL; + const bindProvider = resolveCodexBindModelProvider(); const outboundReplies: CapturedOutboundReply[] = []; await fs.mkdir(workspace, { recursive: true }); @@ -400,7 +411,14 @@ describeLive("gateway live (native Codex conversation binding)", () => { ); await fs.mkdir(tempHome, { recursive: true }); await fs.mkdir(stateDir, { recursive: true }); - await writeGatewayConfig({ configPath, model: bindModel, port, token, workspace }); + await writeGatewayConfig({ + configPath, + model: bindModel, + modelProvider: bindProvider, + port, + token, + workspace, + }); clearConfigCache(); clearRuntimeConfigSnapshot(); @@ -449,7 +467,9 @@ describeLive("gateway live (native Codex conversation binding)", () => { client, sessionKey, idempotencyKey: `idem-codex-bind-${randomUUID()}`, - message: `/codex bind --cwd ${workspace} --model ${bindModel}`, + message: `/codex bind --cwd ${workspace} --model ${bindModel}${ + bindProvider ? ` --provider ${bindProvider}` : "" + }`, originatingChannel: "slack", originatingTo: conversationId, originatingAccountId: accountId, diff --git a/test/scripts/test-live-codex-harness-docker.test.ts b/test/scripts/test-live-codex-harness-docker.test.ts index c49203051f8..6e5d96ab16a 100644 --- a/test/scripts/test-live-codex-harness-docker.test.ts +++ b/test/scripts/test-live-codex-harness-docker.test.ts @@ -47,4 +47,12 @@ describe("scripts/test-live-codex-harness-docker.sh", () => { script.indexOf("CODEX_API_KEY=%s"), ); }); + + it("forwards the live Codex bind provider override into Docker", () => { + const script = fs.readFileSync(SCRIPT_PATH, "utf8"); + + expect(script).toContain( + '-e OPENCLAW_LIVE_CODEX_BIND_PROVIDER="${OPENCLAW_LIVE_CODEX_BIND_PROVIDER:-}"', + ); + }); });