remoteWorkspaceServicePortBridge.test.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { describe, expect, it, vi } from "vitest";
  2. import { InternalChannels } from "@zcode/shared";
  3. import {
  4. notifyRemoteWorkspaceServicePortReady,
  5. parseRemoteWorkspaceServicePortMessage,
  6. } from "../src/renderer/src/remoteWorkspaceServicePortBridge.js";
  7. describe("remoteWorkspaceServicePortBridge", () => {
  8. it("解析带 attachmentId 的 scoped service port", () => {
  9. const port = {} as MessagePort;
  10. const target = { kind: "ssh", host: "dev.internal", username: "developer" } as const;
  11. expect(
  12. parseRemoteWorkspaceServicePortMessage({
  13. data: {
  14. type: InternalChannels.ScopedServicePort,
  15. attachmentId: "attachment-b",
  16. sessionId: "remote-session-1",
  17. target,
  18. },
  19. ports: [port],
  20. } as unknown as MessageEvent),
  21. ).toEqual({
  22. attachmentId: "attachment-b",
  23. port,
  24. sessionId: "remote-session-1",
  25. target,
  26. });
  27. });
  28. it("services 注册完成后发送 attachment-ready ACK", () => {
  29. const postMessage = vi.fn();
  30. notifyRemoteWorkspaceServicePortReady(
  31. { attachmentId: "attachment-b", sessionId: "remote-session-1" },
  32. postMessage,
  33. );
  34. expect(postMessage).toHaveBeenCalledWith(
  35. {
  36. type: InternalChannels.ScopedServicePortReady,
  37. attachmentId: "attachment-b",
  38. sessionId: "remote-session-1",
  39. },
  40. "*",
  41. );
  42. });
  43. });