fix(cli): disable source checkout compile cache

This commit is contained in:
Peter Steinberger
2026-04-27 23:27:59 +01:00
parent 6e77c10c6c
commit 36d3722a96
6 changed files with 401 additions and 11 deletions

View File

@@ -19,6 +19,37 @@ async function addSourceTreeMarker(fixtureRoot: string): Promise<void> {
await fs.writeFile(path.join(fixtureRoot, "src", "entry.ts"), "export {};\n", "utf8");
}
async function addGitMarker(fixtureRoot: string): Promise<void> {
await fs.writeFile(path.join(fixtureRoot, ".git"), "gitdir: .git/worktrees/openclaw\n", "utf8");
}
async function addCompileCacheProbe(fixtureRoot: string): Promise<void> {
await fs.writeFile(
path.join(fixtureRoot, "dist", "entry.js"),
[
'import module from "node:module";',
"process.stdout.write(",
' `${module.getCompileCacheDir?.() ? "cache:enabled" : "cache:disabled"};respawn:${process.env.OPENCLAW_SOURCE_COMPILE_CACHE_RESPAWNED ?? "0"}`',
");",
].join("\n"),
"utf8",
);
}
function launcherEnv(extra: NodeJS.ProcessEnv = {}): NodeJS.ProcessEnv {
const env = { ...process.env, ...extra };
delete env.NODE_COMPILE_CACHE;
delete env.NODE_DISABLE_COMPILE_CACHE;
for (const [key, value] of Object.entries(extra)) {
if (value === undefined) {
delete env[key];
} else {
env[key] = value;
}
}
return env;
}
describe("openclaw launcher", () => {
const fixtureRoots: string[] = [];
@@ -36,6 +67,7 @@ describe("openclaw launcher", () => {
const result = spawnSync(process.execPath, [path.join(fixtureRoot, "openclaw.mjs"), "--help"], {
cwd: fixtureRoot,
env: launcherEnv(),
encoding: "utf8",
});
@@ -49,6 +81,7 @@ describe("openclaw launcher", () => {
const result = spawnSync(process.execPath, [path.join(fixtureRoot, "openclaw.mjs"), "--help"], {
cwd: fixtureRoot,
env: launcherEnv(),
encoding: "utf8",
});
@@ -62,6 +95,7 @@ describe("openclaw launcher", () => {
const result = spawnSync(process.execPath, [path.join(fixtureRoot, "openclaw.mjs"), "--help"], {
cwd: fixtureRoot,
env: launcherEnv(),
encoding: "utf8",
});
@@ -71,4 +105,89 @@ describe("openclaw launcher", () => {
expect(result.stderr).toContain("pnpm install && pnpm build");
expect(result.stderr).toContain("github:openclaw/openclaw#<ref>");
});
it("keeps compile cache off for source-checkout launchers", async () => {
const fixtureRoot = await makeLauncherFixture(fixtureRoots);
await addSourceTreeMarker(fixtureRoot);
await addCompileCacheProbe(fixtureRoot);
const result = spawnSync(process.execPath, [path.join(fixtureRoot, "openclaw.mjs")], {
cwd: fixtureRoot,
env: launcherEnv(),
encoding: "utf8",
});
expect(result.status).toBe(0);
expect(result.stdout).toBe("cache:disabled;respawn:0");
});
it("respawns source-checkout launchers without inherited NODE_COMPILE_CACHE", async () => {
const fixtureRoot = await makeLauncherFixture(fixtureRoots);
await addGitMarker(fixtureRoot);
await addCompileCacheProbe(fixtureRoot);
const result = spawnSync(process.execPath, [path.join(fixtureRoot, "openclaw.mjs")], {
cwd: fixtureRoot,
env: launcherEnv({
NODE_COMPILE_CACHE: path.join(fixtureRoot, ".node-compile-cache"),
}),
encoding: "utf8",
});
expect(result.status).toBe(0);
expect(result.stdout).toBe("cache:disabled;respawn:1");
});
it.runIf(process.platform !== "win32")(
"respawns symlinked source-checkout launchers without inherited NODE_COMPILE_CACHE",
async () => {
const fixtureRoot = await makeLauncherFixture(fixtureRoots);
await addGitMarker(fixtureRoot);
await addCompileCacheProbe(fixtureRoot);
const linkParent = makeTempDir(fixtureRoots, "openclaw-launcher-link-");
const linkedRoot = path.join(linkParent, "openclaw-linked");
await fs.symlink(fixtureRoot, linkedRoot, "dir");
const result = spawnSync(process.execPath, [path.join(linkedRoot, "openclaw.mjs")], {
cwd: linkParent,
env: launcherEnv({
NODE_COMPILE_CACHE: path.join(linkParent, ".node-compile-cache"),
}),
encoding: "utf8",
});
expect(result.status).toBe(0);
expect(result.stdout).toBe("cache:disabled;respawn:1");
},
);
it("does not respawn packaged launchers when NODE_COMPILE_CACHE is configured", async () => {
const fixtureRoot = await makeLauncherFixture(fixtureRoots);
await addCompileCacheProbe(fixtureRoot);
const result = spawnSync(process.execPath, [path.join(fixtureRoot, "openclaw.mjs")], {
cwd: fixtureRoot,
env: launcherEnv({
NODE_COMPILE_CACHE: path.join(fixtureRoot, ".node-compile-cache"),
}),
encoding: "utf8",
});
expect(result.status).toBe(0);
expect(result.stdout).toBe("cache:enabled;respawn:0");
});
it("enables compile cache for packaged launchers", async () => {
const fixtureRoot = await makeLauncherFixture(fixtureRoots);
await addCompileCacheProbe(fixtureRoot);
const result = spawnSync(process.execPath, [path.join(fixtureRoot, "openclaw.mjs")], {
cwd: fixtureRoot,
env: launcherEnv(),
encoding: "utf8",
});
expect(result.status).toBe(0);
expect(result.stdout).toBe("cache:enabled;respawn:0");
});
});