@@ -194,6 +194,22 @@ describe("google web search provider", () => {
194194 expect ( postCalls ) . toHaveLength ( 2 ) ;
195195 } ) ;
196196
197+ it ( "reuses cached Gemini answers across ignored result counts while rejecting invalid counts" , async ( ) => {
198+ const mockFetch = installGeminiFetch ( ) ;
199+ const tool = createGeminiToolWithHeaders ( { } ) ;
200+ const query = "unique Gemini ignored result count cache regression" ;
201+
202+ await tool ?. execute ( { query, count : 1 } ) ;
203+ await tool ?. execute ( { query, count : 10 } ) ;
204+ await tool ?. execute ( { query } ) ;
205+
206+ await expect ( tool ?. execute ( { query, count : 0 } ) ) . rejects . toThrow (
207+ "count must be an integer from 1 to 10." ,
208+ ) ;
209+ const postCalls = mockFetch . mock . calls . filter ( ( [ , init ] ) => typeof init ?. body === "string" ) ;
210+ expect ( postCalls ) . toHaveLength ( 1 ) ;
211+ } ) ;
212+
197213 it ( "does not partition cached results by overwritten provider-owned headers" , async ( ) => {
198214 const mockFetch = installGeminiFetch ( ) ;
199215
@@ -720,6 +736,51 @@ describe("google web search provider", () => {
720736 expect ( thirdBody . contents ?. [ 0 ] ?. parts ?. [ 0 ] ?. text ) . toBe ( "same query cache partition" ) ;
721737 } ) ;
722738
739+ it . each ( [
740+ {
741+ label : "relative freshness" ,
742+ filter : { freshness : "week" } ,
743+ equivalentFilter : { freshness : "pw" } ,
744+ distinctFilter : { freshness : "month" } ,
745+ initialTimeRange : {
746+ startTime : "2026-04-08T12:00:00Z" ,
747+ endTime : "2026-04-15T12:00:00Z" ,
748+ } ,
749+ } ,
750+ {
751+ label : "open-ended date ranges" ,
752+ filter : { date_after : "2026-04-01" } ,
753+ equivalentFilter : { date_after : "2026-04-01" } ,
754+ distinctFilter : { date_after : "2026-04-02" } ,
755+ initialTimeRange : {
756+ startTime : "2026-04-01T00:00:00Z" ,
757+ endTime : "2026-04-15T12:00:00Z" ,
758+ } ,
759+ } ,
760+ ] ) (
761+ "reuses Gemini $label cache entries as the clock advances without merging distinct filters" ,
762+ async ( { label, filter, equivalentFilter, distinctFilter, initialTimeRange } ) => {
763+ vi . useFakeTimers ( { toFake : [ "Date" ] } ) ;
764+ vi . setSystemTime ( new Date ( "2026-04-15T12:00:00.123Z" ) ) ;
765+ const mockFetch = installGeminiFetch ( ) ;
766+ const tool = createGeminiToolWithHeaders ( { } ) ;
767+ const query = `unique Gemini ${ label } moving-clock cache regression` ;
768+
769+ await tool ?. execute ( { query, ...filter } ) ;
770+ vi . setSystemTime ( new Date ( "2026-04-15T12:00:02.123Z" ) ) ;
771+ const cached = await tool ?. execute ( { query, ...equivalentFilter } ) ;
772+
773+ expect ( cached ) . toMatchObject ( { cached : true } ) ;
774+ expect ( parseGeminiFetchBody ( mockFetch ) . tools ?. [ 0 ] ?. google_search ?. timeRangeFilter ) . toEqual (
775+ initialTimeRange ,
776+ ) ;
777+
778+ await tool ?. execute ( { query, ...distinctFilter } ) ;
779+ const postCalls = mockFetch . mock . calls . filter ( ( [ , init ] ) => typeof init ?. body === "string" ) ;
780+ expect ( postCalls ) . toHaveLength ( 2 ) ;
781+ } ,
782+ ) ;
783+
723784 it ( "strips sub-second precision from date-range timestamps so Gemini accepts them" , async ( ) => {
724785 vi . useFakeTimers ( { toFake : [ "Date" ] } ) ;
725786 // "now" with non-zero milliseconds. Without stripping, toISOString() emits
0 commit comments