startupTelemetryDelivery.test.ts 1.3 KB

1234567891011121314151617181920212223242526
  1. import { expect, it, vi } from "vitest";
  2. import { wrapStartupReporterRequest } from "../src/main/startupTelemetryDelivery.js";
  3. it("does not treat HTTP 500 as receipt and retries only startup reports", async () => {
  4. const send = vi
  5. .fn()
  6. .mockResolvedValueOnce({ ok: false, status: 500 })
  7. .mockResolvedValue({ ok: true, status: 200 });
  8. const acknowledged = vi.fn();
  9. const request = wrapStartupReporterRequest(send, { acknowledged, delay: async () => {} });
  10. await request({}, { events: [{ properties: { startup_event_id: "stable-id" } }] });
  11. expect(send).toHaveBeenCalledTimes(2);
  12. expect(acknowledged).toHaveBeenCalledWith(["stable-id"], "http_received");
  13. expect(send.mock.calls[0]?.[1]).toBe(send.mock.calls[1]?.[1]);
  14. await request({}, { events: [{ name: "unrelated" }] });
  15. expect(send).toHaveBeenCalledTimes(3);
  16. });
  17. it("bounds failures without starting a migration or claiming success", async () => {
  18. const send = vi.fn().mockRejectedValue(new Error("offline"));
  19. const acknowledged = vi.fn();
  20. const request = wrapStartupReporterRequest(send, { acknowledged, delay: async () => {} });
  21. await request({}, { events: [{ properties: { startup_event_id: "failed-id" } }] });
  22. expect(send).toHaveBeenCalledTimes(3);
  23. expect(acknowledged).toHaveBeenCalledWith(["failed-id"], "unconfirmed");
  24. });