|
| 1 | +import fs from "node:fs"; |
| 2 | +import path from "node:path"; |
1 | 3 | import { describe, expect, it } from "vitest"; |
2 | 4 | import { parseArgs as parseBulkBuildArgs } from "../../scripts/check-plugin-npm-runtime-builds.mjs"; |
| 5 | +import { listMissingPackageStaticAssetSources } from "../../scripts/lib/plugin-npm-runtime-assets.mjs"; |
3 | 6 | import { parseArgs as parseSingleBuildArgs } from "../../scripts/lib/plugin-npm-runtime-build.mjs"; |
| 7 | +import { createScriptTestHarness } from "./test-helpers.js"; |
| 8 | + |
| 9 | +const { createTempDir } = createScriptTestHarness(); |
4 | 10 | |
5 | 11 | describe("plugin npm runtime build args", () => { |
6 | 12 | it("parses explicit plugin package build targets", () => { |
@@ -40,4 +46,45 @@ describe("plugin npm runtime build args", () => {
|
40 | 46 | "unexpected plugin npm runtime build argument: extra", |
41 | 47 | ); |
42 | 48 | }); |
| 49 | + |
| 50 | +it("reports package-local missing static asset sources", () => { |
| 51 | +const repoRoot = createTempDir("openclaw-plugin-npm-runtime-assets-"); |
| 52 | +const demoDir = path.join(repoRoot, "extensions", "demo"); |
| 53 | +const otherDir = path.join(repoRoot, "extensions", "other"); |
| 54 | +fs.mkdirSync(path.join(demoDir, "assets"), { recursive: true }); |
| 55 | +fs.mkdirSync(otherDir, { recursive: true }); |
| 56 | +fs.writeFileSync(path.join(demoDir, "assets", "present.js"), "export {};\n", "utf8"); |
| 57 | +fs.writeFileSync( |
| 58 | +path.join(demoDir, "package.json"), |
| 59 | +JSON.stringify({ |
| 60 | +openclaw: { |
| 61 | +build: { |
| 62 | +staticAssets: [ |
| 63 | +{ source: "./assets/present.js", output: "assets/present.js" }, |
| 64 | +{ source: "./assets/missing.js", output: "assets/missing.js" }, |
| 65 | +], |
| 66 | +}, |
| 67 | +}, |
| 68 | +}), |
| 69 | +"utf8", |
| 70 | +); |
| 71 | +fs.writeFileSync( |
| 72 | +path.join(otherDir, "package.json"), |
| 73 | +JSON.stringify({ |
| 74 | +openclaw: { |
| 75 | +build: { |
| 76 | +staticAssets: [{ source: "./assets/other-missing.js", output: "assets/other.js" }], |
| 77 | +}, |
| 78 | +}, |
| 79 | +}), |
| 80 | +"utf8", |
| 81 | +); |
| 82 | + |
| 83 | +expect( |
| 84 | +listMissingPackageStaticAssetSources({ |
| 85 | + repoRoot, |
| 86 | +pluginDir: "demo", |
| 87 | +}), |
| 88 | +).toEqual(["extensions/demo/assets/missing.js"]); |
| 89 | +}); |
43 | 90 | }); |