Skip to content

Commit fe3c94d

Browse files
authored
🤖 fix: pass muxEnv to background bash (#1142)
1 parent d78c608 commit fe3c94d

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/node/services/tools/bash.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,7 @@ describe("bash tool - background execution", () => {
15191519
expect(result.success).toBe(true);
15201520
if (result.success && "backgroundProcessId" in result) {
15211521
expect(result.backgroundProcessId).toBeDefined();
1522+
15221523
// Process ID is now the display name directly
15231524
expect(result.backgroundProcessId).toBe("test");
15241525
} else {
@@ -1527,4 +1528,46 @@ describe("bash tool - background execution", () => {
15271528

15281529
tempDir[Symbol.dispose]();
15291530
});
1531+
1532+
it("should inject muxEnv environment variables in background mode", async () => {
1533+
const manager = new BackgroundProcessManager("/tmp/mux-test-bg");
1534+
1535+
const tempDir = new TestTempDir("test-bash-bg-mux-env");
1536+
const config = createTestToolConfig(tempDir.path);
1537+
config.backgroundProcessManager = manager;
1538+
config.muxEnv = {
1539+
MUX_MODEL_STRING: "openai:gpt-5.2",
1540+
MUX_THINKING_LEVEL: "medium",
1541+
};
1542+
1543+
const tool = createBashTool(config);
1544+
const args: BashToolArgs = {
1545+
script: 'echo "MODEL:$MUX_MODEL_STRING THINKING:$MUX_THINKING_LEVEL"',
1546+
timeout_secs: 5,
1547+
run_in_background: true,
1548+
display_name: "test-mux-env-bg",
1549+
};
1550+
1551+
const result = (await tool.execute!(args, mockToolCallOptions)) as BashToolResult;
1552+
1553+
expect(result.success).toBe(true);
1554+
if (result.success && "backgroundProcessId" in result) {
1555+
const outputResult = await manager.getOutput(
1556+
result.backgroundProcessId,
1557+
undefined,
1558+
undefined,
1559+
2
1560+
);
1561+
expect(outputResult.success).toBe(true);
1562+
if (outputResult.success) {
1563+
expect(outputResult.output).toContain("MODEL:openai:gpt-5.2");
1564+
expect(outputResult.output).toContain("THINKING:medium");
1565+
}
1566+
} else {
1567+
throw new Error("Expected background process ID in result");
1568+
}
1569+
1570+
await manager.terminateAll();
1571+
tempDir[Symbol.dispose]();
1572+
});
15301573
});

src/node/services/tools/bash.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ export const createBashTool: ToolFactory = (config: ToolConfiguration) => {
257257
script,
258258
{
259259
cwd: config.cwd,
260-
env: config.secrets,
260+
// Match foreground bash behavior: muxEnv is present and secrets override it.
261+
env: { ...(config.muxEnv ?? {}), ...(config.secrets ?? {}) },
261262
niceness: config.niceness,
262263
displayName: display_name,
263264
isForeground: false, // Explicit background

0 commit comments

Comments
 (0)