mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
c70aee247e
* refactor(scripts): migrate JavaScript tools to TypeScript * fix(ci): keep changed-scope preflight zero-install * fix(ci): preserve zero-install script owners * fix(ci): complete script migration follow-through * fix(release): keep stable closeout zero-install * fix(scripts): preserve standalone execution boundaries * fix(scripts): repair standalone loader boundaries * fix(scripts): normalize gateway observation ids * fix(scripts): keep Docker packager standalone * test(scripts): preserve rebase cleanup helpers * test(sessions): use tracked temp directory
112 lines
3.8 KiB
TypeScript
112 lines
3.8 KiB
TypeScript
// Built plugin control-plane module checks cover native require(esm) acceptance.
|
|
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import {
|
|
listBuiltPluginControlPlaneModules,
|
|
probeBuiltPluginControlPlaneModules,
|
|
verifyBuiltPluginControlPlaneModules,
|
|
} from "../../scripts/check-built-plugin-control-plane-modules.mts";
|
|
|
|
const roots: string[] = [];
|
|
|
|
function makeRoot(): string {
|
|
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-plugin-control-plane-"));
|
|
roots.push(rootDir);
|
|
fs.writeFileSync(path.join(rootDir, "package.json"), '{"type":"module"}\n');
|
|
return rootDir;
|
|
}
|
|
|
|
function write(rootDir: string, relativePath: string, source: string): void {
|
|
const filePath = path.join(rootDir, relativePath);
|
|
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
fs.writeFileSync(filePath, source);
|
|
}
|
|
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
for (const rootDir of roots.splice(0)) {
|
|
fs.rmSync(rootDir, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
describe("built plugin control-plane module loads", () => {
|
|
it("lists exact contract files and channel legacy setup references", () => {
|
|
const rootDir = makeRoot();
|
|
write(rootDir, "dist/extensions/demo/doctor-contract-api.js", "export const ok = true;\n");
|
|
write(rootDir, "dist/extensions/demo/contract-api.js", "export const ok = true;\n");
|
|
write(
|
|
rootDir,
|
|
"dist/extensions/demo/provider-contract-api.js",
|
|
"export const ignored = true;\n",
|
|
);
|
|
write(
|
|
rootDir,
|
|
"dist/extensions/demo/setup-entry.js",
|
|
[
|
|
"const setup = {",
|
|
' legacyStateMigrations: { specifier: "./legacy-state-migrations-api.js" },',
|
|
' legacySessionSurface: { specifier: "./legacy-session-surface-api.js" },',
|
|
"};",
|
|
"export default setup;",
|
|
].join("\n"),
|
|
);
|
|
write(rootDir, "dist/extensions/demo/legacy-state-migrations-api.js", "export {};\n");
|
|
write(rootDir, "dist/extensions/demo/legacy-session-surface-api.js", "export {};\n");
|
|
|
|
expect(listBuiltPluginControlPlaneModules({ rootDir })).toEqual([
|
|
{
|
|
pluginId: "demo",
|
|
kind: "contract",
|
|
relativePath: "dist/extensions/demo/contract-api.js",
|
|
},
|
|
{
|
|
pluginId: "demo",
|
|
kind: "doctor-contract",
|
|
relativePath: "dist/extensions/demo/doctor-contract-api.js",
|
|
},
|
|
{
|
|
pluginId: "demo",
|
|
kind: "channel-legacy-session-surface",
|
|
relativePath: "dist/extensions/demo/legacy-session-surface-api.js",
|
|
},
|
|
{
|
|
pluginId: "demo",
|
|
kind: "channel-legacy-state-migrations",
|
|
relativePath: "dist/extensions/demo/legacy-state-migrations-api.js",
|
|
},
|
|
]);
|
|
});
|
|
|
|
it("accepts synchronously requireable ESM artifacts", () => {
|
|
const rootDir = makeRoot();
|
|
write(rootDir, "dist/extensions/demo/doctor-contract-api.js", "export const ok = true;\n");
|
|
|
|
expect(() => verifyBuiltPluginControlPlaneModules({ rootDir })).not.toThrow();
|
|
});
|
|
|
|
it("reports plugin, kind, path, and native require error", () => {
|
|
const rootDir = makeRoot();
|
|
write(
|
|
rootDir,
|
|
"dist/extensions/demo/doctor-contract-api.js",
|
|
"await Promise.resolve();\nexport const ok = true;\n",
|
|
);
|
|
|
|
expect(() => verifyBuiltPluginControlPlaneModules({ rootDir })).toThrow(
|
|
/demo \(doctor-contract\) dist\/extensions\/demo\/doctor-contract-api\.js:.*ERR_REQUIRE_ASYNC_MODULE/s,
|
|
);
|
|
});
|
|
|
|
it("bounds a stalled native require child", () => {
|
|
const rootDir = makeRoot();
|
|
write(rootDir, "dist/extensions/demo/doctor-contract-api.js", "while (true) {}\n");
|
|
const modules = listBuiltPluginControlPlaneModules({ rootDir });
|
|
|
|
expect(() => probeBuiltPluginControlPlaneModules(modules, { rootDir, timeoutMs: 100 })).toThrow(
|
|
/timed out|ETIMEDOUT/u,
|
|
);
|
|
});
|
|
});
|