mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-28 17:01:53 +03:00
perf(test): speed up path env suite
This commit is contained in:
+41
-37
@@ -1,42 +1,49 @@
|
|||||||
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", () => {
|
||||||
it("prepends the bundled app bin dir when a sibling openclaw exists", async () => {
|
let fixtureRoot = "";
|
||||||
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-path-"));
|
let fixtureCount = 0;
|
||||||
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);
|
|
||||||
|
|
||||||
const originalPath = process.env.PATH;
|
beforeAll(async () => {
|
||||||
const originalFlag = process.env.OPENCLAW_PATH_BOOTSTRAPPED;
|
fixtureRoot = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-path-"));
|
||||||
process.env.PATH = "/usr/bin";
|
});
|
||||||
delete process.env.OPENCLAW_PATH_BOOTSTRAPPED;
|
|
||||||
try {
|
afterAll(async () => {
|
||||||
ensureOpenClawCliOnPath({
|
await fs.rm(fixtureRoot, { recursive: true, force: true });
|
||||||
execPath: cliPath,
|
});
|
||||||
cwd: tmp,
|
|
||||||
homeDir: tmp,
|
it("prepends the bundled app bin dir when a sibling openclaw exists", async () => {
|
||||||
platform: "darwin",
|
const tmp = path.join(fixtureRoot, `case-${fixtureCount++}`);
|
||||||
});
|
const appBinDir = path.join(tmp, "AppBin");
|
||||||
const updated = process.env.PATH ?? "";
|
await fs.mkdir(appBinDir, { recursive: true });
|
||||||
expect(updated.split(path.delimiter)[0]).toBe(appBinDir);
|
const cliPath = path.join(appBinDir, "openclaw");
|
||||||
} finally {
|
await fs.writeFile(cliPath, "#!/bin/sh\necho ok\n", "utf-8");
|
||||||
process.env.PATH = originalPath;
|
await fs.chmod(cliPath, 0o755);
|
||||||
if (originalFlag === undefined) {
|
|
||||||
delete process.env.OPENCLAW_PATH_BOOTSTRAPPED;
|
const originalPath = process.env.PATH;
|
||||||
} else {
|
const originalFlag = process.env.OPENCLAW_PATH_BOOTSTRAPPED;
|
||||||
process.env.OPENCLAW_PATH_BOOTSTRAPPED = originalFlag;
|
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 {
|
} 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 () => {
|
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 });
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user