fix: pass prepared CLI env to spawned process

This commit is contained in:
Shakker
2026-06-16 16:47:51 +01:00
committed by Shakker
parent 0adfca3189
commit 2bde35d29c
2 changed files with 37 additions and 3 deletions

View File

@@ -92,6 +92,7 @@ function buildPreparedCliRunContext(params: {
sessionEntry?: PreparedCliRunContext["params"]["sessionEntry"];
agentId?: string;
backend?: Partial<PreparedCliRunContext["preparedBackend"]["backend"]>;
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<string, string> };
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");

View File

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