Tests: validate discord slash command options

This commit is contained in:
Shadow
2026-02-27 18:40:53 -06:00
parent 32ee2f0109
commit 5cb2a3aa1b

View File

@@ -12,6 +12,7 @@ import {
listNativeCommandSpecsForConfig,
normalizeCommandBody,
parseCommandArgs,
resolveCommandArgChoices,
resolveCommandArgMenu,
serializeCommandArgs,
shouldHandleTextCommands,
@@ -121,18 +122,54 @@ describe("commands registry", () => {
});
it("keeps discord native command specs within slash-command limits", () => {
const native = listNativeCommandSpecsForConfig(
{ commands: { native: true } },
{ provider: "discord" },
);
const cfg = { commands: { native: true } };
const native = listNativeCommandSpecsForConfig(cfg, { provider: "discord" });
for (const spec of native) {
expect(spec.name).toMatch(/^[a-z0-9_-]{1,32}$/);
expect(spec.description.length).toBeGreaterThan(0);
expect(spec.description.length).toBeLessThanOrEqual(100);
for (const arg of spec.args ?? []) {
expect(spec.args?.length ?? 0).toBeLessThanOrEqual(25);
const command = findCommandByNativeName(spec.name, "discord");
expect(command).toBeTruthy();
const args = command?.args ?? spec.args ?? [];
const argNames = new Set<string>();
let sawOptional = false;
for (const arg of args) {
expect(argNames.has(arg.name)).toBe(false);
argNames.add(arg.name);
const isRequired = arg.required ?? false;
if (!isRequired) {
sawOptional = true;
} else {
expect(sawOptional).toBe(false);
}
expect(arg.name).toMatch(/^[a-z0-9_-]{1,32}$/);
expect(arg.description.length).toBeGreaterThan(0);
expect(arg.description.length).toBeLessThanOrEqual(100);
if (!command) {
continue;
}
const choices = resolveCommandArgChoices({
command,
arg,
cfg,
provider: "discord",
});
if (choices.length === 0) {
continue;
}
expect(choices.length).toBeLessThanOrEqual(25);
for (const choice of choices) {
expect(choice.label.length).toBeGreaterThan(0);
expect(choice.label.length).toBeLessThanOrEqual(100);
expect(choice.value.length).toBeGreaterThan(0);
expect(choice.value.length).toBeLessThanOrEqual(100);
}
}
}
});