mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 17:54:47 +00:00
73 lines
2.0 KiB
TypeScript
73 lines
2.0 KiB
TypeScript
import type { PluginRegistryParams } from "../../plugins/registry-types.js";
|
|
import type { OpenClawPluginApi } from "../plugin-entry.js";
|
|
import {
|
|
createPluginRecord,
|
|
createPluginRegistry,
|
|
registerProviderPlugins as registerProviders,
|
|
requireRegisteredProvider as requireProvider,
|
|
type OpenClawConfig,
|
|
type PluginRecord,
|
|
type PluginRuntime,
|
|
} from "../testing.js";
|
|
export { assertNoImportTimeSideEffects } from "./import-side-effects.js";
|
|
import { uniqueSortedStrings } from "./string-utils.js";
|
|
|
|
export { registerProviders, requireProvider, uniqueSortedStrings };
|
|
|
|
export function createPluginRegistryFixture(
|
|
config = {} as OpenClawConfig,
|
|
params: { hostServices?: PluginRegistryParams["hostServices"] } = {},
|
|
) {
|
|
return {
|
|
config,
|
|
registry: createPluginRegistry({
|
|
logger: {
|
|
info() {},
|
|
warn() {},
|
|
error() {},
|
|
debug() {},
|
|
},
|
|
runtime: {} as PluginRuntime,
|
|
...(params.hostServices ? { hostServices: params.hostServices } : {}),
|
|
}),
|
|
};
|
|
}
|
|
|
|
export function registerTestPlugin(params: {
|
|
registry: ReturnType<typeof createPluginRegistry>;
|
|
config: OpenClawConfig;
|
|
record: PluginRecord;
|
|
register(api: OpenClawPluginApi): void;
|
|
}) {
|
|
params.registry.registry.plugins.push(params.record);
|
|
params.register(
|
|
params.registry.createApi(params.record, {
|
|
config: params.config,
|
|
}),
|
|
);
|
|
}
|
|
|
|
export function registerVirtualTestPlugin(params: {
|
|
registry: ReturnType<typeof createPluginRegistry>;
|
|
config: OpenClawConfig;
|
|
id: string;
|
|
name: string;
|
|
source?: string;
|
|
kind?: PluginRecord["kind"];
|
|
contracts?: PluginRecord["contracts"];
|
|
register(this: void, api: OpenClawPluginApi): void;
|
|
}) {
|
|
registerTestPlugin({
|
|
registry: params.registry,
|
|
config: params.config,
|
|
record: createPluginRecord({
|
|
id: params.id,
|
|
name: params.name,
|
|
source: params.source ?? `/virtual/${params.id}/index.ts`,
|
|
...(params.kind ? { kind: params.kind } : {}),
|
|
...(params.contracts ? { contracts: params.contracts } : {}),
|
|
}),
|
|
register: params.register,
|
|
});
|
|
}
|