From ca71b5cc51b60706f3833ea16d9814204bf45016 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Thu, 19 Feb 2026 07:49:43 +0000 Subject: [PATCH] test(shell-env): dedupe repeated login-shell path lookups --- src/infra/shell-env.test.ts | 41 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/infra/shell-env.test.ts b/src/infra/shell-env.test.ts index 0869dfec4f..4fcb41b538 100644 --- a/src/infra/shell-env.test.ts +++ b/src/infra/shell-env.test.ts @@ -8,6 +8,23 @@ import { } from "./shell-env.js"; describe("shell env fallback", () => { + function getShellPathTwice(params: { + exec: Parameters[0]["exec"]; + platform: NodeJS.Platform; + }) { + const first = getShellPathFromLoginShell({ + env: {} as NodeJS.ProcessEnv, + exec: params.exec, + platform: params.platform, + }); + const second = getShellPathFromLoginShell({ + env: {} as NodeJS.ProcessEnv, + exec: params.exec, + platform: params.platform, + }); + return { first, second }; + } + it("is disabled by default", () => { expect(shouldEnableShellEnvFallback({} as NodeJS.ProcessEnv)).toBe(false); expect(shouldEnableShellEnvFallback({ OPENCLAW_LOAD_SHELL_ENV: "0" })).toBe(false); @@ -78,13 +95,7 @@ describe("shell env fallback", () => { 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[0]["exec"], - platform: "linux", - }); - const second = getShellPathFromLoginShell({ - env: {} as NodeJS.ProcessEnv, + const { first, second } = getShellPathTwice({ exec: exec as unknown as Parameters[0]["exec"], platform: "linux", }); @@ -100,13 +111,7 @@ describe("shell env fallback", () => { throw new Error("exec failed"); }); - const first = getShellPathFromLoginShell({ - env: {} as NodeJS.ProcessEnv, - exec: exec as unknown as Parameters[0]["exec"], - platform: "linux", - }); - const second = getShellPathFromLoginShell({ - env: {} as NodeJS.ProcessEnv, + const { first, second } = getShellPathTwice({ exec: exec as unknown as Parameters[0]["exec"], platform: "linux", }); @@ -120,13 +125,7 @@ describe("shell env fallback", () => { 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[0]["exec"], - platform: "win32", - }); - const second = getShellPathFromLoginShell({ - env: {} as NodeJS.ProcessEnv, + const { first, second } = getShellPathTwice({ exec: exec as unknown as Parameters[0]["exec"], platform: "win32", });