|
1 | 1 | import { describe, it, expect, beforeEach, vi } from "vitest" |
2 | 2 | import { CodeIndexOrchestrator } from "../orchestrator" |
| 3 | +import { TelemetryService } from "@roo-code/telemetry" |
| 4 | +import { TelemetryEventName } from "@roo-code/types" |
3 | 5 |
|
4 | 6 | import { clearAllMocks } from "../../../test-utils/reset" |
5 | 7 |
|
@@ -280,6 +282,59 @@ describe("CodeIndexOrchestrator - error path cleanup gating", () => { |
280 | 282 | }, |
281 | 283 | ) |
282 | 284 |
|
| 285 | + it.each([false, true])( |
| 286 | + "keeps private error details out of telemetry (cleanup failure: %s)", |
| 287 | + async (cleanupFails) => { |
| 288 | + const messages = [ |
| 289 | + "Embedding failed (Workspace: /Users/private-user/Secret Project, File: /Users/private-user/Secret Project/src/private.ts)", |
| 290 | + "Embedding failed (Workspace: C:\\Users\\private-user\\Secret Project, File: C:\\Users\\private-user\\Secret Project\\private.ts)", |
| 291 | + ] |
| 292 | + const failures = messages.map((message) => { |
| 293 | + const error = new Error(message) |
| 294 | + error.stack = `${message}\n at privateFunction (/Users/private-user/Secret Project/private.ts:12:3)` |
| 295 | + return error |
| 296 | + }) |
| 297 | + vectorStore.initialize.mockResolvedValue(cleanupFails) |
| 298 | + vectorStore.hasIndexedData.mockResolvedValue(!cleanupFails) |
| 299 | + vectorStore.markIndexingIncomplete.mockResolvedValue(undefined) |
| 300 | + scanner.scanDirectory.mockImplementation(async (_dir: string, onError: (error: Error) => void) => { |
| 301 | + for (const failure of failures) onError(failure) |
| 302 | + return { stats: { processed: 0, skipped: 0 }, totalBlockCount: 0 } |
| 303 | + }) |
| 304 | + if (cleanupFails) vectorStore.clearCollection.mockRejectedValue(failures[1]) |
| 305 | + const orchestrator = new CodeIndexOrchestrator( |
| 306 | + configManager, |
| 307 | + stateManager, |
| 308 | + workspacePath, |
| 309 | + cacheManager, |
| 310 | + vectorStore, |
| 311 | + scanner, |
| 312 | + fileWatcher, |
| 313 | + ) |
| 314 | + |
| 315 | + await orchestrator.startIndexing() |
| 316 | + |
| 317 | + const expectedEvents = [ |
| 318 | + [TelemetryEventName.CODE_INDEX_ERROR, { error: "Indexing failed", location: "startIndexing" }], |
| 319 | + ] |
| 320 | + if (cleanupFails) { |
| 321 | + expectedEvents.push([ |
| 322 | + TelemetryEventName.CODE_INDEX_ERROR, |
| 323 | + { error: "Index cleanup failed", location: "startIndexing.cleanup" }, |
| 324 | + ]) |
| 325 | + } |
| 326 | + // Exact payload assertions also exclude stacks, nested causes and aggregate error objects. |
| 327 | + expect(vi.mocked(TelemetryService.instance.captureEvent).mock.calls).toEqual(expectedEvents) |
| 328 | + expect(stateManager.setSystemState).toHaveBeenLastCalledWith("Error", expect.stringContaining(messages[0])) |
| 329 | + if (!cleanupFails) { |
| 330 | + expect(stateManager.setSystemState).toHaveBeenLastCalledWith( |
| 331 | + "Error", |
| 332 | + expect.stringContaining(messages[1]), |
| 333 | + ) |
| 334 | + } |
| 335 | + }, |
| 336 | + ) |
| 337 | + |
283 | 338 | it("preserves an existing index after an incremental failure and a failed full-scan retry", async () => { |
284 | 339 | let complete = true |
285 | 340 | vectorStore.initialize.mockResolvedValue(false) |
|
0 commit comments