fix: environment edge case launcher regression (#74696)

Co-authored-by: openclaw-clawsweeper[bot] <280122609+openclaw-clawsweeper[bot]@users.noreply.github.com>
This commit is contained in:
clawsweeper[bot]
2026-04-29 22:39:12 -07:00
committed by GitHub
parent 3c9437ae54
commit 9177fab07b
2 changed files with 27 additions and 1 deletions

View File

@@ -47,7 +47,7 @@ const isSourceCheckoutLauncher = () =>
const isNodeCompileCacheDisabled = () => process.env.NODE_DISABLE_COMPILE_CACHE !== undefined;
const isNodeCompileCacheRequested = () =>
process.env.NODE_COMPILE_CACHE !== undefined && !isNodeCompileCacheDisabled();
Boolean(process.env.NODE_COMPILE_CACHE) && !isNodeCompileCacheDisabled();
const sanitizeCompileCachePathSegment = (value) => {
const normalized = value.replace(/[^A-Za-z0-9._-]+/g, "_").replace(/^_+|_+$/g, "");
return normalized.length > 0 ? normalized : "unknown";

View File

@@ -201,6 +201,32 @@ describe("openclaw launcher", () => {
expect(result.stdout).toContain(path.join(".node-compile-cache", "openclaw", "2026.4.29"));
});
it("falls back to the default packaged launcher compile cache when NODE_COMPILE_CACHE is empty", async () => {
const fixtureRoot = await makeLauncherFixture(fixtureRoots);
const runCwd = makeTempDir(fixtureRoots, "openclaw-launcher-cwd-");
await fs.writeFile(path.join(fixtureRoot, "package.json"), '{"version":"2026.4.29"}\n');
await fs.writeFile(
path.join(fixtureRoot, "dist", "entry.js"),
[
'import module from "node:module";',
'process.stdout.write(module.getCompileCacheDir?.() ?? "cache:disabled");',
].join("\n"),
"utf8",
);
const result = spawnSync(process.execPath, [path.join(fixtureRoot, "openclaw.mjs")], {
cwd: runCwd,
env: launcherEnv({
NODE_COMPILE_CACHE: "",
}),
encoding: "utf8",
});
expect(result.status).toBe(0);
expect(result.stdout).toContain(path.join("node-compile-cache", "openclaw", "2026.4.29"));
expect(result.stdout).not.toContain(path.join(runCwd, "openclaw"));
});
it("enables compile cache for packaged launchers", async () => {
const fixtureRoot = await makeLauncherFixture(fixtureRoots);
await addCompileCacheProbe(fixtureRoot);