mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 13:51:45 +00:00
test: split pure docker exec arg checks from bash e2e suite
This commit is contained in:
93
src/agents/bash-tools.build-docker-exec-args.test.ts
Normal file
93
src/agents/bash-tools.build-docker-exec-args.test.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildDockerExecArgs } from "./bash-tools.shared.js";
|
||||
|
||||
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(args).toContain("OPENCLAW_PREPEND_PATH=/custom/bin:/usr/local/bin:/usr/bin");
|
||||
expect(commandArg).toContain('export PATH="${OPENCLAW_PREPEND_PATH}:$PATH"');
|
||||
expect(commandArg).toContain("echo hello");
|
||||
expect(commandArg).toBe(
|
||||
'export PATH="${OPENCLAW_PREPEND_PATH}:$PATH"; unset OPENCLAW_PREPEND_PATH; echo hello',
|
||||
);
|
||||
});
|
||||
|
||||
it("does not interpolate PATH into the shell command", () => {
|
||||
const injectedPath = "$(touch /tmp/openclaw-path-injection)";
|
||||
const args = buildDockerExecArgs({
|
||||
containerName: "test-container",
|
||||
command: "echo hello",
|
||||
env: {
|
||||
PATH: injectedPath,
|
||||
HOME: "/home/user",
|
||||
},
|
||||
tty: false,
|
||||
});
|
||||
|
||||
const commandArg = args[args.length - 1];
|
||||
expect(args).toContain(`OPENCLAW_PREPEND_PATH=${injectedPath}`);
|
||||
expect(commandArg).not.toContain(injectedPath);
|
||||
expect(commandArg).toContain("OPENCLAW_PREPEND_PATH");
|
||||
});
|
||||
|
||||
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