Plugins: honor native command aliases at dispatch

This commit is contained in:
Vincent Koc
2026-03-16 21:01:10 -07:00
parent 095a9f6e1d
commit f90d432de3
4 changed files with 147 additions and 1 deletions

View File

@@ -212,6 +212,58 @@ describe("Discord native plugin command dispatch", () => {
);
});
it("round-trips Discord native aliases through the real plugin registry", async () => {
const cfg = createConfig();
const commandSpec: NativeCommandSpec = {
name: "pairdiscord",
description: "Pair",
acceptsArgs: true,
};
const command = createDiscordNativeCommand({
command: commandSpec,
cfg,
discordConfig: cfg.channels?.discord ?? {},
accountId: "default",
sessionPrefix: "discord:slash",
ephemeralDefault: true,
threadBindings: createNoopThreadBindingManager("default"),
});
const interaction = createInteraction();
expect(
registerPluginCommand("demo-plugin", {
name: "pair",
nativeNames: {
telegram: "pair_device",
discord: "pairdiscord",
},
description: "Pair device",
acceptsArgs: true,
requireAuth: false,
handler: async ({ args }) => ({ text: `paired:${args ?? ""}` }),
}),
).toEqual({ ok: true });
const dispatchSpy = vi
.spyOn(dispatcherModule, "dispatchReplyWithDispatcher")
.mockResolvedValue({} as never);
await (command as { run: (interaction: unknown) => Promise<void> }).run(
Object.assign(interaction, {
options: {
getString: () => "now",
getBoolean: () => null,
getFocused: () => "",
},
}) as unknown,
);
expect(dispatchSpy).not.toHaveBeenCalled();
expect(interaction.reply).toHaveBeenCalledWith(
expect.objectContaining({ content: "paired:now" }),
);
});
it("blocks unauthorized Discord senders before requireAuth:false plugin commands execute", async () => {
const cfg = {
commands: {