mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-16 01:40:43 +00:00
fix(cli): narrow message plugin registry loads
This commit is contained in:
@@ -96,11 +96,46 @@ describe("runMessageAction", () => {
|
||||
it("calls exit(0) after successful message delivery", async () => {
|
||||
await runSendAction();
|
||||
|
||||
expect(ensurePluginRegistryLoaded).toHaveBeenCalledOnce();
|
||||
expect(ensurePluginRegistryLoaded).toHaveBeenCalledWith({
|
||||
scope: "configured-channels",
|
||||
onlyPluginIds: ["discord"],
|
||||
});
|
||||
expect(exitMock).toHaveBeenCalledOnce();
|
||||
expect(exitMock).toHaveBeenCalledWith(0);
|
||||
});
|
||||
|
||||
it("loads configured channel plugins when no target channel is known yet", async () => {
|
||||
await runSendAction({ channel: undefined });
|
||||
|
||||
expect(ensurePluginRegistryLoaded).toHaveBeenCalledWith({
|
||||
scope: "configured-channels",
|
||||
});
|
||||
});
|
||||
|
||||
it("narrows plugin loading from a channel-prefixed target", async () => {
|
||||
await runSendAction({ channel: undefined, target: "telegram:12345" });
|
||||
|
||||
expect(ensurePluginRegistryLoaded).toHaveBeenCalledWith({
|
||||
scope: "configured-channels",
|
||||
onlyPluginIds: ["telegram"],
|
||||
});
|
||||
});
|
||||
|
||||
it("loads configured channel plugins for mixed broadcast target prefixes", async () => {
|
||||
const runMessageAction = createRunMessageAction();
|
||||
|
||||
await expect(
|
||||
runMessageAction("broadcast", {
|
||||
targets: ["discord:channel:1", "telegram:123"],
|
||||
message: "hi",
|
||||
}),
|
||||
).rejects.toThrow("exit");
|
||||
|
||||
expect(ensurePluginRegistryLoaded).toHaveBeenCalledWith({
|
||||
scope: "configured-channels",
|
||||
});
|
||||
});
|
||||
|
||||
it("runs gateway_stop hooks before exit when registered", async () => {
|
||||
hasHooksMock.mockReturnValueOnce(true);
|
||||
await runSendAction();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Command } from "commander";
|
||||
import { resolveMessageSecretScope } from "../../../cli/message-secret-scope.js";
|
||||
import { messageCommand } from "../../../commands/message.js";
|
||||
import { danger, setVerbose } from "../../../globals.js";
|
||||
import { CHANNEL_TARGET_DESCRIPTION } from "../../../infra/outbound/channel-target.js";
|
||||
@@ -6,7 +7,7 @@ import { runGlobalGatewayStopSafely } from "../../../plugins/hook-runner-global.
|
||||
import { defaultRuntime } from "../../../runtime.js";
|
||||
import { runCommandWithRuntime } from "../../cli-utils.js";
|
||||
import { createDefaultDeps } from "../../deps.js";
|
||||
import { ensurePluginRegistryLoaded } from "../../plugin-registry.js";
|
||||
import { ensurePluginRegistryLoaded, type PluginRegistryScope } from "../../plugin-registry.js";
|
||||
|
||||
export type MessageCliHelpers = {
|
||||
withMessageBase: (command: Command) => Command;
|
||||
@@ -31,6 +32,20 @@ async function runPluginStopHooks(): Promise<void> {
|
||||
});
|
||||
}
|
||||
|
||||
function resolveMessagePluginLoadOptions(
|
||||
opts: Record<string, unknown>,
|
||||
): { scope: PluginRegistryScope; onlyPluginIds?: 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" };
|
||||
}
|
||||
|
||||
export function createMessageCliHelpers(
|
||||
message: Command,
|
||||
messageChannelOptions: string,
|
||||
@@ -50,7 +65,7 @@ export function createMessageCliHelpers(
|
||||
|
||||
const runMessageAction = async (action: string, opts: Record<string, unknown>) => {
|
||||
setVerbose(Boolean(opts.verbose));
|
||||
ensurePluginRegistryLoaded();
|
||||
ensurePluginRegistryLoaded(resolveMessagePluginLoadOptions(opts));
|
||||
const deps = createDefaultDeps();
|
||||
let failed = false;
|
||||
await runCommandWithRuntime(
|
||||
|
||||
Reference in New Issue
Block a user