perf(test): speed up path env suite

This commit is contained in:
Peter Steinberger
2026-02-14 22:36:57 +00:00
parent 110cc5d791
commit 6bc5987d6c
+16 -12
View File
@@ -1,13 +1,23 @@
import fs from "node:fs/promises"; import fs from "node:fs/promises";
import os from "node:os"; import os from "node:os";
import path from "node:path"; 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"; import { ensureOpenClawCliOnPath } from "./path-env.js";
describe("ensureOpenClawCliOnPath", () => { describe("ensureOpenClawCliOnPath", () => {
let fixtureRoot = "";
let fixtureCount = 0;
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 () => { it("prepends the bundled app bin dir when a sibling openclaw exists", async () => {
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-path-")); const tmp = path.join(fixtureRoot, `case-${fixtureCount++}`);
try {
const appBinDir = path.join(tmp, "AppBin"); const appBinDir = path.join(tmp, "AppBin");
await fs.mkdir(appBinDir, { recursive: true }); await fs.mkdir(appBinDir, { recursive: true });
const cliPath = path.join(appBinDir, "openclaw"); const cliPath = path.join(appBinDir, "openclaw");
@@ -35,9 +45,6 @@ describe("ensureOpenClawCliOnPath", () => {
process.env.OPENCLAW_PATH_BOOTSTRAPPED = originalFlag; process.env.OPENCLAW_PATH_BOOTSTRAPPED = originalFlag;
} }
} }
} finally {
await fs.rm(tmp, { recursive: true, force: true });
}
}); });
it("is idempotent", () => { it("is idempotent", () => {
@@ -64,7 +71,7 @@ describe("ensureOpenClawCliOnPath", () => {
}); });
it("prepends mise shims when available", async () => { 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 originalPath = process.env.PATH;
const originalFlag = process.env.OPENCLAW_PATH_BOOTSTRAPPED; const originalFlag = process.env.OPENCLAW_PATH_BOOTSTRAPPED;
const originalMiseDataDir = process.env.MISE_DATA_DIR; const originalMiseDataDir = process.env.MISE_DATA_DIR;
@@ -107,12 +114,11 @@ describe("ensureOpenClawCliOnPath", () => {
} else { } else {
process.env.MISE_DATA_DIR = originalMiseDataDir; 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 () => { 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 originalPath = process.env.PATH;
const originalFlag = process.env.OPENCLAW_PATH_BOOTSTRAPPED; const originalFlag = process.env.OPENCLAW_PATH_BOOTSTRAPPED;
try { try {
@@ -162,12 +168,11 @@ describe("ensureOpenClawCliOnPath", () => {
} else { } else {
process.env.OPENCLAW_PATH_BOOTSTRAPPED = originalFlag; process.env.OPENCLAW_PATH_BOOTSTRAPPED = originalFlag;
} }
await fs.rm(tmp, { recursive: true, force: true });
} }
}); });
it("prepends Linuxbrew dirs when present", async () => { 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 originalPath = process.env.PATH;
const originalFlag = process.env.OPENCLAW_PATH_BOOTSTRAPPED; const originalFlag = process.env.OPENCLAW_PATH_BOOTSTRAPPED;
const originalHomebrewPrefix = process.env.HOMEBREW_PREFIX; const originalHomebrewPrefix = process.env.HOMEBREW_PREFIX;
@@ -221,7 +226,6 @@ describe("ensureOpenClawCliOnPath", () => {
} else { } else {
process.env.XDG_BIN_HOME = originalXdgBinHome; process.env.XDG_BIN_HOME = originalXdgBinHome;
} }
await fs.rm(tmp, { recursive: true, force: true });
} }
}); });
}); });