Files
Moltbot/src/plugins/commands.test.ts
Cui Chen e8cb0484ce fix(security): strip partial API token from status labels (#33262)
Merged via squash.

Prepared head SHA: 5fe81704e678dc5b18ca9416e5eb0750cfe49fb6
Co-authored-by: cu1ch3n <80438676+cu1ch3n@users.noreply.github.com>
Co-authored-by: grp06 <1573959+grp06@users.noreply.github.com>
Reviewed-by: @grp06
2026-03-03 15:11:49 -08:00

63 lines
1.6 KiB
TypeScript

import { afterEach, describe, expect, it } from "vitest";
import {
clearPluginCommands,
getPluginCommandSpecs,
listPluginCommands,
registerPluginCommand,
} from "./commands.js";
afterEach(() => {
clearPluginCommands();
});
describe("registerPluginCommand", () => {
it("rejects malformed runtime command shapes", () => {
const invalidName = registerPluginCommand(
"demo-plugin",
// Runtime plugin payloads are untyped; guard at boundary.
{
name: undefined as unknown as string,
description: "Demo",
handler: async () => ({ text: "ok" }),
},
);
expect(invalidName).toEqual({
ok: false,
error: "Command name must be a string",
});
const invalidDescription = registerPluginCommand("demo-plugin", {
name: "demo",
description: undefined as unknown as string,
handler: async () => ({ text: "ok" }),
});
expect(invalidDescription).toEqual({
ok: false,
error: "Command description must be a string",
});
});
it("normalizes command metadata for downstream consumers", () => {
const result = registerPluginCommand("demo-plugin", {
name: " demo_cmd ",
description: " Demo command ",
handler: async () => ({ text: "ok" }),
});
expect(result).toEqual({ ok: true });
expect(listPluginCommands()).toEqual([
{
name: "demo_cmd",
description: "Demo command",
pluginId: "demo-plugin",
},
]);
expect(getPluginCommandSpecs()).toEqual([
{
name: "demo_cmd",
description: "Demo command",
acceptsArgs: false,
},
]);
});
});