fix(ci): clean check-changed pnpm shim temp dirs

This commit is contained in:
Vincent Koc
2026-06-01 16:16:21 +02:00
parent 4253517070
commit a4847297b8
2 changed files with 53 additions and 8 deletions

View File

@@ -1,4 +1,12 @@
import { accessSync, chmodSync, constants, existsSync, mkdtempSync, writeFileSync } from "node:fs";
import {
accessSync,
chmodSync,
constants,
existsSync,
mkdtempSync,
rmSync,
writeFileSync,
} from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
import { performance } from "node:perf_hooks";
@@ -36,6 +44,7 @@ const LINTABLE_CORE_PATH_RE = /^(?:src|ui|packages)\/.+\.[cm]?[jt]sx?$/u;
const CORE_LINT_OPTIMIZATION_NEUTRAL_PATH_RE =
/^(?:scripts|test\/scripts)\/|^\.github\/workflows\/ci\.yml$/u;
let corepackPnpmShimDir;
let corepackPnpmShimCleanupRegistered = false;
export function createChangedCheckChildEnv(baseEnv = process.env) {
const resolvedBaseEnv = resolveLocalHeavyCheckEnv(baseEnv);
@@ -464,9 +473,27 @@ function ensureCorepackPnpmShimDir() {
chmodSync(pnpmPath, 0o755);
writeFileSync(path.join(dir, "pnpm.cmd"), "@echo off\r\ncorepack pnpm %*\r\n", "utf8");
corepackPnpmShimDir = dir;
registerCorepackPnpmShimCleanup();
return dir;
}
function registerCorepackPnpmShimCleanup() {
if (corepackPnpmShimCleanupRegistered) {
return;
}
corepackPnpmShimCleanupRegistered = true;
process.once("exit", cleanupCorepackPnpmShimDir);
}
export function cleanupCorepackPnpmShimDir() {
if (!corepackPnpmShimDir) {
return;
}
const dir = corepackPnpmShimDir;
corepackPnpmShimDir = undefined;
rmSync(dir, { recursive: true, force: true });
}
async function runCommand(command, timings) {
const startedAt = performance.now();
console.error(`\n[check:changed] ${command.name}`);

View File

@@ -1,5 +1,5 @@
import { execFileSync, spawnSync } from "node:child_process";
import { mkdirSync, unlinkSync, writeFileSync } from "node:fs";
import { existsSync, mkdirSync, unlinkSync, writeFileSync } from "node:fs";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import {
@@ -11,6 +11,7 @@ import {
} from "../../scripts/changed-lanes.mjs";
import {
buildChangedCheckCrabboxArgs,
cleanupCorepackPnpmShimDir,
createChangedCheckChildEnv,
createChangedCheckPlan,
createPnpmManagedCommand,
@@ -71,6 +72,7 @@ function parseChangedLaneOutput(output: string): {
}
afterEach(() => {
cleanupCorepackPnpmShimDir();
cleanupTempDirs(tempDirs);
});
@@ -228,14 +230,15 @@ describe("scripts/changed-lanes", () => {
mkdirSync(path.join(dir, "src"), { recursive: true });
writeFileSync(path.join(dir, "src", "feature.ts"), "export const value = 1;\n", "utf8");
const normalPaths = listChangedPathsFromGit({ base: "origin/main", cwd: dir });
expect(normalPaths.length).toBeGreaterThan(200);
expect(normalPaths).toContain("baseline-0.txt");
expect(normalPaths).toContain("src/feature.ts");
const previousRawSync = process.env.OPENCLAW_CHANGED_LANES_RAW_SYNC;
process.env.OPENCLAW_CHANGED_LANES_RAW_SYNC = "1";
delete process.env.OPENCLAW_CHANGED_LANES_RAW_SYNC;
try {
const normalPaths = listChangedPathsFromGit({ base: "origin/main", cwd: dir });
expect(normalPaths.length).toBeGreaterThan(200);
expect(normalPaths).toContain("baseline-0.txt");
expect(normalPaths).toContain("src/feature.ts");
process.env.OPENCLAW_CHANGED_LANES_RAW_SYNC = "1";
expect(listChangedPathsFromGit({ base: "origin/main", cwd: dir })).toEqual([
"src/feature.ts",
]);
@@ -501,6 +504,21 @@ describe("scripts/changed-lanes", () => {
expect(command.args).toEqual(["pnpm", "check:no-conflict-markers"]);
});
it("cleans CI Corepack pnpm shim temp dirs", () => {
const command = createPnpmManagedCommand(
{ name: "conflict markers", args: ["check:no-conflict-markers"] },
{ CI: "1", PATH: "/usr/bin" },
);
const [shimDir] = String(command.env?.PATH ?? "").split(path.delimiter);
expect(path.basename(shimDir)).toMatch(/^openclaw-corepack-pnpm-/u);
expect(existsSync(path.join(shimDir, "pnpm"))).toBe(true);
cleanupCorepackPnpmShimDir();
expect(existsSync(shimDir)).toBe(false);
});
it("keeps local changed-check children on the repo pnpm shim", () => {
const command = createPnpmManagedCommand(
{ name: "conflict markers", args: ["check:no-conflict-markers"] },