test: keep command registry native overrides hermetic

This commit is contained in:
Gustavo Madeira Santana
2026-04-17 15:41:09 -04:00
parent fde25bfb8c
commit c550642cde
3 changed files with 88 additions and 1 deletions

View File

@@ -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");
});
});

View File

@@ -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", () => {

View File

@@ -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) {