fix(cli): resolve message channel plugin scopes

This commit is contained in:
Peter Steinberger
2026-04-27 21:02:00 +01:00
parent 0c305596a2
commit 5e49e8590d
7 changed files with 98 additions and 10 deletions

View File

@@ -34,6 +34,10 @@ const mocks = vi.hoisted(() => ({
getActivePluginRegistry: vi.fn<typeof import("../plugins/runtime.js").getActivePluginRegistry>(),
resolveConfiguredChannelPluginIds:
vi.fn<typeof import("../plugins/channel-plugin-ids.js").resolveConfiguredChannelPluginIds>(),
resolveDiscoverableScopedChannelPluginIds:
vi.fn<
typeof import("../plugins/channel-plugin-ids.js").resolveDiscoverableScopedChannelPluginIds
>(),
resolveChannelPluginIds:
vi.fn<typeof import("../plugins/channel-plugin-ids.js").resolveChannelPluginIds>(),
resolvePluginRuntimeLoadContext:
@@ -59,6 +63,9 @@ vi.mock("../plugins/channel-plugin-ids.js", () => ({
resolveConfiguredChannelPluginIds: (
...args: Parameters<typeof mocks.resolveConfiguredChannelPluginIds>
) => mocks.resolveConfiguredChannelPluginIds(...args),
resolveDiscoverableScopedChannelPluginIds: (
...args: Parameters<typeof mocks.resolveDiscoverableScopedChannelPluginIds>
) => mocks.resolveDiscoverableScopedChannelPluginIds(...args),
resolveChannelPluginIds: (...args: Parameters<typeof mocks.resolveChannelPluginIds>) =>
mocks.resolveChannelPluginIds(...args),
}));
@@ -119,12 +126,14 @@ describe("ensurePluginRegistryLoaded", () => {
mocks.resolveRuntimePluginRegistry.mockReset();
mocks.getActivePluginRegistry.mockReset();
mocks.resolveConfiguredChannelPluginIds.mockReset();
mocks.resolveDiscoverableScopedChannelPluginIds.mockReset();
mocks.resolveChannelPluginIds.mockReset();
mocks.resolvePluginRuntimeLoadContext.mockReset();
resetPluginRegistryLoadedForTests();
mocks.getActivePluginRegistry.mockReturnValue(createEmptyPluginRegistry());
mocks.resolveRuntimePluginRegistry.mockReturnValue(undefined);
mocks.resolveDiscoverableScopedChannelPluginIds.mockReturnValue([]);
mocks.resolvePluginRuntimeLoadContext.mockImplementation((options) => {
const rawConfig = (options?.config ?? {}) as Record<string, unknown>;
return {

View File

@@ -98,7 +98,7 @@ describe("runMessageAction", () => {
expect(ensurePluginRegistryLoaded).toHaveBeenCalledWith({
scope: "configured-channels",
onlyPluginIds: ["discord"],
onlyChannelIds: ["discord"],
});
expect(exitMock).toHaveBeenCalledOnce();
expect(exitMock).toHaveBeenCalledWith(0);
@@ -117,7 +117,7 @@ describe("runMessageAction", () => {
expect(ensurePluginRegistryLoaded).toHaveBeenCalledWith({
scope: "configured-channels",
onlyPluginIds: ["telegram"],
onlyChannelIds: ["telegram"],
});
});

View File

@@ -34,14 +34,14 @@ async function runPluginStopHooks(): Promise<void> {
function resolveMessagePluginLoadOptions(
opts: Record<string, unknown>,
): { scope: PluginRegistryScope; onlyPluginIds?: string[] } | undefined {
): { scope: PluginRegistryScope; onlyChannelIds?: string[] } | undefined {
const scopedChannel = resolveMessageSecretScope({
channel: opts.channel,
target: opts.target,
targets: opts.targets,
}).channel;
if (scopedChannel) {
return { scope: "configured-channels", onlyPluginIds: [scopedChannel] };
return { scope: "configured-channels", onlyChannelIds: [scopedChannel] };
}
return { scope: "configured-channels" };
}