workspacePluginPreview.test.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { describe, expect, it } from "vitest";
  2. import type { ZCodePluginReferenceCatalogEntry } from "@zcode/shared";
  3. import {
  4. buildWorkspacePluginMention,
  5. isWorkspacePluginReferenceable,
  6. } from "../src/WorkspacePluginPreview.js";
  7. function entry(
  8. overrides: Partial<ZCodePluginReferenceCatalogEntry> = {},
  9. ): ZCodePluginReferenceCatalogEntry {
  10. return {
  11. pluginId: "pdf@zcode-plugins-official",
  12. name: "pdf",
  13. marketplace: "zcode-plugins-official",
  14. icon: "https://cdn.example.com/pdf.png",
  15. enabled: true,
  16. conflictingPluginIds: [],
  17. skillQualifiedNames: ["pdf:read"],
  18. mcpServerNames: [],
  19. subagentNames: [],
  20. ...overrides,
  21. };
  22. }
  23. describe("workspace plugin preview", () => {
  24. it("只允许已启用且无冲突的 workspace catalog 插件被引用", () => {
  25. expect(isWorkspacePluginReferenceable(entry())).toBe(true);
  26. expect(isWorkspacePluginReferenceable(entry({ enabled: false }))).toBe(false);
  27. expect(
  28. isWorkspacePluginReferenceable(entry({ conflictingPluginIds: ["pdf@personal-marketplace"] })),
  29. ).toBe(false);
  30. });
  31. it("构造与 Composer @ Picker 相同的 canonical 插件引用", () => {
  32. expect(buildWorkspacePluginMention(entry())).toEqual({
  33. id: "plugin:pdf@zcode-plugins-official",
  34. category: "plugins",
  35. label: "pdf",
  36. value: "pdf@zcode-plugins-official",
  37. markdown: "[@pdf](plugin://pdf@zcode-plugins-official)",
  38. data: {
  39. pluginId: "pdf@zcode-plugins-official",
  40. icon: "https://cdn.example.com/pdf.png",
  41. },
  42. });
  43. });
  44. });