Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions src/node/services/tools/bash.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,7 @@ describe("bash tool - background execution", () => {
expect(result.success).toBe(true);
if (result.success && "backgroundProcessId" in result) {
expect(result.backgroundProcessId).toBeDefined();

// Process ID is now the display name directly
expect(result.backgroundProcessId).toBe("test");
} else {
Expand All @@ -1527,4 +1528,46 @@ describe("bash tool - background execution", () => {

tempDir[Symbol.dispose]();
});

it("should inject muxEnv environment variables in background mode", async () => {
const manager = new BackgroundProcessManager("/tmp/mux-test-bg");

const tempDir = new TestTempDir("test-bash-bg-mux-env");
const config = createTestToolConfig(tempDir.path);
config.backgroundProcessManager = manager;
config.muxEnv = {
MUX_MODEL_STRING: "openai:gpt-5.2",
MUX_THINKING_LEVEL: "medium",
};

const tool = createBashTool(config);
const args: BashToolArgs = {
script: 'echo "MODEL:$MUX_MODEL_STRING THINKING:$MUX_THINKING_LEVEL"',
timeout_secs: 5,
run_in_background: true,
display_name: "test-mux-env-bg",
};

const result = (await tool.execute!(args, mockToolCallOptions)) as BashToolResult;

expect(result.success).toBe(true);
if (result.success && "backgroundProcessId" in result) {
const outputResult = await manager.getOutput(
result.backgroundProcessId,
undefined,
undefined,
2
);
expect(outputResult.success).toBe(true);
if (outputResult.success) {
expect(outputResult.output).toContain("MODEL:openai:gpt-5.2");
expect(outputResult.output).toContain("THINKING:medium");
}
} else {
throw new Error("Expected background process ID in result");
}

await manager.terminateAll();
tempDir[Symbol.dispose]();
});
});
3 changes: 2 additions & 1 deletion src/node/services/tools/bash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ export const createBashTool: ToolFactory = (config: ToolConfiguration) => {
script,
{
cwd: config.cwd,
env: config.secrets,
// Match foreground bash behavior: muxEnv is present and secrets override it.
env: { ...(config.muxEnv ?? {}), ...(config.secrets ?? {}) },
niceness: config.niceness,
displayName: display_name,
isForeground: false, // Explicit background
Expand Down
Loading