mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-11 03:46:39 +02:00
66 lines
1.8 KiB
TypeScript
66 lines
1.8 KiB
TypeScript
import type { OpenClawConfig } from "../../config/config.js";
|
|
import { createPluginRegistry, type PluginRecord } from "../registry.js";
|
|
import type { PluginRuntime } from "../runtime/types.js";
|
|
import { createPluginRecord } from "../status.test-helpers.js";
|
|
import type { OpenClawPluginApi } from "../types.js";
|
|
|
|
export {
|
|
registerProviderPlugins as registerProviders,
|
|
requireRegisteredProvider as requireProvider,
|
|
} from "../../test-utils/plugin-registration.js";
|
|
|
|
export function uniqueSortedStrings(values: readonly string[]) {
|
|
return [...new Set(values)].toSorted((left, right) => left.localeCompare(right));
|
|
}
|
|
|
|
export function createPluginRegistryFixture(config = {} as OpenClawConfig) {
|
|
return {
|
|
config,
|
|
registry: createPluginRegistry({
|
|
logger: {
|
|
info() {},
|
|
warn() {},
|
|
error() {},
|
|
debug() {},
|
|
},
|
|
runtime: {} as PluginRuntime,
|
|
}),
|
|
};
|
|
}
|
|
|
|
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"];
|
|
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 } : {}),
|
|
}),
|
|
register: params.register,
|
|
});
|
|
}
|