mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-01 12:21:25 +00:00
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import fs from "node:fs/promises";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { copyStaticExtensionAssets } from "../../scripts/runtime-postbuild.mjs";
|
|
|
|
const cleanupDirs: string[] = [];
|
|
|
|
afterEach(async () => {
|
|
await Promise.all(
|
|
cleanupDirs.splice(0).map((dir) => fs.rm(dir, { recursive: true, force: true })),
|
|
);
|
|
});
|
|
|
|
async function createTempRoot() {
|
|
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-runtime-postbuild-"));
|
|
cleanupDirs.push(dir);
|
|
return dir;
|
|
}
|
|
|
|
describe("runtime postbuild static assets", () => {
|
|
it("copies declared static assets into dist", async () => {
|
|
const rootDir = await createTempRoot();
|
|
const src = "extensions/acpx/src/runtime-internals/mcp-proxy.mjs";
|
|
const dest = "dist/extensions/acpx/mcp-proxy.mjs";
|
|
const sourcePath = path.join(rootDir, src);
|
|
const destPath = path.join(rootDir, dest);
|
|
await fs.mkdir(path.dirname(sourcePath), { recursive: true });
|
|
await fs.writeFile(sourcePath, "proxy-data\n", "utf8");
|
|
|
|
copyStaticExtensionAssets({
|
|
rootDir,
|
|
assets: [{ src, dest }],
|
|
});
|
|
|
|
expect(await fs.readFile(destPath, "utf8")).toBe("proxy-data\n");
|
|
});
|
|
|
|
it("warns when a declared static asset is missing", async () => {
|
|
const rootDir = await createTempRoot();
|
|
const warn = vi.fn();
|
|
|
|
copyStaticExtensionAssets({
|
|
rootDir,
|
|
assets: [{ src: "missing/file.mjs", dest: "dist/file.mjs" }],
|
|
warn,
|
|
});
|
|
|
|
expect(warn).toHaveBeenCalledWith(
|
|
"[runtime-postbuild] static asset not found, skipping: missing/file.mjs",
|
|
);
|
|
});
|
|
});
|