zcodeAgentService.pluginOperationProgress.test.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { describe, expect, it, vi } from "vitest";
  2. import {
  3. zcodeProtocolMethods,
  4. zcodeProtocolNotifications,
  5. type ZCodePluginOperationProgressNotification,
  6. } from "@zcode/shared";
  7. describe("zcodeAgentService Plugin operation progress", () => {
  8. it("projects a validated Agent progress notification by operationId", async () => {
  9. let notificationListener:
  10. | ((notification: { method: string; params?: unknown }) => void)
  11. | null = null;
  12. const request = vi.fn(async (method: string) => {
  13. if (method !== zcodeProtocolMethods.pluginsResolveSuggestedReference) {
  14. throw new Error(`Unexpected request method: ${method}`);
  15. }
  16. notificationListener?.({
  17. method: zcodeProtocolNotifications.pluginOperationProgress,
  18. params: { operationId: "suggested-progress", state: "refreshing" },
  19. });
  20. return {
  21. stableId: "document-skills@zcode-plugins-official",
  22. status: "missing",
  23. marketplace: "zcode-plugins-official",
  24. pluginName: "document-skills",
  25. sourceTrust: "official",
  26. diagnostics: [],
  27. };
  28. });
  29. vi.resetModules();
  30. vi.doMock("../src/zcode-agent/zcodeAgentProcessManager.js", () => ({
  31. ZCodeAgentProcessManager: class {
  32. onRuntimeLifecycle() {
  33. return { dispose() {} };
  34. }
  35. onRuntimeRestarted() {
  36. return { dispose() {} };
  37. }
  38. async getClient() {
  39. return {
  40. request,
  41. transportKind: "stdio",
  42. onNotification: (
  43. listener: (notification: { method: string; params?: unknown }) => void,
  44. ) => {
  45. notificationListener = listener;
  46. return { dispose() {} };
  47. },
  48. onRequest: () => ({ dispose() {} }),
  49. onClose: () => ({ dispose() {} }),
  50. };
  51. }
  52. disposeAll() {}
  53. async disposeAllAndWait() {}
  54. },
  55. }));
  56. const { createZCodeAgentService } = await import("../src/zcode-agent/zcodeAgentService.js");
  57. const service = createZCodeAgentService();
  58. const received: ZCodePluginOperationProgressNotification[] = [];
  59. const subscription = service.onDynamicPluginOperationProgress("suggested-progress")((event) =>
  60. received.push(event),
  61. );
  62. try {
  63. await service.resolveSuggestedPluginReference({
  64. workspacePath: "/workspace",
  65. stableId: "document-skills@zcode-plugins-official",
  66. operationId: "suggested-progress",
  67. clientMode: "desktop-continuous",
  68. deliveryKind: "desktop-continuous",
  69. });
  70. expect(received).toEqual([{ operationId: "suggested-progress", state: "refreshing" }]);
  71. notificationListener?.({
  72. method: zcodeProtocolNotifications.pluginOperationProgress,
  73. params: {
  74. operationId: "suggested-progress",
  75. state: "refreshing",
  76. unexpected: true,
  77. },
  78. });
  79. expect(received).toHaveLength(1);
  80. } finally {
  81. subscription.dispose();
  82. await service.disposeAllAndWait();
  83. }
  84. });
  85. });