test: bind Codex live API key lane through OpenAI

This commit is contained in:
Vincent Koc
2026-05-17 01:17:22 +08:00
parent f0105939bf
commit 3a13d1e0be
3 changed files with 32 additions and 3 deletions

View File

@@ -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)

View File

@@ -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<void> {
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,

View File

@@ -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:-}"',
);
});
});