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

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