test(installer): isolate install shell snippets

This commit is contained in:
Vincent Koc
2026-06-01 04:06:11 +01:00
parent fcc279e233
commit 916ee82814
+20 -1
View File
@@ -11,8 +11,10 @@ function runInstallShell(script: string, env: NodeJS.ProcessEnv = {}) {
encoding: "utf8",
env: {
...process.env,
OPENCLAW_INSTALL_SH_NO_RUN: "1",
...env,
BASH_ENV: "",
ENV: "",
OPENCLAW_INSTALL_SH_NO_RUN: "1",
},
});
}
@@ -88,6 +90,23 @@ function writeNpmBeforePolicyFixture(path: string, argsLog: string) {
describe("install.sh", () => {
const script = readFileSync(SCRIPT_PATH, "utf8");
it("runs installer snippets without inherited shell startup files", () => {
const tmp = mkdtempSync(join(tmpdir(), "openclaw-install-shell-env-"));
const bashEnvPath = join(tmp, "bash_env");
writeFileSync(bashEnvPath, "export OPENCLAW_BASH_ENV_LEAKED=1\n");
try {
const result = runInstallShell('printf "leaked=%s\\n" "${OPENCLAW_BASH_ENV_LEAKED:-0}"', {
BASH_ENV: bashEnvPath,
});
expect(result.status).toBe(0);
expect(result.stdout).toBe("leaked=0\n");
} finally {
rmSync(tmp, { force: true, recursive: true });
}
});
it("runs apt-get through noninteractive wrappers", () => {
expect(script).toContain("apt_get()");
expect(script).toContain('DEBIAN_FRONTEND="${DEBIAN_FRONTEND:-noninteractive}"');