mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-21 21:56:46 +00:00
test: tighten plugin registry assertions
This commit is contained in:
@@ -27,6 +27,56 @@ function withActivatedPluginIdsForTest<T extends Record<string, unknown>>(
|
||||
};
|
||||
}
|
||||
|
||||
function expectConfiguredChannelPluginIdsParams(expected: {
|
||||
config: unknown;
|
||||
workspaceDir?: string;
|
||||
}) {
|
||||
expect(mocks.resolveConfiguredChannelPluginIds).toHaveBeenCalledTimes(1);
|
||||
const params = mocks.resolveConfiguredChannelPluginIds.mock.calls[0]?.[0] as
|
||||
| { config?: unknown; env?: NodeJS.ProcessEnv; workspaceDir?: string }
|
||||
| undefined;
|
||||
expect(params?.config).toBe(expected.config);
|
||||
expect(params?.env).toBe(process.env);
|
||||
expect(params?.workspaceDir).toBe(expected.workspaceDir);
|
||||
}
|
||||
|
||||
function expectLoadOpenClawPluginsCall(
|
||||
callIndex: number,
|
||||
expected: {
|
||||
config?: unknown;
|
||||
activationSourceConfig?: unknown;
|
||||
autoEnabledReasons?: unknown;
|
||||
onlyPluginIds: string[];
|
||||
throwOnLoadError: boolean;
|
||||
workspaceDir?: string;
|
||||
},
|
||||
) {
|
||||
const params = mocks.loadOpenClawPlugins.mock.calls[callIndex]?.[0] as
|
||||
| {
|
||||
config?: unknown;
|
||||
activationSourceConfig?: unknown;
|
||||
autoEnabledReasons?: unknown;
|
||||
onlyPluginIds?: string[];
|
||||
throwOnLoadError?: boolean;
|
||||
workspaceDir?: string;
|
||||
}
|
||||
| undefined;
|
||||
if ("config" in expected) {
|
||||
expect(params?.config).toEqual(expected.config);
|
||||
}
|
||||
if ("activationSourceConfig" in expected) {
|
||||
expect(params?.activationSourceConfig).toEqual(expected.activationSourceConfig);
|
||||
}
|
||||
if ("autoEnabledReasons" in expected) {
|
||||
expect(params?.autoEnabledReasons).toEqual(expected.autoEnabledReasons);
|
||||
}
|
||||
expect(params?.onlyPluginIds).toEqual(expected.onlyPluginIds);
|
||||
expect(params?.throwOnLoadError).toBe(expected.throwOnLoadError);
|
||||
if ("workspaceDir" in expected) {
|
||||
expect(params?.workspaceDir).toBe(expected.workspaceDir);
|
||||
}
|
||||
}
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
loadOpenClawPlugins: vi.fn<typeof import("../plugins/loader.js").loadOpenClawPlugins>(),
|
||||
resolveCompatibleRuntimePluginRegistry:
|
||||
@@ -193,25 +243,21 @@ describe("ensurePluginRegistryLoaded", () => {
|
||||
|
||||
ensurePluginRegistryLoaded({ scope: "configured-channels" });
|
||||
|
||||
expect(mocks.resolveConfiguredChannelPluginIds).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
config: autoEnabledConfig,
|
||||
env: process.env,
|
||||
workspaceDir: "/tmp/workspace",
|
||||
}),
|
||||
);
|
||||
expect(mocks.loadOpenClawPlugins).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
config: autoEnabledConfig,
|
||||
activationSourceConfig: autoEnabledConfig,
|
||||
autoEnabledReasons: {
|
||||
"demo-chat": ["demo-chat configured"],
|
||||
},
|
||||
onlyPluginIds: ["demo-chat"],
|
||||
throwOnLoadError: true,
|
||||
workspaceDir: "/tmp/workspace",
|
||||
}),
|
||||
);
|
||||
expectConfiguredChannelPluginIdsParams({
|
||||
config: autoEnabledConfig,
|
||||
workspaceDir: "/tmp/workspace",
|
||||
});
|
||||
expect(mocks.loadOpenClawPlugins).toHaveBeenCalledTimes(1);
|
||||
expectLoadOpenClawPluginsCall(0, {
|
||||
config: autoEnabledConfig,
|
||||
activationSourceConfig: autoEnabledConfig,
|
||||
autoEnabledReasons: {
|
||||
"demo-chat": ["demo-chat configured"],
|
||||
},
|
||||
onlyPluginIds: ["demo-chat"],
|
||||
throwOnLoadError: true,
|
||||
workspaceDir: "/tmp/workspace",
|
||||
});
|
||||
});
|
||||
|
||||
it("reloads when escalating from configured-channels to channels", () => {
|
||||
@@ -236,20 +282,14 @@ describe("ensurePluginRegistryLoaded", () => {
|
||||
ensurePluginRegistryLoaded({ scope: "channels" });
|
||||
|
||||
expect(mocks.loadOpenClawPlugins).toHaveBeenCalledTimes(2);
|
||||
expect(mocks.loadOpenClawPlugins).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
expect.objectContaining({
|
||||
onlyPluginIds: ["demo-channel-a"],
|
||||
throwOnLoadError: true,
|
||||
}),
|
||||
);
|
||||
expect(mocks.loadOpenClawPlugins).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
expect.objectContaining({
|
||||
onlyPluginIds: ["demo-channel-a", "demo-channel-b"],
|
||||
throwOnLoadError: true,
|
||||
}),
|
||||
);
|
||||
expectLoadOpenClawPluginsCall(0, {
|
||||
onlyPluginIds: ["demo-channel-a"],
|
||||
throwOnLoadError: true,
|
||||
});
|
||||
expectLoadOpenClawPluginsCall(1, {
|
||||
onlyPluginIds: ["demo-channel-a", "demo-channel-b"],
|
||||
throwOnLoadError: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("does not treat a pre-seeded partial registry as all scope", () => {
|
||||
@@ -276,14 +316,12 @@ describe("ensurePluginRegistryLoaded", () => {
|
||||
ensurePluginRegistryLoaded({ scope: "all" });
|
||||
|
||||
expect(mocks.loadOpenClawPlugins).toHaveBeenCalledTimes(1);
|
||||
expect(mocks.loadOpenClawPlugins).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
config,
|
||||
onlyPluginIds: ["demo"],
|
||||
throwOnLoadError: true,
|
||||
workspaceDir: "/tmp/workspace",
|
||||
}),
|
||||
);
|
||||
expectLoadOpenClawPluginsCall(0, {
|
||||
config,
|
||||
onlyPluginIds: ["demo"],
|
||||
throwOnLoadError: true,
|
||||
workspaceDir: "/tmp/workspace",
|
||||
});
|
||||
});
|
||||
|
||||
it("does not treat a tools-only pre-seeded registry as channel scope", () => {
|
||||
@@ -312,15 +350,13 @@ describe("ensurePluginRegistryLoaded", () => {
|
||||
ensurePluginRegistryLoaded({ scope: "configured-channels" });
|
||||
|
||||
expect(mocks.loadOpenClawPlugins).toHaveBeenCalledTimes(1);
|
||||
expect(mocks.loadOpenClawPlugins).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
config: activatedConfig,
|
||||
activationSourceConfig: activatedConfig,
|
||||
onlyPluginIds: ["demo-channel-a"],
|
||||
throwOnLoadError: true,
|
||||
workspaceDir: "/tmp/workspace",
|
||||
}),
|
||||
);
|
||||
expectLoadOpenClawPluginsCall(0, {
|
||||
config: activatedConfig,
|
||||
activationSourceConfig: activatedConfig,
|
||||
onlyPluginIds: ["demo-channel-a"],
|
||||
throwOnLoadError: true,
|
||||
workspaceDir: "/tmp/workspace",
|
||||
});
|
||||
});
|
||||
|
||||
it("reloads when a pre-seeded channel registry is missing the configured channel plugin ids", () => {
|
||||
@@ -353,14 +389,12 @@ describe("ensurePluginRegistryLoaded", () => {
|
||||
ensurePluginRegistryLoaded({ scope: "configured-channels" });
|
||||
|
||||
expect(mocks.loadOpenClawPlugins).toHaveBeenCalledTimes(1);
|
||||
expect(mocks.loadOpenClawPlugins).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
config: activatedConfig,
|
||||
activationSourceConfig: activatedConfig,
|
||||
onlyPluginIds: ["demo-channel-a"],
|
||||
throwOnLoadError: true,
|
||||
workspaceDir: "/tmp/workspace",
|
||||
}),
|
||||
);
|
||||
expectLoadOpenClawPluginsCall(0, {
|
||||
config: activatedConfig,
|
||||
activationSourceConfig: activatedConfig,
|
||||
onlyPluginIds: ["demo-channel-a"],
|
||||
throwOnLoadError: true,
|
||||
workspaceDir: "/tmp/workspace",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user