mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 05:07:38 +00:00
refactor(infra): share shell env timeout normalization
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
getShellPathFromLoginShell,
|
||||
loadShellEnvFallback,
|
||||
resetShellPathCacheForTests,
|
||||
resolveShellEnvFallbackTimeoutMs,
|
||||
shouldEnableShellEnvFallback,
|
||||
} from "./shell-env.js";
|
||||
@@ -71,4 +73,42 @@ describe("shell env fallback", () => {
|
||||
expect(env.DISCORD_BOT_TOKEN).toBe("discord");
|
||||
expect(exec2).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("resolves PATH via login shell and caches it", () => {
|
||||
resetShellPathCacheForTests();
|
||||
const exec = vi.fn(() => Buffer.from("PATH=/usr/local/bin:/usr/bin\0HOME=/tmp\0"));
|
||||
|
||||
const first = getShellPathFromLoginShell({
|
||||
env: {} as NodeJS.ProcessEnv,
|
||||
exec: exec as unknown as Parameters<typeof getShellPathFromLoginShell>[0]["exec"],
|
||||
});
|
||||
const second = getShellPathFromLoginShell({
|
||||
env: {} as NodeJS.ProcessEnv,
|
||||
exec: exec as unknown as Parameters<typeof getShellPathFromLoginShell>[0]["exec"],
|
||||
});
|
||||
|
||||
expect(first).toBe("/usr/local/bin:/usr/bin");
|
||||
expect(second).toBe("/usr/local/bin:/usr/bin");
|
||||
expect(exec).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it("returns null on shell env read failure and caches null", () => {
|
||||
resetShellPathCacheForTests();
|
||||
const exec = vi.fn(() => {
|
||||
throw new Error("exec failed");
|
||||
});
|
||||
|
||||
const first = getShellPathFromLoginShell({
|
||||
env: {} as NodeJS.ProcessEnv,
|
||||
exec: exec as unknown as Parameters<typeof getShellPathFromLoginShell>[0]["exec"],
|
||||
});
|
||||
const second = getShellPathFromLoginShell({
|
||||
env: {} as NodeJS.ProcessEnv,
|
||||
exec: exec as unknown as Parameters<typeof getShellPathFromLoginShell>[0]["exec"],
|
||||
});
|
||||
|
||||
expect(first).toBeNull();
|
||||
expect(second).toBeNull();
|
||||
expect(exec).toHaveBeenCalledOnce();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user