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
63 lines
1.6 KiB
TypeScript
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,
|
|
},
|
|
]);
|
|
});
|
|
});
|