From 6bc5987d6cc9933565a6867ebeab59a30a5a91fc Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 14 Feb 2026 22:36:57 +0000 Subject: [PATCH] perf(test): speed up path env suite --- src/infra/path-env.test.ts | 78 ++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/src/infra/path-env.test.ts b/src/infra/path-env.test.ts index 50d7ec3ac..0f3aed636 100644 --- a/src/infra/path-env.test.ts +++ b/src/infra/path-env.test.ts @@ -1,42 +1,49 @@ import fs from "node:fs/promises"; import os from "node:os"; import path from "node:path"; -import { describe, expect, it } from "vitest"; +import { afterAll, beforeAll, describe, expect, it } from "vitest"; import { ensureOpenClawCliOnPath } from "./path-env.js"; describe("ensureOpenClawCliOnPath", () => { - it("prepends the bundled app bin dir when a sibling openclaw exists", async () => { - const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-path-")); - try { - const appBinDir = path.join(tmp, "AppBin"); - await fs.mkdir(appBinDir, { recursive: true }); - const cliPath = path.join(appBinDir, "openclaw"); - await fs.writeFile(cliPath, "#!/bin/sh\necho ok\n", "utf-8"); - await fs.chmod(cliPath, 0o755); + let fixtureRoot = ""; + let fixtureCount = 0; - const originalPath = process.env.PATH; - const originalFlag = process.env.OPENCLAW_PATH_BOOTSTRAPPED; - process.env.PATH = "/usr/bin"; - delete process.env.OPENCLAW_PATH_BOOTSTRAPPED; - try { - ensureOpenClawCliOnPath({ - execPath: cliPath, - cwd: tmp, - homeDir: tmp, - platform: "darwin", - }); - const updated = process.env.PATH ?? ""; - expect(updated.split(path.delimiter)[0]).toBe(appBinDir); - } finally { - process.env.PATH = originalPath; - if (originalFlag === undefined) { - delete process.env.OPENCLAW_PATH_BOOTSTRAPPED; - } else { - process.env.OPENCLAW_PATH_BOOTSTRAPPED = originalFlag; - } - } + beforeAll(async () => { + fixtureRoot = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-path-")); + }); + + afterAll(async () => { + await fs.rm(fixtureRoot, { recursive: true, force: true }); + }); + + it("prepends the bundled app bin dir when a sibling openclaw exists", async () => { + const tmp = path.join(fixtureRoot, `case-${fixtureCount++}`); + const appBinDir = path.join(tmp, "AppBin"); + await fs.mkdir(appBinDir, { recursive: true }); + const cliPath = path.join(appBinDir, "openclaw"); + await fs.writeFile(cliPath, "#!/bin/sh\necho ok\n", "utf-8"); + await fs.chmod(cliPath, 0o755); + + const originalPath = process.env.PATH; + const originalFlag = process.env.OPENCLAW_PATH_BOOTSTRAPPED; + process.env.PATH = "/usr/bin"; + delete process.env.OPENCLAW_PATH_BOOTSTRAPPED; + try { + ensureOpenClawCliOnPath({ + execPath: cliPath, + cwd: tmp, + homeDir: tmp, + platform: "darwin", + }); + const updated = process.env.PATH ?? ""; + expect(updated.split(path.delimiter)[0]).toBe(appBinDir); } finally { - await fs.rm(tmp, { recursive: true, force: true }); + process.env.PATH = originalPath; + if (originalFlag === undefined) { + delete process.env.OPENCLAW_PATH_BOOTSTRAPPED; + } else { + process.env.OPENCLAW_PATH_BOOTSTRAPPED = originalFlag; + } } }); @@ -64,7 +71,7 @@ describe("ensureOpenClawCliOnPath", () => { }); it("prepends mise shims when available", async () => { - const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-path-")); + const tmp = path.join(fixtureRoot, `case-${fixtureCount++}`); const originalPath = process.env.PATH; const originalFlag = process.env.OPENCLAW_PATH_BOOTSTRAPPED; const originalMiseDataDir = process.env.MISE_DATA_DIR; @@ -107,12 +114,11 @@ describe("ensureOpenClawCliOnPath", () => { } else { process.env.MISE_DATA_DIR = originalMiseDataDir; } - await fs.rm(tmp, { recursive: true, force: true }); } }); it("only appends project-local node_modules/.bin when explicitly enabled", async () => { - const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-path-")); + const tmp = path.join(fixtureRoot, `case-${fixtureCount++}`); const originalPath = process.env.PATH; const originalFlag = process.env.OPENCLAW_PATH_BOOTSTRAPPED; try { @@ -162,12 +168,11 @@ describe("ensureOpenClawCliOnPath", () => { } else { process.env.OPENCLAW_PATH_BOOTSTRAPPED = originalFlag; } - await fs.rm(tmp, { recursive: true, force: true }); } }); it("prepends Linuxbrew dirs when present", async () => { - const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-path-")); + const tmp = path.join(fixtureRoot, `case-${fixtureCount++}`); const originalPath = process.env.PATH; const originalFlag = process.env.OPENCLAW_PATH_BOOTSTRAPPED; const originalHomebrewPrefix = process.env.HOMEBREW_PREFIX; @@ -221,7 +226,6 @@ describe("ensureOpenClawCliOnPath", () => { } else { process.env.XDG_BIN_HOME = originalXdgBinHome; } - await fs.rm(tmp, { recursive: true, force: true }); } }); });