mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-21 15:01:03 +00:00
70 lines
2.4 KiB
TypeScript
70 lines
2.4 KiB
TypeScript
import fs from "node:fs/promises";
|
|
import path from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
import { buildPluginSdkPackageExports } from "./entrypoints.js";
|
|
import * as sdk from "./index.js";
|
|
|
|
describe("plugin-sdk exports", () => {
|
|
it("does not expose runtime modules", () => {
|
|
const forbidden = [
|
|
"chunkMarkdownText",
|
|
"chunkText",
|
|
"hasControlCommand",
|
|
"isControlCommandMessage",
|
|
"shouldComputeCommandAuthorized",
|
|
"shouldHandleTextCommands",
|
|
"buildMentionRegexes",
|
|
"matchesMentionPatterns",
|
|
"resolveStateDir",
|
|
"writeConfigFile",
|
|
"enqueueSystemEvent",
|
|
"fetchRemoteMedia",
|
|
"saveMediaBuffer",
|
|
"formatAgentEnvelope",
|
|
"buildPairingReply",
|
|
"resolveAgentRoute",
|
|
"dispatchReplyFromConfig",
|
|
"createReplyDispatcherWithTyping",
|
|
"dispatchReplyWithBufferedBlockDispatcher",
|
|
"resolveCommandAuthorizedFromAuthorizers",
|
|
"monitorSlackProvider",
|
|
"monitorTelegramProvider",
|
|
"monitorIMessageProvider",
|
|
"monitorSignalProvider",
|
|
"sendMessageSlack",
|
|
"sendMessageTelegram",
|
|
"sendMessageIMessage",
|
|
"sendMessageSignal",
|
|
"sendMessageWhatsApp",
|
|
"probeSlack",
|
|
"probeTelegram",
|
|
"probeIMessage",
|
|
"probeSignal",
|
|
];
|
|
|
|
for (const key of forbidden) {
|
|
expect(Object.prototype.hasOwnProperty.call(sdk, key)).toBe(false);
|
|
}
|
|
});
|
|
|
|
it("keeps the root runtime surface intentionally small", () => {
|
|
expect(typeof sdk.emptyPluginConfigSchema).toBe("function");
|
|
expect(typeof sdk.delegateCompactionToRuntime).toBe("function");
|
|
expect(Object.prototype.hasOwnProperty.call(sdk, "resolveControlCommandGate")).toBe(false);
|
|
expect(Object.prototype.hasOwnProperty.call(sdk, "buildAgentSessionKey")).toBe(false);
|
|
expect(Object.prototype.hasOwnProperty.call(sdk, "isDangerousNameMatchingEnabled")).toBe(false);
|
|
});
|
|
|
|
it("keeps package.json plugin-sdk exports synced with the manifest", async () => {
|
|
const packageJsonPath = path.join(process.cwd(), "package.json");
|
|
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, "utf8")) as {
|
|
exports?: Record<string, unknown>;
|
|
};
|
|
const currentPluginSdkExports = Object.fromEntries(
|
|
Object.entries(packageJson.exports ?? {}).filter(([key]) => key.startsWith("./plugin-sdk")),
|
|
);
|
|
|
|
expect(currentPluginSdkExports).toEqual(buildPluginSdkPackageExports());
|
|
});
|
|
});
|