From 93cfa4645498df396764df462a206f68151c19c5 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 9 May 2026 10:13:16 +0100 Subject: [PATCH] test: dedupe postinstall missing path assertions --- .../postinstall-bundled-plugins.test.ts | 72 +++++++++---------- 1 file changed, 33 insertions(+), 39 deletions(-) diff --git a/test/scripts/postinstall-bundled-plugins.test.ts b/test/scripts/postinstall-bundled-plugins.test.ts index 073dfa967d2..b4baee0048c 100644 --- a/test/scripts/postinstall-bundled-plugins.test.ts +++ b/test/scripts/postinstall-bundled-plugins.test.ts @@ -30,6 +30,10 @@ async function expectPathExists(filePath: string) { await expect(fs.access(filePath)).resolves.toBeUndefined(); } +async function expectPathMissing(filePath: string) { + await expect(fs.access(filePath)).rejects.toHaveProperty("code", "ENOENT"); +} + async function writePluginPackage( extensionsDir: string, pluginId: string, @@ -242,9 +246,7 @@ describe("bundled plugin postinstall", () => { log: { log: vi.fn(), warn: vi.fn() }, }); - await expect(fs.stat(path.join(extensionsDir, "acpx", "node_modules"))).rejects.toMatchObject({ - code: "ENOENT", - }); + await expectPathMissing(path.join(extensionsDir, "acpx", "node_modules")); }); it("keeps source-checkout prune non-fatal", async () => { @@ -453,7 +455,7 @@ describe("bundled plugin postinstall", () => { ).toEqual(["dist/channel-CJUAgRQR.js"]); await expectPathExists(currentFile); - await expect(fs.stat(staleFile)).rejects.toMatchObject({ code: "ENOENT" }); + await expectPathMissing(staleFile); }); it("prunes legacy plugin runtime deps state during packaged postinstall", async () => { @@ -514,11 +516,11 @@ describe("bundled plugin postinstall", () => { log, }); - await expect(fs.stat(defaultLegacyRoot)).rejects.toMatchObject({ code: "ENOENT" }); - await expect(fs.stat(oldBrandLegacyRoot)).rejects.toMatchObject({ code: "ENOENT" }); - await expect(fs.stat(overrideLegacyRoot)).rejects.toMatchObject({ code: "ENOENT" }); - await expect(fs.stat(systemLegacyRoot)).rejects.toMatchObject({ code: "ENOENT" }); - await expect(fs.lstat(legacySymlink)).rejects.toMatchObject({ code: "ENOENT" }); + await expectPathMissing(defaultLegacyRoot); + await expectPathMissing(oldBrandLegacyRoot); + await expectPathMissing(overrideLegacyRoot); + await expectPathMissing(systemLegacyRoot); + await expectPathMissing(legacySymlink); await expectPathExists(thirdPartyNodeModules); expect(log.warn).not.toHaveBeenCalled(); expect(log.log).toHaveBeenCalledWith( @@ -555,8 +557,8 @@ describe("bundled plugin postinstall", () => { log, }); - await expect(fs.lstat(slackLink)).rejects.toMatchObject({ code: "ENOENT" }); - await expect(fs.stat(legacyRuntimeRoot)).rejects.toMatchObject({ code: "ENOENT" }); + await expectPathMissing(slackLink); + await expectPathMissing(legacyRuntimeRoot); expect(log.warn).not.toHaveBeenCalled(); expect(log.log).toHaveBeenCalledWith( expect.stringContaining("[postinstall] pruned legacy plugin runtime deps symlinks:"), @@ -625,7 +627,7 @@ describe("bundled plugin postinstall", () => { ).toEqual(["dist/memory-state-old.js"]); await expectPathExists(importedChunk); - await expect(fs.stat(staleFile)).rejects.toMatchObject({ code: "ENOENT" }); + await expectPathMissing(staleFile); }); it("does not abort dist pruning when a listed chunk disappears before import expansion", async () => { @@ -653,7 +655,7 @@ describe("bundled plugin postinstall", () => { }), ).toEqual(["dist/stale.js"]); - await expect(fs.stat(staleFile)).rejects.toMatchObject({ code: "ENOENT" }); + await expectPathMissing(staleFile); }); it("prunes stale private QA files without restoring compat sidecars", async () => { @@ -678,20 +680,20 @@ describe("bundled plugin postinstall", () => { log: { log: vi.fn(), warn: vi.fn() }, }); - await expect(fs.stat(stalePackage)).rejects.toMatchObject({ code: "ENOENT" }); - await expect(fs.stat(staleManifest)).rejects.toMatchObject({ code: "ENOENT" }); - await expect( - fs.stat(path.join(packageRoot, "dist", "extensions", "qa-channel", "runtime-api.js")), - ).rejects.toMatchObject({ code: "ENOENT" }); - await expect( - fs.stat(path.join(packageRoot, "dist", "extensions", "qa-channel", "package.json")), - ).rejects.toMatchObject({ code: "ENOENT" }); - await expect( - fs.stat(path.join(packageRoot, "dist", "extensions", "qa-channel", "openclaw.plugin.json")), - ).rejects.toMatchObject({ code: "ENOENT" }); - await expect( - fs.stat(path.join(packageRoot, "dist", "extensions", "qa-lab", "runtime-api.js")), - ).rejects.toMatchObject({ code: "ENOENT" }); + await expectPathMissing(stalePackage); + await expectPathMissing(staleManifest); + await expectPathMissing( + path.join(packageRoot, "dist", "extensions", "qa-channel", "runtime-api.js"), + ); + await expectPathMissing( + path.join(packageRoot, "dist", "extensions", "qa-channel", "package.json"), + ); + await expectPathMissing( + path.join(packageRoot, "dist", "extensions", "qa-channel", "openclaw.plugin.json"), + ); + await expectPathMissing( + path.join(packageRoot, "dist", "extensions", "qa-lab", "runtime-api.js"), + ); }); it("keeps packaged postinstall non-fatal when the dist inventory is missing", async () => { @@ -842,15 +844,9 @@ describe("bundled plugin postinstall", () => { log: { log: vi.fn(), warn: vi.fn() }, }), ).toEqual(["dist/stale-runtime.js"]); - await expect( - fs.stat(path.join(packageRoot, "dist", "extensions", "slack", "node_modules")), - ).rejects.toMatchObject({ code: "ENOENT" }); - await expect(fs.stat(path.dirname(installStageFile))).rejects.toMatchObject({ - code: "ENOENT", - }); - await expect(fs.stat(path.dirname(retryInstallStageFile))).rejects.toMatchObject({ - code: "ENOENT", - }); + await expectPathMissing(path.join(packageRoot, "dist", "extensions", "slack", "node_modules")); + await expectPathMissing(path.dirname(installStageFile)); + await expectPathMissing(path.dirname(retryInstallStageFile)); }); it("unlinks stale files instead of recursive pruning them", () => { @@ -899,9 +895,7 @@ describe("bundled plugin postinstall", () => { pruneBundledPluginSourceNodeModules({ extensionsDir }); - await expect(fs.stat(path.join(extensionsDir, "acpx", "node_modules"))).rejects.toMatchObject({ - code: "ENOENT", - }); + await expectPathMissing(path.join(extensionsDir, "acpx", "node_modules")); await expectPathExists(path.join(extensionsDir, "fixtures", "node_modules")); });