@@ -157,6 +157,29 @@ describe("GeminiHandler", () => {
157157 const result = await handler . completePrompt ( "Test prompt" )
158158 expect ( result ) . toBe ( "" )
159159 } )
160+
161+ it ( "should handle grounding metadata in completePrompt response" , async ( ) => {
162+ // Mock response with grounding metadata
163+ ; ( handler [ "client" ] . models . generateContent as any ) . mockResolvedValue ( {
164+ text : "Main response" ,
165+ candidates : [
166+ {
167+ groundingMetadata : {
168+ groundingChunks : [ { web : { uri : "https://example.com" } } ] ,
169+ } ,
170+ } ,
171+ ] ,
172+ } )
173+
174+ const result = await handler . completePrompt ( "Test prompt" )
175+ expect ( result ) . toContain ( "Main response" )
176+ } )
177+
178+ it ( "should handle non-Error thrown in completePrompt" , async ( ) => {
179+ ; ( handler [ "client" ] . models . generateContent as any ) . mockRejectedValue ( "string error" )
180+
181+ await expect ( handler . completePrompt ( "Test prompt" ) ) . rejects . toBe ( "string error" )
182+ } )
160183 } )
161184
162185 describe ( "getModel" , ( ) => {
@@ -223,6 +246,17 @@ describe("GeminiHandler", () => {
223246 } )
224247
225248 describe ( "calculateCost" , ( ) => {
249+ it ( "should set cacheReadsPrice to 0 when it is undefined" , ( ) => {
250+ const infoWithoutCachePrice : ModelInfo = {
251+ ...mockInfo ,
252+ cacheReadsPrice : undefined ,
253+ }
254+ const cost = handler . calculateCost ( { info : infoWithoutCachePrice , inputTokens : 1000 , outputTokens : 1000 } )
255+ // Should still compute cost without cache reads
256+ expect ( cost ) . toBeDefined ( )
257+ expect ( cost ) . toBeGreaterThan ( 0 )
258+ } )
259+
226260 // Mock ModelInfo based on gemini-1.5-flash-latest pricing (per 1M tokens)
227261 // Removed 'id' and 'name' as they are not part of ModelInfo type directly
228262 const mockInfo : ModelInfo = {
@@ -367,4 +401,14 @@ describe("GeminiHandler", () => {
367401 expect ( mockCaptureException ) . toHaveBeenCalled ( )
368402 } )
369403 } )
404+
405+ describe ( "getThoughtSignature and getResponseId" , ( ) => {
406+ it ( "should return undefined for getThoughtSignature before any request" , ( ) => {
407+ expect ( handler . getThoughtSignature ( ) ) . toBeUndefined ( )
408+ } )
409+
410+ it ( "should return undefined for getResponseId before any request" , ( ) => {
411+ expect ( handler . getResponseId ( ) ) . toBeUndefined ( )
412+ } )
413+ } )
370414} )
0 commit comments