mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 10:05:19 +00:00
fix: stabilize contract loader seams
This commit is contained in:
parent
4a690b452a
commit
4aeabf95cc
7 changed files with 40 additions and 85 deletions
|
|
@ -1,4 +1,3 @@
|
|||
// Keep this barrel helper-only so plugin-sdk facades do not pull the full
|
||||
// channel plugin (and its runtime state) into tests or other shared surfaces.
|
||||
export { mattermostPlugin } from "./src/channel.js";
|
||||
export { isMattermostSenderAllowed } from "./src/mattermost/monitor-auth.js";
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ export default defineBundledChannelEntry({
|
|||
description: "Mattermost channel plugin",
|
||||
importMetaUrl: import.meta.url,
|
||||
plugin: {
|
||||
specifier: "./api.js",
|
||||
specifier: "./src/channel.js",
|
||||
exportName: "mattermostPlugin",
|
||||
},
|
||||
runtime: {
|
||||
|
|
|
|||
1
extensions/mattermost/policy-api.ts
Normal file
1
extensions/mattermost/policy-api.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export { isMattermostSenderAllowed } from "./src/mattermost/monitor-auth.js";
|
||||
|
|
@ -3,7 +3,7 @@ import { defineBundledChannelSetupEntry } from "openclaw/plugin-sdk/channel-entr
|
|||
export default defineBundledChannelSetupEntry({
|
||||
importMetaUrl: import.meta.url,
|
||||
plugin: {
|
||||
specifier: "./api.js",
|
||||
specifier: "./src/channel.js",
|
||||
exportName: "mattermostPlugin",
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -41,10 +41,9 @@ const sendMessageMatrixMock = vi.hoisted(() =>
|
|||
roomId: to.replace(/^room:/, ""),
|
||||
})),
|
||||
);
|
||||
const matrixRuntimeApiModuleId = new URL(
|
||||
"../../../../extensions/matrix/runtime-api.js",
|
||||
import.meta.url,
|
||||
).href;
|
||||
const matrixRuntimeApiModuleId = vi.hoisted(
|
||||
() => new URL("../../../../extensions/matrix/runtime-api.js", import.meta.url).href,
|
||||
);
|
||||
|
||||
const lineContractApi = await importBundledChannelContractArtifact<{
|
||||
listLineAccountIds: () => string[];
|
||||
|
|
|
|||
|
|
@ -1,11 +1,19 @@
|
|||
// Manual facade. Keep loader boundary explicit.
|
||||
type FacadeModule = typeof import("@openclaw/mattermost/api.js");
|
||||
type MattermostSenderAllowed = (params: {
|
||||
senderId: string;
|
||||
senderName?: string;
|
||||
allowFrom: string[];
|
||||
allowNameMatching?: boolean;
|
||||
}) => boolean;
|
||||
type FacadeModule = {
|
||||
isMattermostSenderAllowed: MattermostSenderAllowed;
|
||||
};
|
||||
import { loadBundledPluginPublicSurfaceModuleSync } from "./facade-runtime.js";
|
||||
|
||||
function loadFacadeModule(): FacadeModule {
|
||||
return loadBundledPluginPublicSurfaceModuleSync<FacadeModule>({
|
||||
dirName: "mattermost",
|
||||
artifactBasename: "api.js",
|
||||
artifactBasename: "policy-api.js",
|
||||
});
|
||||
}
|
||||
export const isMattermostSenderAllowed: FacadeModule["isMattermostSenderAllowed"] = ((...args) =>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,16 @@
|
|||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { bluebubblesPlugin } from "../../../extensions/bluebubbles/api.js";
|
||||
import {
|
||||
discordPlugin,
|
||||
discordThreadBindingTesting,
|
||||
} from "../../../extensions/discord/test-api.js";
|
||||
import { feishuPlugin, feishuThreadBindingTesting } from "../../../extensions/feishu/api.js";
|
||||
import { imessagePlugin } from "../../../extensions/imessage/api.js";
|
||||
import { matrixPlugin, setMatrixRuntime } from "../../../extensions/matrix/test-api.js";
|
||||
import {
|
||||
telegramPlugin,
|
||||
resetTelegramThreadBindingsForTests,
|
||||
} from "../../../extensions/telegram/test-api.js";
|
||||
import { getSessionBindingContractRegistry } from "../../../src/channels/plugins/contracts/registry-session-binding.js";
|
||||
import type { ChannelPlugin } from "../../../src/channels/plugins/types.js";
|
||||
import {
|
||||
|
|
@ -13,10 +25,6 @@ import {
|
|||
import { resetPluginRuntimeStateForTest } from "../../../src/plugins/runtime.js";
|
||||
import { setActivePluginRegistry } from "../../../src/plugins/runtime.js";
|
||||
import type { PluginRuntime } from "../../../src/plugins/runtime/index.js";
|
||||
import {
|
||||
loadBundledPluginPublicSurfaceSync,
|
||||
loadBundledPluginTestApiSync,
|
||||
} from "../../../src/test-utils/bundled-plugin-public-surface.js";
|
||||
import { createTestRegistry } from "../../../src/test-utils/channel-plugins.js";
|
||||
|
||||
type DiscordThreadBindingTesting = {
|
||||
|
|
@ -25,109 +33,49 @@ type DiscordThreadBindingTesting = {
|
|||
|
||||
type ResetTelegramThreadBindingsForTests = () => Promise<void>;
|
||||
|
||||
let discordThreadBindingTestingCache: DiscordThreadBindingTesting | undefined;
|
||||
let resetTelegramThreadBindingsForTestsCache: ResetTelegramThreadBindingsForTests | undefined;
|
||||
let feishuApiPromise: Promise<typeof import("../../../extensions/feishu/api.js")> | undefined;
|
||||
let matrixApiPromise: Promise<typeof import("../../../extensions/matrix/api.js")> | undefined;
|
||||
let bluebubblesPluginCache: ChannelPlugin | undefined;
|
||||
let discordPluginCache: ChannelPlugin | undefined;
|
||||
let feishuPluginCache: ChannelPlugin | undefined;
|
||||
let imessagePluginCache: ChannelPlugin | undefined;
|
||||
let matrixPluginCache: ChannelPlugin | undefined;
|
||||
let setMatrixRuntimeCache: ((runtime: PluginRuntime) => void) | undefined;
|
||||
let telegramPluginCache: ChannelPlugin | undefined;
|
||||
|
||||
function getBluebubblesPlugin(): ChannelPlugin {
|
||||
if (!bluebubblesPluginCache) {
|
||||
({ bluebubblesPlugin: bluebubblesPluginCache } = loadBundledPluginPublicSurfaceSync<{
|
||||
bluebubblesPlugin: ChannelPlugin;
|
||||
}>({ pluginId: "bluebubbles", artifactBasename: "index.js" }));
|
||||
}
|
||||
return bluebubblesPluginCache;
|
||||
return bluebubblesPlugin as unknown as ChannelPlugin;
|
||||
}
|
||||
|
||||
function getDiscordPlugin(): ChannelPlugin {
|
||||
if (!discordPluginCache) {
|
||||
({ discordPlugin: discordPluginCache } = loadBundledPluginTestApiSync<{
|
||||
discordPlugin: ChannelPlugin;
|
||||
}>("discord"));
|
||||
}
|
||||
return discordPluginCache;
|
||||
return discordPlugin as unknown as ChannelPlugin;
|
||||
}
|
||||
|
||||
function getFeishuPlugin(): ChannelPlugin {
|
||||
if (!feishuPluginCache) {
|
||||
({ feishuPlugin: feishuPluginCache } = loadBundledPluginPublicSurfaceSync<{
|
||||
feishuPlugin: ChannelPlugin;
|
||||
}>({ pluginId: "feishu", artifactBasename: "api.js" }));
|
||||
}
|
||||
return feishuPluginCache;
|
||||
return feishuPlugin as unknown as ChannelPlugin;
|
||||
}
|
||||
|
||||
function getIMessagePlugin(): ChannelPlugin {
|
||||
if (!imessagePluginCache) {
|
||||
({ imessagePlugin: imessagePluginCache } = loadBundledPluginPublicSurfaceSync<{
|
||||
imessagePlugin: ChannelPlugin;
|
||||
}>({ pluginId: "imessage", artifactBasename: "api.js" }));
|
||||
}
|
||||
return imessagePluginCache;
|
||||
return imessagePlugin as unknown as ChannelPlugin;
|
||||
}
|
||||
|
||||
function getMatrixPlugin(): ChannelPlugin {
|
||||
if (!matrixPluginCache) {
|
||||
({ matrixPlugin: matrixPluginCache, setMatrixRuntime: setMatrixRuntimeCache } =
|
||||
loadBundledPluginTestApiSync<{
|
||||
matrixPlugin: ChannelPlugin;
|
||||
setMatrixRuntime: (runtime: PluginRuntime) => void;
|
||||
}>("matrix"));
|
||||
}
|
||||
return matrixPluginCache;
|
||||
return matrixPlugin as unknown as ChannelPlugin;
|
||||
}
|
||||
|
||||
function getSetMatrixRuntime(): (runtime: PluginRuntime) => void {
|
||||
if (!setMatrixRuntimeCache) {
|
||||
void getMatrixPlugin();
|
||||
}
|
||||
return setMatrixRuntimeCache!;
|
||||
return setMatrixRuntime;
|
||||
}
|
||||
|
||||
function getTelegramPlugin(): ChannelPlugin {
|
||||
if (!telegramPluginCache) {
|
||||
({ telegramPlugin: telegramPluginCache } = loadBundledPluginTestApiSync<{
|
||||
telegramPlugin: ChannelPlugin;
|
||||
}>("telegram"));
|
||||
}
|
||||
return telegramPluginCache;
|
||||
return telegramPlugin as unknown as ChannelPlugin;
|
||||
}
|
||||
|
||||
function getDiscordThreadBindingTesting(): DiscordThreadBindingTesting {
|
||||
if (!discordThreadBindingTestingCache) {
|
||||
({ discordThreadBindingTesting: discordThreadBindingTestingCache } =
|
||||
loadBundledPluginTestApiSync<{
|
||||
discordThreadBindingTesting: DiscordThreadBindingTesting;
|
||||
}>("discord"));
|
||||
}
|
||||
return discordThreadBindingTestingCache;
|
||||
return discordThreadBindingTesting;
|
||||
}
|
||||
|
||||
function getResetTelegramThreadBindingsForTests(): ResetTelegramThreadBindingsForTests {
|
||||
if (!resetTelegramThreadBindingsForTestsCache) {
|
||||
({ resetTelegramThreadBindingsForTests: resetTelegramThreadBindingsForTestsCache } =
|
||||
loadBundledPluginTestApiSync<{
|
||||
resetTelegramThreadBindingsForTests: ResetTelegramThreadBindingsForTests;
|
||||
}>("telegram"));
|
||||
}
|
||||
return resetTelegramThreadBindingsForTestsCache;
|
||||
return resetTelegramThreadBindingsForTests;
|
||||
}
|
||||
|
||||
async function getFeishuThreadBindingTesting() {
|
||||
feishuApiPromise ??= import("../../../extensions/feishu/api.js");
|
||||
return (await feishuApiPromise).feishuThreadBindingTesting;
|
||||
return feishuThreadBindingTesting;
|
||||
}
|
||||
|
||||
async function getResetMatrixThreadBindingsForTests() {
|
||||
matrixApiPromise ??= import("../../../extensions/matrix/api.js");
|
||||
return (await matrixApiPromise).resetMatrixThreadBindingsForTests;
|
||||
const matrixApi = await import("../../../extensions/matrix/api.js");
|
||||
return matrixApi.resetMatrixThreadBindingsForTests;
|
||||
}
|
||||
|
||||
function resolveSessionBindingContractRuntimeConfig(id: string) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue