diff --git a/src/agents/cli-runner.spawn.test.ts b/src/agents/cli-runner.spawn.test.ts index df2e4bea10e..04e7ccab1cd 100644 --- a/src/agents/cli-runner.spawn.test.ts +++ b/src/agents/cli-runner.spawn.test.ts @@ -92,6 +92,7 @@ function buildPreparedCliRunContext(params: { sessionEntry?: PreparedCliRunContext["params"]["sessionEntry"]; agentId?: string; backend?: Partial; + preparedEnv?: PreparedCliRunContext["preparedBackend"]["env"]; resolveExecutionArgs?: PreparedCliRunContext["backendResolved"]["resolveExecutionArgs"]; config?: PreparedCliRunContext["params"]["config"]; mcpConfigHash?: string; @@ -162,7 +163,7 @@ function buildPreparedCliRunContext(params: { }, preparedBackend: { backend, - env: {}, + env: params.preparedEnv ?? {}, ...(params.mcpConfigHash ? { mcpConfigHash: params.mcpConfigHash } : {}), }, reusableCliSession: {}, @@ -532,6 +533,35 @@ describe("runCliAgent spawn path", () => { expect(requireArgAfter(input.argv, "--effort")).toBe("high"); }); + it("passes prepared backend env to the spawned CLI process", async () => { + mockSuccessfulCliRun(); + + await executePreparedCliRun( + buildPreparedCliRunContext({ + provider: "codex-cli", + model: "gpt-5.5", + runId: "run-prepared-env", + backend: { + env: { + GEMINI_CLI_HOME: "/ignored/static-home", + STATIC_BACKEND_FLAG: "set", + }, + }, + preparedEnv: { + GEMINI_CLI_HOME: "/tmp/openclaw-gemini-profile-home", + GEMINI_CLI_SYSTEM_SETTINGS_PATH: "/tmp/openclaw-gemini-system-settings.json", + }, + }), + ); + + const input = mockCallArg(supervisorSpawnMock) as { env?: Record }; + expect(input.env?.STATIC_BACKEND_FLAG).toBe("set"); + expect(input.env?.GEMINI_CLI_HOME).toBe("/tmp/openclaw-gemini-profile-home"); + expect(input.env?.GEMINI_CLI_SYSTEM_SETTINGS_PATH).toBe( + "/tmp/openclaw-gemini-system-settings.json", + ); + }); + it("passes OpenClaw skills to Claude as a session plugin", async () => { const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-cli-skills-")); const skillDir = path.join(workspaceDir, "skills", "weather"); diff --git a/src/agents/cli-runner/execute.ts b/src/agents/cli-runner/execute.ts index a9a68f01107..297d37a1378 100644 --- a/src/agents/cli-runner/execute.ts +++ b/src/agents/cli-runner/execute.ts @@ -676,12 +676,16 @@ export async function executePreparedCliRun( } delete next[key]; } - if (backend.env && Object.keys(backend.env).length > 0) { + const backendEnv = { + ...(backend.env ?? {}), + ...(context.preparedBackend.env ?? {}), + }; + if (Object.keys(backendEnv).length > 0) { Object.assign( next, sanitizeHostExecEnv({ baseEnv: {}, - overrides: backend.env, + overrides: backendEnv, blockPathOverrides: true, }), );