pluginCreatorPrefill.test.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { describe, expect, it } from "vitest";
  2. import type { SkillSummary } from "@zcode/shared";
  3. import { buildPluginCreatorPrefill } from "@/settings/pluginCreatorPrefill.js";
  4. const creator: SkillSummary = {
  5. id: "official-creator",
  6. name: "plugin-creator",
  7. description: "Create plugins",
  8. body: "",
  9. path: "/remote space/plugins/creator/SKILL.md",
  10. scope: "plugin",
  11. enabled: true,
  12. pluginName: "plugin-creator",
  13. pluginId: "plugin-creator@zcode-plugins-official",
  14. };
  15. describe("Plugin Creator prefill", () => {
  16. it("binds the real official skill path and preserves trailing space without submission", () => {
  17. const result = buildPluginCreatorPrefill([creator]);
  18. expect(result.initialPrompt).toBe("[$plugin-creator](/remote space/plugins/creator/SKILL.md) ");
  19. expect(result.initialPromptMention).toMatchObject({
  20. id: "skill:official-creator",
  21. category: "skills",
  22. value: "plugin-creator",
  23. data: { path: creator.path, scope: "plugin" },
  24. });
  25. expect(result).not.toHaveProperty("autoSubmit");
  26. });
  27. it("rejects missing, disabled and wrong-market same-name skills", () => {
  28. for (const entries of [
  29. [],
  30. [{ ...creator, enabled: false }],
  31. [{ ...creator, path: "" }],
  32. [{ ...creator, pluginId: "plugin-creator@third-party" }],
  33. ]) {
  34. expect(() => buildPluginCreatorPrefill(entries)).toThrow();
  35. }
  36. });
  37. });
  38. it("discards a completed lookup after its workspace identity is superseded", async () => {
  39. const { loadPluginCreatorPrefill } = await import("@/settings/pluginCreatorPrefill.js");
  40. let finish!: (result: { skills: SkillSummary[] }) => void;
  41. let current = true;
  42. const result = loadPluginCreatorPrefill(
  43. () =>
  44. new Promise((resolve) => {
  45. finish = resolve;
  46. }),
  47. () => current,
  48. );
  49. current = false;
  50. finish({ skills: [creator] });
  51. expect(await result).toBeNull();
  52. });