fix: restore docker binds and PATH in sandbox exec (#873)
Thanks @akonyer. Co-authored-by: Aaron Konyer <aaronk@gomodular.ca>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { resetProcessRegistryForTests } from "./bash-process-registry.js";
|
||||
import { createExecTool, createProcessTool, execTool, processTool } from "./bash-tools.js";
|
||||
import { buildDockerExecArgs } from "./bash-tools.shared.js";
|
||||
import { sanitizeBinaryOutput } from "./shell-utils.js";
|
||||
|
||||
const isWin = process.platform === "win32";
|
||||
@@ -239,3 +240,73 @@ describe("exec tool backgrounding", () => {
|
||||
expect(pollB.details.status).toBe("failed");
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildDockerExecArgs", () => {
|
||||
it("prepends custom PATH after login shell sourcing to preserve both custom and system tools", () => {
|
||||
const args = buildDockerExecArgs({
|
||||
containerName: "test-container",
|
||||
command: "echo hello",
|
||||
env: {
|
||||
PATH: "/custom/bin:/usr/local/bin:/usr/bin",
|
||||
HOME: "/home/user",
|
||||
},
|
||||
tty: false,
|
||||
});
|
||||
|
||||
const commandArg = args[args.length - 1];
|
||||
expect(commandArg).toContain('export PATH="/custom/bin:/usr/local/bin:/usr/bin:$PATH"');
|
||||
expect(commandArg).toContain("echo hello");
|
||||
expect(commandArg).toBe('export PATH="/custom/bin:/usr/local/bin:/usr/bin:$PATH"; echo hello');
|
||||
});
|
||||
|
||||
it("does not add PATH export when PATH is not in env", () => {
|
||||
const args = buildDockerExecArgs({
|
||||
containerName: "test-container",
|
||||
command: "echo hello",
|
||||
env: {
|
||||
HOME: "/home/user",
|
||||
},
|
||||
tty: false,
|
||||
});
|
||||
|
||||
const commandArg = args[args.length - 1];
|
||||
expect(commandArg).toBe("echo hello");
|
||||
expect(commandArg).not.toContain("export PATH");
|
||||
});
|
||||
|
||||
it("includes workdir flag when specified", () => {
|
||||
const args = buildDockerExecArgs({
|
||||
containerName: "test-container",
|
||||
command: "pwd",
|
||||
workdir: "/workspace",
|
||||
env: { HOME: "/home/user" },
|
||||
tty: false,
|
||||
});
|
||||
|
||||
expect(args).toContain("-w");
|
||||
expect(args).toContain("/workspace");
|
||||
});
|
||||
|
||||
it("uses login shell for consistent environment", () => {
|
||||
const args = buildDockerExecArgs({
|
||||
containerName: "test-container",
|
||||
command: "echo test",
|
||||
env: { HOME: "/home/user" },
|
||||
tty: false,
|
||||
});
|
||||
|
||||
expect(args).toContain("sh");
|
||||
expect(args).toContain("-lc");
|
||||
});
|
||||
|
||||
it("includes tty flag when requested", () => {
|
||||
const args = buildDockerExecArgs({
|
||||
containerName: "test-container",
|
||||
command: "bash",
|
||||
env: { HOME: "/home/user" },
|
||||
tty: true,
|
||||
});
|
||||
|
||||
expect(args).toContain("-t");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user