From c550642cdec9a32909ff6bb574e85dbe6758c60a Mon Sep 17 00:00:00 2001 From: Gustavo Madeira Santana Date: Fri, 17 Apr 2026 15:41:09 -0400 Subject: [PATCH] test: keep command registry native overrides hermetic --- extensions/discord/src/shared.test.ts | 21 +++++++++++ extensions/slack/src/shared.test.ts | 24 ++++++++++++- src/auto-reply/commands-registry.test.ts | 44 ++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 extensions/discord/src/shared.test.ts diff --git a/extensions/discord/src/shared.test.ts b/extensions/discord/src/shared.test.ts new file mode 100644 index 00000000000..3d6af28d4fa --- /dev/null +++ b/extensions/discord/src/shared.test.ts @@ -0,0 +1,21 @@ +import { describe, expect, it } from "vitest"; +import { createDiscordPluginBase } from "./shared.js"; + +describe("createDiscordPluginBase", () => { + it("owns Discord native command name overrides", () => { + const plugin = createDiscordPluginBase({ setup: {} as never }); + + expect( + plugin.commands?.resolveNativeCommandName?.({ + commandKey: "tts", + defaultName: "tts", + }), + ).toBe("voice"); + expect( + plugin.commands?.resolveNativeCommandName?.({ + commandKey: "status", + defaultName: "status", + }), + ).toBe("status"); + }); +}); diff --git a/extensions/slack/src/shared.test.ts b/extensions/slack/src/shared.test.ts index 69181159e61..c2ba08091bf 100644 --- a/extensions/slack/src/shared.test.ts +++ b/extensions/slack/src/shared.test.ts @@ -1,5 +1,27 @@ import { describe, expect, it } from "vitest"; -import { setSlackChannelAllowlist } from "./shared.js"; +import { createSlackPluginBase, setSlackChannelAllowlist } from "./shared.js"; + +describe("createSlackPluginBase", () => { + it("owns Slack native command name overrides", () => { + const plugin = createSlackPluginBase({ + setup: {} as never, + setupWizard: {} as never, + }); + + expect( + plugin.commands?.resolveNativeCommandName?.({ + commandKey: "status", + defaultName: "status", + }), + ).toBe("agentstatus"); + expect( + plugin.commands?.resolveNativeCommandName?.({ + commandKey: "tts", + defaultName: "tts", + }), + ).toBe("tts"); + }); +}); describe("setSlackChannelAllowlist", () => { it("writes canonical enabled entries for setup-generated channel allowlists", () => { diff --git a/src/auto-reply/commands-registry.test.ts b/src/auto-reply/commands-registry.test.ts index 989c835f959..af81f326074 100644 --- a/src/auto-reply/commands-registry.test.ts +++ b/src/auto-reply/commands-registry.test.ts @@ -19,6 +19,47 @@ import { } from "./commands-registry.js"; import type { ChatCommandDefinition } from "./commands-registry.types.js"; +type NativeCommandNameResolver = (params: { commandKey: string; defaultName: string }) => string; + +function installNativeCommandOverridePlugin(params: { + id: "discord" | "slack"; + resolveNativeCommandName: NativeCommandNameResolver; +}) { + setActivePluginRegistry( + createTestRegistry([ + { + pluginId: params.id, + plugin: { + ...createChannelTestPluginBase({ + id: params.id, + capabilities: { nativeCommands: true, chatTypes: ["direct"] }, + }), + commands: { + resolveNativeCommandName: params.resolveNativeCommandName, + }, + }, + source: "test", + }, + ]), + ); +} + +function installDiscordNativeCommandOverrides() { + installNativeCommandOverridePlugin({ + id: "discord", + resolveNativeCommandName: ({ commandKey, defaultName }) => + commandKey === "tts" ? "voice" : defaultName, + }); +} + +function installSlackNativeCommandOverrides() { + installNativeCommandOverridePlugin({ + id: "slack", + resolveNativeCommandName: ({ commandKey, defaultName }) => + commandKey === "status" ? "agentstatus" : defaultName, + }); +} + beforeEach(() => { vi.doUnmock("../channels/plugins/index.js"); setActivePluginRegistry(createTestRegistry([])); @@ -112,6 +153,7 @@ describe("commands registry", () => { }); it("applies discord native command overrides", () => { + installDiscordNativeCommandOverrides(); const native = listNativeCommandSpecsForConfig( { commands: { native: true } }, { provider: "discord" }, @@ -122,6 +164,7 @@ describe("commands registry", () => { }); it("applies slack native command overrides", () => { + installSlackNativeCommandOverrides(); const native = listNativeCommandSpecsForConfig( { commands: { native: true } }, { provider: "slack" }, @@ -132,6 +175,7 @@ describe("commands registry", () => { }); it("keeps discord native command specs within slash-command limits", () => { + installDiscordNativeCommandOverrides(); const cfg = { commands: { native: true } }; const native = listNativeCommandSpecsForConfig(cfg, { provider: "discord" }); for (const spec of native) {