From 12933a2bcbf9d9ba65758f56ab51da52ae25876e Mon Sep 17 00:00:00 2001 From: Ruben Cuevas Date: Tue, 5 May 2026 20:16:49 -0400 Subject: [PATCH] fix(gateway): stage static runtime assets --- scripts/runtime-postbuild.mjs | 10 ++--- test/scripts/runtime-postbuild.test.ts | 52 +++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/scripts/runtime-postbuild.mjs b/scripts/runtime-postbuild.mjs index 035c77c95c6..797bcd4fd4c 100644 --- a/scripts/runtime-postbuild.mjs +++ b/scripts/runtime-postbuild.mjs @@ -459,17 +459,17 @@ export function runRuntimePostBuild(params = {}) { runPhase("plugin SDK root alias", () => copyPluginSdkRootAlias(params)); runPhase("bundled plugin metadata", () => copyBundledPluginMetadata(params)); runPhase("official channel catalog", () => writeOfficialChannelCatalog(params)); - runPhase("bundled plugin runtime overlay", () => stageBundledPluginRuntime(params)); - runPhase("stable root runtime imports", () => rewriteRootRuntimeImportsToStableAliases(params)); - runPhase("stable root runtime aliases", () => writeStableRootRuntimeAliases(params)); - runPhase("legacy root runtime compat aliases", () => writeLegacyRootRuntimeCompatAliases(params)); - runPhase("legacy CLI exit compat chunks", () => writeLegacyCliExitCompatChunks(params)); runPhase("static extension assets", () => copyStaticExtensionAssets({ rootDir: ROOT, ...params, }), ); + runPhase("bundled plugin runtime overlay", () => stageBundledPluginRuntime(params)); + runPhase("stable root runtime imports", () => rewriteRootRuntimeImportsToStableAliases(params)); + runPhase("stable root runtime aliases", () => writeStableRootRuntimeAliases(params)); + runPhase("legacy root runtime compat aliases", () => writeLegacyRootRuntimeCompatAliases(params)); + runPhase("legacy CLI exit compat chunks", () => writeLegacyCliExitCompatChunks(params)); } if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href) { diff --git a/test/scripts/runtime-postbuild.test.ts b/test/scripts/runtime-postbuild.test.ts index 960e0d69153..98d7148f937 100644 --- a/test/scripts/runtime-postbuild.test.ts +++ b/test/scripts/runtime-postbuild.test.ts @@ -6,6 +6,7 @@ import { copyStaticExtensionAssets, listStaticExtensionAssetOutputs, rewriteRootRuntimeImportsToStableAliases, + runRuntimePostBuild, writeLegacyCliExitCompatChunks, writeLegacyRootRuntimeCompatAliases, writeStableRootRuntimeAliases, @@ -86,7 +87,56 @@ describe("runtime postbuild static assets", () => { expect(await fs.readFile(destPath, "utf8")).toBe("proxy-data\n"); }); - it("warns when a declared static asset is missing", () => { + it("stages copied static assets into the runtime overlay during the same postbuild run", async () => { + const rootDir = createTempDir("openclaw-runtime-postbuild-"); + const source = "extensions/diffs/assets/viewer-runtime.js"; + const output = "assets/viewer-runtime.js"; + const distAsset = "dist/extensions/diffs/assets/viewer-runtime.js"; + const runtimeAsset = "dist-runtime/extensions/diffs/assets/viewer-runtime.js"; + + await fs.mkdir(path.join(rootDir, "src", "plugin-sdk"), { recursive: true }); + await fs.writeFile( + path.join(rootDir, "src", "plugin-sdk", "root-alias.cjs"), + "module.exports = {};\n", + "utf8", + ); + await fs.mkdir(path.join(rootDir, "extensions", "diffs", "assets"), { recursive: true }); + await fs.writeFile( + path.join(rootDir, "extensions", "diffs", "package.json"), + JSON.stringify({ + name: "@openclaw/diffs", + openclaw: { + extensions: ["./index.ts"], + build: { + staticAssets: [{ source: `./${output}`, output }], + }, + }, + }), + "utf8", + ); + await fs.writeFile( + path.join(rootDir, "extensions", "diffs", "openclaw.plugin.json"), + '{"id":"diffs"}\n', + "utf8", + ); + await fs.writeFile(path.join(rootDir, source), "export const viewer = true;\n", "utf8"); + + runRuntimePostBuild({ + cwd: rootDir, + repoRoot: rootDir, + rootDir, + timings: false, + }); + + await expect(fs.readFile(path.join(rootDir, distAsset), "utf8")).resolves.toBe( + "export const viewer = true;\n", + ); + await expect(fs.readFile(path.join(rootDir, runtimeAsset), "utf8")).resolves.toContain( + "dist/extensions/diffs/assets/viewer-runtime.js", + ); + }); + + it("warns when a declared static asset is missing", async () => { const rootDir = createTempDir("openclaw-runtime-postbuild-"); const warn = vi.fn();