fix(cli): trim plugin preloads for setup-safe commands

This commit is contained in:
Peter Steinberger
2026-04-25 23:05:45 +01:00
parent 8d08e86f42
commit cf303b3101
8 changed files with 176 additions and 14 deletions

View File

@@ -13,6 +13,7 @@ vi.mock("../../../globals.js", () => ({
vi.mock("../../plugin-registry.js", () => ({
ensurePluginRegistryLoaded: vi.fn(),
}));
const { ensurePluginRegistryLoaded } = await import("../../plugin-registry.js");
const hasHooksMock = vi.fn((_hookName: string) => false);
const runGatewayStopMock = vi.fn(
@@ -95,6 +96,7 @@ describe("runMessageAction", () => {
it("calls exit(0) after successful message delivery", async () => {
await runSendAction();
expect(ensurePluginRegistryLoaded).toHaveBeenCalledOnce();
expect(exitMock).toHaveBeenCalledOnce();
expect(exitMock).toHaveBeenCalledWith(0);
});

View File

@@ -122,6 +122,7 @@ describe("registerPreActionHooks", () => {
.command("agent")
.requiredOption("-m, --message <text>")
.option("--local")
.option("--json")
.action(() => {});
program
.command("status")
@@ -214,15 +215,15 @@ describe("registerPreActionHooks", () => {
vi.clearAllMocks();
await runPreAction({
parseArgv: ["message", "send"],
processArgv: ["node", "openclaw", "message", "send"],
parseArgv: ["agents", "list"],
processArgv: ["node", "openclaw", "agents", "list"],
});
expect(setVerboseMock).toHaveBeenCalledWith(false);
expect(process.env.NODE_NO_WARNINGS).toBe("1");
expect(ensureConfigReadyMock).toHaveBeenCalledWith({
runtime: runtimeMock,
commandPath: ["message", "send"],
commandPath: ["agents", "list"],
});
expect(ensurePluginRegistryLoadedMock).toHaveBeenCalledWith({ scope: "all" });
processTitleSetSpy.mockRestore();
@@ -393,8 +394,8 @@ describe("registerPreActionHooks", () => {
it("routes logs to stderr in --json mode so stdout stays clean", async () => {
await runPreAction({
parseArgv: ["message", "send"],
processArgv: ["node", "openclaw", "message", "send", "--json"],
parseArgv: ["agent"],
processArgv: ["node", "openclaw", "agent", "--message", "hi", "--json"],
});
expect(routeLogsToStderrMock).toHaveBeenCalledOnce();
@@ -473,8 +474,8 @@ describe("registerPreActionHooks", () => {
});
await runPreAction({
parseArgv: ["message", "send"],
processArgv: ["node", "openclaw", "message", "send", "--json"],
parseArgv: ["agent"],
processArgv: ["node", "openclaw", "agent", "--message", "hi", "--json"],
});
expect(ensurePluginRegistryLoadedMock).toHaveBeenCalled();