mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 00:53:28 +00:00
test: make shell env path cache tests platform deterministic
This commit is contained in:
@@ -224,35 +224,34 @@ describe("infra runtime", () => {
|
||||
afterEach(() => resetShellPathCacheForTests());
|
||||
|
||||
it("returns PATH from login shell env", () => {
|
||||
if (process.platform === "win32") {
|
||||
return;
|
||||
}
|
||||
const exec = vi
|
||||
.fn()
|
||||
.mockReturnValue(Buffer.from("PATH=/custom/bin\0HOME=/home/user\0", "utf-8"));
|
||||
const result = getShellPathFromLoginShell({ env: { SHELL: "/bin/sh" }, exec });
|
||||
const result = getShellPathFromLoginShell({
|
||||
env: { SHELL: "/bin/sh" },
|
||||
exec,
|
||||
platform: "linux",
|
||||
});
|
||||
expect(result).toBe("/custom/bin");
|
||||
});
|
||||
|
||||
it("caches the value", () => {
|
||||
if (process.platform === "win32") {
|
||||
return;
|
||||
}
|
||||
const exec = vi.fn().mockReturnValue(Buffer.from("PATH=/custom/bin\0", "utf-8"));
|
||||
const env = { SHELL: "/bin/sh" } as NodeJS.ProcessEnv;
|
||||
expect(getShellPathFromLoginShell({ env, exec })).toBe("/custom/bin");
|
||||
expect(getShellPathFromLoginShell({ env, exec })).toBe("/custom/bin");
|
||||
expect(getShellPathFromLoginShell({ env, exec, platform: "linux" })).toBe("/custom/bin");
|
||||
expect(getShellPathFromLoginShell({ env, exec, platform: "linux" })).toBe("/custom/bin");
|
||||
expect(exec).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("returns null on exec failure", () => {
|
||||
if (process.platform === "win32") {
|
||||
return;
|
||||
}
|
||||
const exec = vi.fn(() => {
|
||||
throw new Error("boom");
|
||||
});
|
||||
const result = getShellPathFromLoginShell({ env: { SHELL: "/bin/sh" }, exec });
|
||||
const result = getShellPathFromLoginShell({
|
||||
env: { SHELL: "/bin/sh" },
|
||||
exec,
|
||||
platform: "linux",
|
||||
});
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user