pluginSlashCommandRefresh.test.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { describe, expect, it } from "vitest";
  2. import type { ZCodeCommand, ZCodeSlashCommand } from "@zcode/shared";
  3. import { mergeSlashCommandsAfterCommandRefresh } from "../src/settings/pluginSlashCommandRefresh.js";
  4. function makePluginCommand(
  5. overrides: Partial<Extract<ZCodeCommand, { source: "plugin" }>>,
  6. ): Extract<ZCodeCommand, { source: "plugin" }> {
  7. return {
  8. id: "plugin:team-market:hello-world:hello:/remote/commands/hello.md",
  9. name: "hello",
  10. prompt: "Say hello",
  11. content: "# hello",
  12. filePath: "/remote/commands/hello.md",
  13. source: "plugin",
  14. enabled: true,
  15. pluginName: "hello-world",
  16. pluginMarketplace: "team-market",
  17. pluginEnabled: true,
  18. scope: "global",
  19. ...overrides,
  20. };
  21. }
  22. describe("plugin slash command refresh", () => {
  23. it("keeps builtin slash commands while replacing refreshed custom commands", () => {
  24. const current: ZCodeSlashCommand[] = [
  25. {
  26. name: "compact",
  27. description: "Compact",
  28. inputHint: "/compact [instructions]",
  29. source: "builtin",
  30. },
  31. {
  32. name: "old-plugin",
  33. description: "Old plugin command",
  34. inputHint: "/old-plugin",
  35. source: "custom",
  36. },
  37. ];
  38. const next = mergeSlashCommandsAfterCommandRefresh(current, [
  39. makePluginCommand({
  40. name: "hello",
  41. description: "Hello plugin command",
  42. argumentHint: "[name]",
  43. }),
  44. makePluginCommand({
  45. name: "disabled",
  46. enabled: false,
  47. }),
  48. makePluginCommand({
  49. name: "compact",
  50. description: "Should not replace builtin",
  51. }),
  52. ]);
  53. expect(next).toEqual([
  54. {
  55. name: "compact",
  56. description: "Compact",
  57. inputHint: "/compact [instructions]",
  58. source: "builtin",
  59. },
  60. {
  61. name: "hello",
  62. description: "Hello plugin command",
  63. inputHint: "/hello [name]",
  64. source: "custom",
  65. },
  66. ]);
  67. });
  68. });