From 1077cb74f9883e7e1f052805b0bb38ef3fceda9e Mon Sep 17 00:00:00 2001 From: Ayaan Zaidi Date: Wed, 15 Apr 2026 09:52:46 +0530 Subject: [PATCH] test(postinstall): use real dist inventory fixtures --- scripts/postinstall-bundled-plugins.mjs | 2 +- .../postinstall-bundled-plugins.test.ts | 19 +++---------------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/scripts/postinstall-bundled-plugins.mjs b/scripts/postinstall-bundled-plugins.mjs index 6d325f67f89..20d423c18f8 100644 --- a/scripts/postinstall-bundled-plugins.mjs +++ b/scripts/postinstall-bundled-plugins.mjs @@ -30,7 +30,7 @@ const __dirname = dirname(fileURLToPath(import.meta.url)); const DEFAULT_EXTENSIONS_DIR = join(__dirname, "..", "dist", "extensions"); const DEFAULT_PACKAGE_ROOT = join(__dirname, ".."); const DISABLE_POSTINSTALL_ENV = "OPENCLAW_DISABLE_BUNDLED_PLUGIN_POSTINSTALL"; -const DIST_INVENTORY_PATH = join("dist", "postinstall-inventory.json"); +const DIST_INVENTORY_PATH = "dist/postinstall-inventory.json"; const BAILEYS_MEDIA_FILE = join( "node_modules", "@whiskeysockets", diff --git a/test/scripts/postinstall-bundled-plugins.test.ts b/test/scripts/postinstall-bundled-plugins.test.ts index a8f4b96355f..a3278b99968 100644 --- a/test/scripts/postinstall-bundled-plugins.test.ts +++ b/test/scripts/postinstall-bundled-plugins.test.ts @@ -8,6 +8,7 @@ import { pruneBundledPluginSourceNodeModules, runBundledPluginPostinstall, } from "../../scripts/postinstall-bundled-plugins.mjs"; +import { writePackageDistInventory } from "../../src/infra/package-dist-inventory.ts"; import { createScriptTestHarness } from "./test-helpers.js"; const { createTempDirAsync } = createScriptTestHarness(); @@ -34,16 +35,8 @@ async function writePluginPackage( path.basename(path.dirname(extensionsDir)) === "dist" ? path.dirname(path.dirname(extensionsDir)) : path.dirname(extensionsDir); - const distRoot = path.join(packageRoot, "dist"); try { - const distEntries = await fs.readdir(distRoot, { recursive: true }); - await writeDistInventory( - packageRoot, - distEntries - .filter((entry) => typeof entry === "string") - .map((entry) => path.join("dist", entry).replace(/\\/g, "/")) - .toSorted((left, right) => left.localeCompare(right)), - ); + await writePackageDistInventory(packageRoot); } catch (error) { if ((error as NodeJS.ErrnoException).code !== "ENOENT") { throw error; @@ -51,12 +44,6 @@ async function writePluginPackage( } } -async function writeDistInventory(packageRoot: string, files: string[]) { - const inventoryPath = path.join(packageRoot, "dist", "postinstall-inventory.json"); - await fs.mkdir(path.dirname(inventoryPath), { recursive: true }); - await fs.writeFile(inventoryPath, `${JSON.stringify(files, null, 2)}\n`); -} - describe("bundled plugin postinstall", () => { function createNpmInstallArgs(...packages: string[]) { return [ @@ -213,8 +200,8 @@ describe("bundled plugin postinstall", () => { const staleFile = path.join(packageRoot, "dist", "channel-CJUAgRQR.js"); await fs.mkdir(path.dirname(currentFile), { recursive: true }); await fs.writeFile(currentFile, "export {};\n"); + await writePackageDistInventory(packageRoot); await fs.writeFile(staleFile, "export {};\n"); - await writeDistInventory(packageRoot, ["dist/channel-BOa4MfoC.js"]); expect( pruneInstalledPackageDist({