diff --git a/openclaw.mjs b/openclaw.mjs index 1ceda9c2246..aae262e5b57 100755 --- a/openclaw.mjs +++ b/openclaw.mjs @@ -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"; diff --git a/test/openclaw-launcher.e2e.test.ts b/test/openclaw-launcher.e2e.test.ts index 8778c58731b..59ab00993f9 100644 --- a/test/openclaw-launcher.e2e.test.ts +++ b/test/openclaw-launcher.e2e.test.ts @@ -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);