desktopMcpTelemetry.test.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { beforeEach, describe, expect, it, vi } from "vitest";
  2. const sendCustom = vi.fn();
  3. vi.mock("@arms/rum-electron", () => ({
  4. default: { sendCustom },
  5. }));
  6. describe("desktopMcpTelemetry", () => {
  7. beforeEach(() => {
  8. vi.clearAllMocks();
  9. });
  10. it("maps lifecycle facts and drops legacy memory telemetry (PRT-019)", async () => {
  11. const { configureDesktopMcpTelemetry, reportMcpTelemetryToArms } =
  12. await import("../src/main/desktopMcpTelemetry.js");
  13. configureDesktopMcpTelemetry({
  14. appVersion: "3.6.1-test",
  15. armsEnv: "test",
  16. deviceMid: "device-a",
  17. });
  18. const base = { arch: "arm64", occurredAt: 1_000, platform: "darwin" } as const;
  19. reportMcpTelemetryToArms(
  20. {
  21. ...base,
  22. kind: "process_start",
  23. mcpId: "builtin:node_repl",
  24. mcpInstanceId: "mcp-instance-1",
  25. mcpIsolation: "workspace",
  26. mcpSource: "builtin",
  27. },
  28. "local",
  29. );
  30. reportMcpTelemetryToArms(
  31. {
  32. ...base,
  33. affectedSessionCount: 2,
  34. exitCode: 1,
  35. kind: "process_crash",
  36. mcpId: "builtin:node_repl",
  37. mcpInstanceId: "mcp-instance-1",
  38. mcpIsolation: "workspace",
  39. mcpSource: "builtin",
  40. signal: null,
  41. uptimeMs: 10_000,
  42. },
  43. "local",
  44. );
  45. reportMcpTelemetryToArms(
  46. {
  47. ...base,
  48. configuredCount: 3,
  49. connectedCount: 2,
  50. failedCount: 1,
  51. kind: "session_startup",
  52. processCount: 1,
  53. sessionId: "session-1",
  54. },
  55. "remote",
  56. );
  57. reportMcpTelemetryToArms(
  58. {
  59. ...base,
  60. kind: "memory",
  61. mcpId: "custom:123456789abc",
  62. mcpInstanceId: "mcp-instance-2",
  63. mcpIsolation: "session",
  64. mcpSource: "custom",
  65. memoryKb: 65_536,
  66. memoryScope: "process_tree",
  67. orphanSuspected: true,
  68. ownerSessionCount: 0,
  69. unownedSeconds: 61,
  70. },
  71. "remote",
  72. );
  73. expect(sendCustom.mock.calls.map(([payload]) => payload.name)).toEqual([
  74. "perf_mcp_process_start",
  75. "perf_mcp_process_crash",
  76. "perf_mcp_session_startup",
  77. ]);
  78. expect(sendCustom.mock.calls[0]?.[0]).toMatchObject({ group: "stability", value: 1 });
  79. expect(sendCustom.mock.calls[2]?.[0]).toMatchObject({ group: "stability", value: 1 });
  80. expect(JSON.stringify(sendCustom.mock.calls)).not.toContain("mcpServerName");
  81. });
  82. });