From 1bec458950266d5e8340124a953c5ee73c5af2e2 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 15 Mar 2026 15:24:09 -0700 Subject: [PATCH] Tests: cover invalid plugin command reply payloads --- src/plugins/commands.test.ts | 85 ++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/src/plugins/commands.test.ts b/src/plugins/commands.test.ts index 64f953fb014..3685300e71e 100644 --- a/src/plugins/commands.test.ts +++ b/src/plugins/commands.test.ts @@ -198,4 +198,89 @@ describe("registerPluginCommand", () => { }), ); }); + + it("returns a safe error payload when a runtime plugin command returns undefined", async () => { + const handler = async () => undefined as unknown as { text: string }; + const command = { + name: "unsafe", + description: "Demo command", + acceptsArgs: false, + handler, + pluginId: "demo-plugin", + }; + + const result = await executePluginCommand({ + command, + channel: "discord", + senderId: "U123", + isAuthorizedSender: true, + commandBody: "/unsafe", + config: {} as never, + }); + + expect(result).toEqual({ + text: "⚠️ Command failed. Please try again later.", + isError: true, + }); + }); + + it("returns a safe error payload when a runtime plugin command returns an empty object", async () => { + const handler = async () => ({}) as { text: string }; + const command = { + name: "empty", + description: "Demo command", + acceptsArgs: false, + handler, + pluginId: "demo-plugin", + }; + + const result = await executePluginCommand({ + command, + channel: "discord", + senderId: "U123", + isAuthorizedSender: true, + commandBody: "/empty", + config: {} as never, + }); + + expect(result).toEqual({ + text: "⚠️ Command failed. Please try again later.", + isError: true, + }); + }); + + it("preserves channelData-only plugin replies", async () => { + const handler = async () => + ({ + channelData: { + discord: { + components: [{ type: 1, components: [] }], + }, + }, + }) as unknown as { text: string }; + const command = { + name: "interactive", + description: "Demo command", + acceptsArgs: false, + handler, + pluginId: "demo-plugin", + }; + + const result = await executePluginCommand({ + command, + channel: "discord", + senderId: "U123", + isAuthorizedSender: true, + commandBody: "/interactive", + config: {} as never, + }); + + expect(result).toEqual({ + channelData: { + discord: { + components: [{ type: 1, components: [] }], + }, + }, + }); + }); });