perf: speed plugin contract tests and fix ci

This commit is contained in:
Peter Steinberger
2026-04-29 05:17:23 +01:00
parent 9ae629052a
commit 203213028e
6 changed files with 49 additions and 8 deletions

View File

@@ -420,6 +420,37 @@ describe("stageBundledPluginRuntimeDeps", () => {
expect(fs.existsSync(path.join(targetPath, "owner.json"))).toBe(false);
});
it("retries transient backup cleanup during atomic replace", () => {
const parentDir = createTempDir("openclaw-runtime-deps-replace-");
const targetPath = path.join(parentDir, "node_modules");
const sourcePath = path.join(parentDir, "source-node_modules");
fs.mkdirSync(targetPath, { recursive: true });
fs.writeFileSync(path.join(targetPath, "marker.txt"), "original\n", "utf8");
fs.mkdirSync(sourcePath, { recursive: true });
fs.writeFileSync(path.join(sourcePath, "marker.txt"), "replacement\n", "utf8");
const realRmSync = fs.rmSync.bind(fs);
let transientFailures = 0;
vi.spyOn(fs, "rmSync").mockImplementation((target, options) => {
const targetString = String(target);
if (
targetString.includes(`${path.sep}.openclaw-runtime-deps-backup-`) &&
transientFailures < 2
) {
transientFailures += 1;
const error = new Error("transient backup cleanup failure") as NodeJS.ErrnoException;
error.code = "ENOTEMPTY";
throw error;
}
return realRmSync(target, options);
});
stageBundledPluginRuntimeDepsTesting.replaceDirAtomically(targetPath, sourcePath);
expect(transientFailures).toBe(2);
expect(fs.readFileSync(path.join(targetPath, "marker.txt"), "utf8")).toBe("replacement\n");
});
it("restages when installed root runtime dependency contents change", () => {
const { pluginDir, repoRoot } = createBundledPluginFixture({
packageJson: {