fix: release local heavy-check locks on success

This commit is contained in:
Tak Hoffman
2026-04-10 17:03:52 -05:00
parent 8b7ba0e481
commit f16a66fa43
5 changed files with 59 additions and 6 deletions

View File

@@ -133,6 +133,9 @@ export function acquireLocalHeavyCheckLockSync(params) {
let lastProgressAt = 0;
fs.mkdirSync(locksDir, { recursive: true });
if (!params.lockName) {
cleanupLegacyLockDirs(locksDir, staleLockMs);
}
for (;;) {
try {
@@ -210,6 +213,20 @@ export function resolveGitCommonDir(cwd) {
return path.join(cwd, ".git");
}
function cleanupLegacyLockDirs(locksDir, staleLockMs) {
for (const legacyLockName of ["test"]) {
const legacyLockDir = path.join(locksDir, `${legacyLockName}.lock`);
if (!fs.existsSync(legacyLockDir)) {
continue;
}
const owner = readOwnerFile(path.join(legacyLockDir, "owner.json"));
if (shouldReclaimLock({ owner, lockDir: legacyLockDir, staleLockMs })) {
fs.rmSync(legacyLockDir, { recursive: true, force: true });
}
}
}
function insertBeforeSeparator(args, ...items) {
if (items.length > 0 && hasFlag(args, items[0])) {
return;

View File

@@ -18,6 +18,7 @@ export function runExtensionOxlint(params) {
});
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), params.tempDirPrefix));
const tempConfigPath = path.join(tempDir, "oxlint.json");
let exitCode = 0;
try {
prepareExtensionPackageBoundaryArtifacts(repoRoot);
@@ -45,11 +46,13 @@ export function runExtensionOxlint(params) {
throw result.error;
}
process.exit(result.status ?? 1);
exitCode = result.status ?? 1;
} finally {
fs.rmSync(tempDir, { recursive: true, force: true });
releaseLock();
}
process.exitCode = exitCode;
}
function prepareExtensionPackageBoundaryArtifacts(repoRoot) {
@@ -59,6 +62,7 @@ function prepareExtensionPackageBoundaryArtifacts(repoRoot) {
toolName: "extension-package-boundary-artifacts",
lockName: "extension-package-boundary-artifacts",
});
let exitCode = 0;
try {
const result = spawnSync(
@@ -75,12 +79,14 @@ function prepareExtensionPackageBoundaryArtifacts(repoRoot) {
throw result.error;
}
if ((result.status ?? 1) !== 0) {
process.exit(result.status ?? 1);
}
exitCode = result.status ?? 1;
} finally {
releaseLock();
}
if (exitCode !== 0) {
process.exitCode = exitCode;
}
}
function writeTempOxlintConfig(repoRoot, configPath) {

View File

@@ -25,7 +25,7 @@ try {
throw result.error;
}
process.exit(result.status ?? 1);
process.exitCode = result.status ?? 1;
} finally {
releaseLock();
}

View File

@@ -30,7 +30,7 @@ try {
throw result.error;
}
process.exit(result.status ?? 1);
process.exitCode = result.status ?? 1;
} finally {
releaseLock();
}

View File

@@ -197,4 +197,34 @@ describe("local-heavy-check-runtime", () => {
release();
expect(fs.existsSync(lockDir)).toBe(false);
});
it("cleans up stale legacy test locks when acquiring the shared heavy-check lock", () => {
const cwd = createTempDir("openclaw-local-heavy-check-legacy-");
const commonDir = path.join(cwd, ".git");
const locksDir = path.join(commonDir, "openclaw-local-checks");
const legacyLockDir = path.join(locksDir, "test.lock");
const heavyCheckLockDir = path.join(locksDir, "heavy-check.lock");
fs.mkdirSync(legacyLockDir, { recursive: true });
fs.writeFileSync(
path.join(legacyLockDir, "owner.json"),
`${JSON.stringify({
pid: 999_999_999,
tool: "test",
cwd,
})}\n`,
"utf8",
);
const release = acquireLocalHeavyCheckLockSync({
cwd,
env: makeEnv(),
toolName: "oxlint",
});
expect(fs.existsSync(legacyLockDir)).toBe(false);
expect(fs.existsSync(heavyCheckLockDir)).toBe(true);
release();
expect(fs.existsSync(heavyCheckLockDir)).toBe(false);
});
});