plugin-lifecycle-telemetry.test.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { clearAppData } from "#e2e/helpers/desktop-app";
  2. import {
  3. PLUGIN_LIFECYCLE_ID,
  4. addLifecycleMarketplaceThroughUi,
  5. clickPluginControl,
  6. createPluginLifecycleFixture,
  7. openPluginCard,
  8. openPluginSettings,
  9. requirePluginManualReview,
  10. waitUntilPluginOverview,
  11. } from "#e2e/helpers/plugin-management-lifecycle";
  12. describe("PLM-TEL-001 plugin lifecycle telemetry", () => {
  13. after(async () => {
  14. await browser.electron.restoreAllMocks();
  15. await clearAppData();
  16. });
  17. it("reports one installation outcome after the real UI action without private data", async function () {
  18. this.timeout(180000);
  19. requirePluginManualReview();
  20. const fixture = await createPluginLifecycleFixture("1.0.0");
  21. await openPluginSettings();
  22. await addLifecycleMarketplaceThroughUi(fixture);
  23. await clickPluginControl("plugin-store-segment-personal");
  24. await openPluginCard(PLUGIN_LIFECYCLE_ID);
  25. const transport = await browser.electron.mock("net", "fetch");
  26. await transport.mockResolvedValue({ ok: true, status: 204 });
  27. const reports = async () => {
  28. await transport.update();
  29. return transport.mock.calls.flatMap((call) => {
  30. if (!String(call[0]).includes("/event/report")) return [];
  31. const body = (call[1] as { body?: string })?.body;
  32. if (!body) return [];
  33. const event = JSON.parse(body);
  34. return event.element_name === "plugin_lifecycle" &&
  35. event.event_extra_detail?.action === "install"
  36. ? [event]
  37. : [];
  38. });
  39. };
  40. expect(await reports()).toEqual([]);
  41. await clickPluginControl("plugin-store-install", { pluginId: PLUGIN_LIFECYCLE_ID });
  42. await waitUntilPluginOverview(
  43. (overview) => overview.installedPlugins.some((plugin) => plugin.id === PLUGIN_LIFECYCLE_ID),
  44. "plugin did not install",
  45. 90000,
  46. );
  47. await browser.waitUntil(async () => (await reports()).length === 1, {
  48. timeout: 15000,
  49. timeoutMsg: "missing plugin installation telemetry",
  50. });
  51. const [event] = await reports();
  52. expect(event.event_id).toBeTruthy();
  53. expect(event.event_extra_detail).toMatchObject({
  54. action: "install",
  55. result: "success",
  56. plugin_id: PLUGIN_LIFECYCLE_ID,
  57. entry: "store_detail",
  58. client_kind: "desktop",
  59. });
  60. expect(Number(event.event_extra_detail.duration_ms)).toBeGreaterThanOrEqual(0);
  61. expect(event.event_extra_detail).not.toHaveProperty("operation_id");
  62. expect(JSON.stringify(event.event_extra_detail)).not.toContain("/Users/");
  63. expect(JSON.stringify(event.event_extra_detail)).not.toContain("workspacePath");
  64. });
  65. });