|
| 1 | +// pnpm --filter @roo-code/telemetry test src/__tests__/TelemetryService.consecutive-mistake.test.ts |
| 2 | + |
| 3 | +import { TelemetryEventName, type TelemetryClient } from "@roo-code/types" |
| 4 | + |
| 5 | +import { TelemetryService } from "../TelemetryService" |
| 6 | + |
| 7 | +describe("TelemetryService.captureConsecutiveMistakeError", () => { |
| 8 | + let mockClient: TelemetryClient |
| 9 | + |
| 10 | + beforeEach(() => { |
| 11 | + mockClient = { |
| 12 | + setProvider: vi.fn(), |
| 13 | + capture: vi.fn().mockResolvedValue(undefined), |
| 14 | + captureException: vi.fn().mockResolvedValue(undefined), |
| 15 | + updateTelemetryState: vi.fn(), |
| 16 | + isTelemetryEnabled: vi.fn().mockReturnValue(true), |
| 17 | + shutdown: vi.fn().mockResolvedValue(undefined), |
| 18 | + } |
| 19 | + }) |
| 20 | + |
| 21 | + it.each(["no_tools_used", "tool_repetition"] as const)( |
| 22 | + "sends reason, count and limit for %s without a separate exception", |
| 23 | + (reason) => { |
| 24 | + const service = new TelemetryService([mockClient]) |
| 25 | + |
| 26 | + service.captureConsecutiveMistakeError("task_1", reason, 3, 5) |
| 27 | + |
| 28 | + expect(mockClient.capture).toHaveBeenCalledWith({ |
| 29 | + event: TelemetryEventName.CONSECUTIVE_MISTAKE_ERROR, |
| 30 | + properties: { |
| 31 | + taskId: "task_1", |
| 32 | + reason, |
| 33 | + consecutiveMistakeCount: 3, |
| 34 | + consecutiveMistakeLimit: 5, |
| 35 | + }, |
| 36 | + }) |
| 37 | + expect(mockClient.captureException).not.toHaveBeenCalled() |
| 38 | + }, |
| 39 | + ) |
| 40 | +}) |
0 commit comments