pluginManagementService.test.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { describe, expect, it, vi } from "vitest";
  2. import { createPluginManagementService } from "../src/plugins/pluginManagementService.js";
  3. import type { IZCodeAgentService } from "../src/zcode-agent/zcodeAgent.js";
  4. describe("pluginManagementService suggested prompt operations", () => {
  5. it("forwards trusted resolution and cancellation to the selected Agent service", async () => {
  6. const progressEvent = vi.fn();
  7. const onDynamicPluginOperationProgress = vi.fn(() => progressEvent);
  8. const resolveSuggestedPluginReference = vi.fn(async () => ({
  9. stableId: "document-skills@zcode-plugins-official",
  10. status: "missing" as const,
  11. marketplace: "zcode-plugins-official",
  12. pluginName: "document-skills",
  13. sourceTrust: "official" as const,
  14. diagnostics: [],
  15. }));
  16. const cancelPluginOperation = vi.fn(async ({ operationId }: { operationId: string }) => ({
  17. operationId,
  18. cancelled: true,
  19. }));
  20. const service = createPluginManagementService({
  21. zcodeAgentService: {
  22. resolveSuggestedPluginReference,
  23. cancelPluginOperation,
  24. onDynamicPluginOperationProgress,
  25. } as unknown as IZCodeAgentService,
  26. });
  27. expect(service.onDynamicPluginOperationProgress("suggested-1")).toBe(progressEvent);
  28. await expect(
  29. service.resolveSuggestedPluginReference({
  30. workspacePath: "/remote/workspace",
  31. workspaceIdentity: "ssh://host/remote/workspace",
  32. remoteSessionId: "remote-session-1",
  33. stableId: "document-skills@zcode-plugins-official",
  34. operationId: "suggested-1",
  35. clientMode: "web-remote-replayable",
  36. deliveryKind: "web-remote-replayable",
  37. }),
  38. ).resolves.toMatchObject({ status: "missing" });
  39. await expect(
  40. service.cancelPluginOperation({ operationId: "suggested-1" }),
  41. ).resolves.toEqual({ operationId: "suggested-1", cancelled: true });
  42. expect(resolveSuggestedPluginReference).toHaveBeenCalledWith({
  43. workspacePath: "/remote/workspace",
  44. workspaceIdentity: "ssh://host/remote/workspace",
  45. remoteSessionId: "remote-session-1",
  46. stableId: "document-skills@zcode-plugins-official",
  47. operationId: "suggested-1",
  48. clientMode: "web-remote-replayable",
  49. deliveryKind: "web-remote-replayable",
  50. });
  51. expect(cancelPluginOperation).toHaveBeenCalledWith({ operationId: "suggested-1" });
  52. expect(onDynamicPluginOperationProgress).toHaveBeenCalledWith("suggested-1");
  53. });
  54. });