mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-03 15:13:38 +00:00
fix: pass prepared CLI env to spawned process
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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,
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user