From e57e54e591ad0dab67fc4c8c56712f4302e0559b Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 21 Apr 2026 09:34:33 +0100 Subject: [PATCH] fix: run packed bundled postinstall in release check --- scripts/postinstall-bundled-plugins.mjs | 16 +++++++++++++++- scripts/release-check.ts | 19 +++++++++++++++++++ test/release-check.test.ts | 11 +++++++++++ .../postinstall-bundled-plugins.test.ts | 15 +++++++++++++++ 4 files changed, 60 insertions(+), 1 deletion(-) diff --git a/scripts/postinstall-bundled-plugins.mjs b/scripts/postinstall-bundled-plugins.mjs index dd9cbd67afa..c1abb5d38a3 100644 --- a/scripts/postinstall-bundled-plugins.mjs +++ b/scripts/postinstall-bundled-plugins.mjs @@ -807,6 +807,20 @@ export function runBundledPluginPostinstall(params = {}) { }); } -if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href) { +export function isDirectPostinstallInvocation(params = {}) { + const entryPath = params.entryPath ?? process.argv[1]; + if (!entryPath) { + return false; + } + const modulePath = params.modulePath ?? fileURLToPath(import.meta.url); + const resolveRealPath = params.realpathSync ?? realpathSync; + try { + return resolveRealPath(entryPath) === resolveRealPath(modulePath); + } catch { + return pathToFileURL(entryPath).href === pathToFileURL(modulePath).href; + } +} + +if (isDirectPostinstallInvocation()) { runBundledPluginPostinstall(); } diff --git a/scripts/release-check.ts b/scripts/release-check.ts index 76f1adc2296..208fe749b25 100755 --- a/scripts/release-check.ts +++ b/scripts/release-check.ts @@ -204,6 +204,24 @@ function resolveGlobalRoot(prefixDir: string, cwd: string): string { }).trim(); } +export function createPackedBundledPluginPostinstallEnv( + env: NodeJS.ProcessEnv = process.env, +): NodeJS.ProcessEnv { + return { + ...env, + OPENCLAW_DISABLE_BUNDLED_ENTRY_SOURCE_FALLBACK: "1", + OPENCLAW_EAGER_BUNDLED_PLUGIN_DEPS: "1", + }; +} + +function runPackedBundledPluginPostinstall(packageRoot: string): void { + execFileSync(process.execPath, [join(packageRoot, "scripts/postinstall-bundled-plugins.mjs")], { + cwd: packageRoot, + stdio: "inherit", + env: createPackedBundledPluginPostinstallEnv(), + }); +} + function runPackedBundledChannelEntrySmoke(): void { const tmpRoot = mkdtempSync(join(tmpdir(), "openclaw-release-pack-smoke-")); try { @@ -216,6 +234,7 @@ function runPackedBundledChannelEntrySmoke(): void { installPackedTarball(prefixDir, tarballPath, tmpRoot); const packageRoot = join(resolveGlobalRoot(prefixDir, tmpRoot), "openclaw"); + runPackedBundledPluginPostinstall(packageRoot); execFileSync( process.execPath, [ diff --git a/test/release-check.test.ts b/test/release-check.test.ts index 70e31d1c9b7..0429dbed494 100644 --- a/test/release-check.test.ts +++ b/test/release-check.test.ts @@ -14,6 +14,7 @@ import { collectForbiddenPackPaths, collectMissingPackPaths, collectPackUnpackedSizeErrors, + createPackedBundledPluginPostinstallEnv, packageNameFromSpecifier, } from "../scripts/release-check.ts"; import { PACKAGE_DIST_INVENTORY_RELATIVE_PATH } from "../src/infra/package-dist-inventory.ts"; @@ -463,3 +464,13 @@ describe("collectPackUnpackedSizeErrors", () => { ]); }); }); + +describe("createPackedBundledPluginPostinstallEnv", () => { + it("enables eager bundled dependency repair for packed channel entry smoke", () => { + expect(createPackedBundledPluginPostinstallEnv({ PATH: "/usr/bin" })).toEqual({ + PATH: "/usr/bin", + OPENCLAW_DISABLE_BUNDLED_ENTRY_SOURCE_FALLBACK: "1", + OPENCLAW_EAGER_BUNDLED_PLUGIN_DEPS: "1", + }); + }); +}); diff --git a/test/scripts/postinstall-bundled-plugins.test.ts b/test/scripts/postinstall-bundled-plugins.test.ts index cd252304378..607168463c3 100644 --- a/test/scripts/postinstall-bundled-plugins.test.ts +++ b/test/scripts/postinstall-bundled-plugins.test.ts @@ -5,6 +5,7 @@ import { createBundledRuntimeDependencyInstallArgs, createBundledRuntimeDependencyInstallEnv, createNestedNpmInstallEnv, + isDirectPostinstallInvocation, pruneInstalledPackageDist, discoverBundledPluginRuntimeDeps, pruneBundledPluginSourceNodeModules, @@ -82,6 +83,20 @@ describe("bundled plugin postinstall", () => { }); } + it("recognizes direct invocation through symlinked temp prefixes", () => { + const realpathSync = vi.fn((value: string) => + value.replace(/^\/var\/folders\//u, "/private/var/folders/"), + ); + + expect( + isDirectPostinstallInvocation({ + entryPath: "/var/folders/tmp/openclaw/scripts/postinstall-bundled-plugins.mjs", + modulePath: "/private/var/folders/tmp/openclaw/scripts/postinstall-bundled-plugins.mjs", + realpathSync, + }), + ).toBe(true); + }); + async function writeDiscordDaveyOptionalDependencyFixture( extensionsDir: string, packageRoot: string,