|
1 | | -// npx vitest run src/api/providers/__tests__/virtual-quota-fallback-provider.spec.spec.ts |
| 1 | +// npx vitest run src/api/providers/__tests__/virtual-quota-fallback-provider.spec.ts |
2 | 2 |
|
3 | 3 | // Mock vscode first to avoid import errors |
4 | 4 | vitest.mock("vscode", () => ({ |
@@ -298,14 +298,12 @@ describe("VirtualQuotaFallbackProvider", () => { |
298 | 298 |
|
299 | 299 | describe("adjustActiveHandler", () => { |
300 | 300 | beforeEach(() => { |
301 | | - // kilocode_change start |
302 | 301 | ;(mockSettingsManager.getProfile as any).mockImplementation(async ({ id }: { id: string }) => { |
303 | 302 | if (id === "p1") return { id: "p1", name: "primary-profile" } |
304 | 303 | if (id === "p2") return { id: "p2", name: "secondary-profile" } |
305 | 304 | if (id === "p3") return { id: "p3", name: "backup-profile" } |
306 | 305 | return undefined |
307 | 306 | }) |
308 | | - // kilocode_change end |
309 | 307 | }) |
310 | 308 | it("should set first handler as active if it is under limit", async () => { |
311 | 309 | const handler = new VirtualQuotaFallbackHandler({ |
@@ -505,7 +503,15 @@ describe("VirtualQuotaFallbackProvider", () => { |
505 | 503 | it("should delegate to the active handler", () => { |
506 | 504 | const handler = new VirtualQuotaFallbackHandler({} as any) |
507 | 505 | const getModelMock = vitest.fn().mockReturnValue({ id: "test-model" }) |
| 506 | + |
| 507 | + // Set up handler configs to ensure the active handler isn't overridden by our default logic |
| 508 | + ;(handler as any).handlerConfigs = [ |
| 509 | + { handler: { getModel: getModelMock }, profileId: "p1", config: { profileId: "p1" } }, |
| 510 | + ] |
| 511 | + |
| 512 | + // Set the active handler |
508 | 513 | ;(handler as any).activeHandler = { getModel: getModelMock } |
| 514 | + ;(handler as any).activeProfileId = "p1" |
509 | 515 |
|
510 | 516 | const result = handler.getModel() |
511 | 517 |
|
@@ -565,17 +571,22 @@ describe("VirtualQuotaFallbackProvider", () => { |
565 | 571 | profiles: manyProfiles, |
566 | 572 | } as any) |
567 | 573 |
|
568 | | - // The constructor already calls initialize through initializationPromise |
569 | | - // We don't need to call it again, but we need to wait for it to complete |
570 | | - await (handler as any).initializationPromise |
| 574 | + // Explicitly call initialize since constructor no longer does this automatically |
| 575 | + await handler.initialize() |
571 | 576 |
|
572 | 577 | // Verify that all profiles were processed |
573 | | - // In the current implementation, buildApiHandler is called for each profile |
574 | | - expect(buildApiHandler).toHaveBeenCalledTimes(1) |
| 578 | + // buildApiHandler should be called for each profile |
| 579 | + expect(buildApiHandler).toHaveBeenCalledTimes(manyProfiles.length) |
575 | 580 |
|
576 | 581 | // Verify that handler configs were created for all profiles |
577 | 582 | const handlerConfigs = (handler as any).handlerConfigs |
578 | | - expect(handlerConfigs).toHaveLength(0) |
| 583 | + expect(handlerConfigs).toHaveLength(manyProfiles.length) |
| 584 | + |
| 585 | + // Verify each handler config has the correct profileId |
| 586 | + handlerConfigs.forEach((config: any, index: number) => { |
| 587 | + expect(config.profileId).toBe(manyProfiles[index].profileId) |
| 588 | + expect(config.handler.getModel().id).toBe(`${manyProfiles[index].profileId}-model`) |
| 589 | + }) |
579 | 590 | }) |
580 | 591 | it("should maintain active handler if it's still valid", async () => { |
581 | 592 | const handler = new VirtualQuotaFallbackHandler({ |
|
0 commit comments