From 894895685a38254fb91a737c4dd2199d7b5a732c Mon Sep 17 00:00:00 2001 From: Roo Code Date: Sat, 23 Aug 2025 23:30:32 +0000 Subject: [PATCH] test: add tests for Gemini free tier model ID stripping - Added test cases to verify -free suffix is properly stripped from model IDs - Ensures free tier models (gemini-2.5-pro-free, gemini-2.5-flash-free, gemini-2.5-flash-lite-free) map to correct API model IDs - Validates that model info still reflects free tier pricing (0 cost) and context limits --- src/api/providers/__tests__/gemini.spec.ts | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/api/providers/__tests__/gemini.spec.ts b/src/api/providers/__tests__/gemini.spec.ts index 812c1ae1a6..32db86d721 100644 --- a/src/api/providers/__tests__/gemini.spec.ts +++ b/src/api/providers/__tests__/gemini.spec.ts @@ -164,6 +164,44 @@ describe("GeminiHandler", () => { }) }) + describe("getModel with free tier models", () => { + it("should strip -free suffix from model ID for API calls", () => { + const freeHandler = new GeminiHandler({ + apiModelId: "gemini-2.5-pro-free", + geminiApiKey: "test-key", + }) + const modelInfo = freeHandler.getModel() + // The returned ID should have -free stripped for API calls + expect(modelInfo.id).toBe("gemini-2.5-pro") + // But the info should still be from the free model + expect(modelInfo.info.inputPrice).toBe(0) + expect(modelInfo.info.outputPrice).toBe(0) + expect(modelInfo.info.contextWindow).toBe(250_000) + }) + + it("should strip -free suffix from flash model", () => { + const freeHandler = new GeminiHandler({ + apiModelId: "gemini-2.5-flash-free", + geminiApiKey: "test-key", + }) + const modelInfo = freeHandler.getModel() + expect(modelInfo.id).toBe("gemini-2.5-flash") + expect(modelInfo.info.inputPrice).toBe(0) + expect(modelInfo.info.outputPrice).toBe(0) + }) + + it("should strip -free suffix from flash-lite model", () => { + const freeHandler = new GeminiHandler({ + apiModelId: "gemini-2.5-flash-lite-free", + geminiApiKey: "test-key", + }) + const modelInfo = freeHandler.getModel() + expect(modelInfo.id).toBe("gemini-2.5-flash-lite") + expect(modelInfo.info.inputPrice).toBe(0) + expect(modelInfo.info.outputPrice).toBe(0) + }) + }) + describe("calculateCost", () => { // Mock ModelInfo based on gemini-1.5-flash-latest pricing (per 1M tokens) // Removed 'id' and 'name' as they are not part of ModelInfo type directly