Skip to content

Commit 7de2f02

Browse files
committed
fix: add TelemetryService mock to existing error handling tests
- Fix bedrock-error-handling.spec.ts (21 failing tests) - Fix mistral.spec.ts (2 failing tests) - Fix xai.spec.ts (1 failing test) - Use vi.hoisted() to ensure mock is initialized before vi.mock()
1 parent 1b5eb9b commit 7de2f02

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

src/api/providers/__tests__/bedrock-error-handling.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// Mock TelemetryService - must come before other imports
2+
const mockCaptureException = vi.hoisted(() => vi.fn())
3+
vi.mock("@roo-code/telemetry", () => ({
4+
TelemetryService: {
5+
instance: {
6+
captureException: mockCaptureException,
7+
},
8+
},
9+
}))
10+
111
// Mock BedrockRuntimeClient and commands
212
const mockSend = vi.fn()
313

@@ -27,6 +37,7 @@ describe("AwsBedrockHandler Error Handling", () => {
2737

2838
beforeEach(() => {
2939
vi.clearAllMocks()
40+
mockCaptureException.mockClear()
3041
handler = new AwsBedrockHandler({
3142
apiModelId: "anthropic.claude-3-5-sonnet-20241022-v2:0",
3243
awsAccessKey: "test-access-key",

src/api/providers/__tests__/mistral.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// Mock TelemetryService - must come before other imports
2+
const mockCaptureException = vi.hoisted(() => vi.fn())
3+
vi.mock("@roo-code/telemetry", () => ({
4+
TelemetryService: {
5+
instance: {
6+
captureException: mockCaptureException,
7+
},
8+
},
9+
}))
10+
111
// Mock Mistral client - must come before other imports
212
const mockCreate = vi.fn()
313
const mockComplete = vi.fn()
@@ -59,6 +69,7 @@ describe("MistralHandler", () => {
5969
handler = new MistralHandler(mockOptions)
6070
mockCreate.mockClear()
6171
mockComplete.mockClear()
72+
mockCaptureException.mockClear()
6273
})
6374

6475
describe("constructor", () => {

src/api/providers/__tests__/xai.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
// npx vitest api/providers/__tests__/xai.spec.ts
22

3+
// Mock TelemetryService - must come before other imports
4+
const mockCaptureException = vitest.hoisted(() => vitest.fn())
5+
vitest.mock("@roo-code/telemetry", () => ({
6+
TelemetryService: {
7+
instance: {
8+
captureException: mockCaptureException,
9+
},
10+
},
11+
}))
12+
313
const mockCreate = vitest.fn()
414

515
vitest.mock("openai", () => {
@@ -25,6 +35,7 @@ describe("XAIHandler", () => {
2535
// Reset all mocks
2636
vi.clearAllMocks()
2737
mockCreate.mockClear()
38+
mockCaptureException.mockClear()
2839

2940
// Create handler with mock
3041
handler = new XAIHandler({})

0 commit comments

Comments
 (0)