mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-20 21:23:23 +00:00
test(commands): lazy-load default channel registry plugins
This commit is contained in:
@@ -5,40 +5,91 @@ import type { PluginRuntime } from "../plugins/runtime/index.js";
|
||||
import { loadBundledPluginTestApiSync } from "../test-utils/bundled-plugin-public-surface.js";
|
||||
import { createTestRegistry } from "../test-utils/channel-plugins.js";
|
||||
|
||||
const { googlechatPlugin } = loadBundledPluginTestApiSync<{
|
||||
googlechatPlugin: ChannelPlugin;
|
||||
}>("googlechat");
|
||||
const { matrixPlugin, setMatrixRuntime } = loadBundledPluginTestApiSync<{
|
||||
matrixPlugin: ChannelPlugin;
|
||||
setMatrixRuntime: (runtime: PluginRuntime) => void;
|
||||
}>("matrix");
|
||||
const { msteamsPlugin } = loadBundledPluginTestApiSync<{
|
||||
msteamsPlugin: ChannelPlugin;
|
||||
}>("msteams");
|
||||
const { nostrPlugin } = loadBundledPluginTestApiSync<{
|
||||
nostrPlugin: ChannelPlugin;
|
||||
}>("nostr");
|
||||
const { tlonPlugin } = loadBundledPluginTestApiSync<{
|
||||
tlonPlugin: ChannelPlugin;
|
||||
}>("tlon");
|
||||
const { whatsappPlugin } = loadBundledPluginTestApiSync<{
|
||||
whatsappPlugin: ChannelPlugin;
|
||||
}>("whatsapp");
|
||||
let googlechatPluginCache: ChannelPlugin | undefined;
|
||||
let matrixPluginCache: ChannelPlugin | undefined;
|
||||
let setMatrixRuntimeCache: ((runtime: PluginRuntime) => void) | undefined;
|
||||
let msteamsPluginCache: ChannelPlugin | undefined;
|
||||
let nostrPluginCache: ChannelPlugin | undefined;
|
||||
let tlonPluginCache: ChannelPlugin | undefined;
|
||||
let whatsappPluginCache: ChannelPlugin | undefined;
|
||||
|
||||
function getGooglechatPlugin(): ChannelPlugin {
|
||||
if (!googlechatPluginCache) {
|
||||
({ googlechatPlugin: googlechatPluginCache } = loadBundledPluginTestApiSync<{
|
||||
googlechatPlugin: ChannelPlugin;
|
||||
}>("googlechat"));
|
||||
}
|
||||
return googlechatPluginCache;
|
||||
}
|
||||
|
||||
function getMatrixPlugin(): ChannelPlugin {
|
||||
if (!matrixPluginCache) {
|
||||
({ matrixPlugin: matrixPluginCache, setMatrixRuntime: setMatrixRuntimeCache } =
|
||||
loadBundledPluginTestApiSync<{
|
||||
matrixPlugin: ChannelPlugin;
|
||||
setMatrixRuntime: (runtime: PluginRuntime) => void;
|
||||
}>("matrix"));
|
||||
}
|
||||
return matrixPluginCache;
|
||||
}
|
||||
|
||||
function getSetMatrixRuntime(): (runtime: PluginRuntime) => void {
|
||||
if (!setMatrixRuntimeCache) {
|
||||
void getMatrixPlugin();
|
||||
}
|
||||
return setMatrixRuntimeCache!;
|
||||
}
|
||||
|
||||
function getMSTeamsPlugin(): ChannelPlugin {
|
||||
if (!msteamsPluginCache) {
|
||||
({ msteamsPlugin: msteamsPluginCache } = loadBundledPluginTestApiSync<{
|
||||
msteamsPlugin: ChannelPlugin;
|
||||
}>("msteams"));
|
||||
}
|
||||
return msteamsPluginCache;
|
||||
}
|
||||
|
||||
function getNostrPlugin(): ChannelPlugin {
|
||||
if (!nostrPluginCache) {
|
||||
({ nostrPlugin: nostrPluginCache } = loadBundledPluginTestApiSync<{
|
||||
nostrPlugin: ChannelPlugin;
|
||||
}>("nostr"));
|
||||
}
|
||||
return nostrPluginCache;
|
||||
}
|
||||
|
||||
function getTlonPlugin(): ChannelPlugin {
|
||||
if (!tlonPluginCache) {
|
||||
({ tlonPlugin: tlonPluginCache } = loadBundledPluginTestApiSync<{
|
||||
tlonPlugin: ChannelPlugin;
|
||||
}>("tlon"));
|
||||
}
|
||||
return tlonPluginCache;
|
||||
}
|
||||
|
||||
function getWhatsAppPlugin(): ChannelPlugin {
|
||||
if (!whatsappPluginCache) {
|
||||
({ whatsappPlugin: whatsappPluginCache } = loadBundledPluginTestApiSync<{
|
||||
whatsappPlugin: ChannelPlugin;
|
||||
}>("whatsapp"));
|
||||
}
|
||||
return whatsappPluginCache;
|
||||
}
|
||||
|
||||
export function setDefaultChannelPluginRegistryForTests(): void {
|
||||
setMatrixRuntime({
|
||||
getSetMatrixRuntime()({
|
||||
state: {
|
||||
resolveStateDir: (_env, homeDir) => (homeDir ?? (() => "/tmp"))(),
|
||||
},
|
||||
} as Parameters<typeof setMatrixRuntime>[0]);
|
||||
} as Parameters<ReturnType<typeof getSetMatrixRuntime>>[0]);
|
||||
const channels = [
|
||||
...listBundledChannelPlugins(),
|
||||
matrixPlugin,
|
||||
msteamsPlugin,
|
||||
nostrPlugin,
|
||||
tlonPlugin,
|
||||
googlechatPlugin,
|
||||
whatsappPlugin,
|
||||
getMatrixPlugin(),
|
||||
getMSTeamsPlugin(),
|
||||
getNostrPlugin(),
|
||||
getTlonPlugin(),
|
||||
getGooglechatPlugin(),
|
||||
getWhatsAppPlugin(),
|
||||
].map((plugin) => ({
|
||||
pluginId: plugin.id,
|
||||
plugin,
|
||||
|
||||
Reference in New Issue
Block a user