@@ -47,6 +47,8 @@ vi.mock("../requesty")
4747vi . mock ( "../kenari" )
4848vi . mock ( "../nanogpt" )
4949vi . mock ( "../moonshot" )
50+ vi . mock ( "../gemini" )
51+ vi . mock ( "../vertex" )
5052vi . mock ( "../zoo-gateway" )
5153
5254// Mock ContextProxy with a simple static instance
@@ -75,6 +77,8 @@ import { getRequestyModels } from "../requesty"
7577import { getKenariModels } from "../kenari"
7678import { getNanoGptModels } from "../nanogpt"
7779import { getMoonshotModels } from "../moonshot"
80+ import { getGeminiModels } from "../gemini"
81+ import { getVertexModels } from "../vertex"
7882import { getZooGatewayModels } from "../zoo-gateway"
7983
8084const mockGetLiteLLMModels = getLiteLLMModels as Mock < typeof getLiteLLMModels >
@@ -83,6 +87,8 @@ const mockGetRequestyModels = getRequestyModels as Mock<typeof getRequestyModels
8387const mockGetKenariModels = getKenariModels as Mock < typeof getKenariModels >
8488const mockGetNanoGptModels = getNanoGptModels as Mock < typeof getNanoGptModels >
8589const mockGetMoonshotModels = getMoonshotModels as Mock < typeof getMoonshotModels >
90+ const mockGetGeminiModels = getGeminiModels as Mock < typeof getGeminiModels >
91+ const mockGetVertexModels = getVertexModels as Mock < typeof getVertexModels >
8692const mockGetZooGatewayModels = getZooGatewayModels as Mock < typeof getZooGatewayModels >
8793
8894const DUMMY_REQUESTY_KEY = "requesty-key-for-testing"
@@ -263,6 +269,72 @@ describe("getModels with new GetModelsOptions", () => {
263269 expect ( result ) . toEqual ( mockModels )
264270 } )
265271
272+ it ( "calls getGeminiModels with the API key, base URL, and the flight signal" , async ( ) => {
273+ const mockModels = {
274+ "gemini-2.5-flash" : {
275+ maxTokens : 64_000 ,
276+ contextWindow : 1_048_576 ,
277+ supportsImages : true ,
278+ supportsPromptCache : true ,
279+ description : "Gemini 2.5 Flash" ,
280+ } ,
281+ }
282+ mockGetGeminiModels . mockResolvedValue ( mockModels )
283+
284+ const result = await getModels ( {
285+ provider : providerIdentifiers . gemini ,
286+ apiKey : "gemini-key" ,
287+ baseUrl : "https://gemini-proxy.example" ,
288+ } )
289+
290+ expect ( mockGetGeminiModels ) . toHaveBeenCalledWith ( "gemini-key" , "https://gemini-proxy.example" , {
291+ signal : expect . any ( AbortSignal ) ,
292+ } )
293+ expect ( result ) . toEqual ( mockModels )
294+ } )
295+
296+ it ( "calls getGeminiModels without a base URL while preserving the signal arity" , async ( ) => {
297+ mockGetGeminiModels . mockResolvedValue ( {
298+ "gemini-2.5-flash" : {
299+ maxTokens : 64_000 ,
300+ contextWindow : 1_048_576 ,
301+ supportsImages : true ,
302+ supportsPromptCache : true ,
303+ } ,
304+ } )
305+
306+ await getModels ( { provider : providerIdentifiers . gemini , apiKey : "gemini-key" } )
307+
308+ expect ( mockGetGeminiModels ) . toHaveBeenCalledWith ( "gemini-key" , undefined , {
309+ signal : expect . any ( AbortSignal ) ,
310+ } )
311+ } )
312+
313+ it ( "calls getVertexModels with project, region, credentials, and the flight signal" , async ( ) => {
314+ const mockModels = {
315+ "gemini-3.7-flash" : {
316+ maxTokens : 65_536 ,
317+ contextWindow : 1_048_576 ,
318+ supportsImages : true ,
319+ supportsPromptCache : true ,
320+ description : "Vertex Gemini 3.7 Flash" ,
321+ } ,
322+ }
323+ mockGetVertexModels . mockResolvedValue ( mockModels )
324+
325+ const result = await getModels ( {
326+ provider : providerIdentifiers . vertex ,
327+ projectId : "gcp-project" ,
328+ region : "us-central1" ,
329+ keyFile : "/keys/sa.json" ,
330+ } )
331+
332+ expect ( mockGetVertexModels ) . toHaveBeenCalledWith ( "gcp-project" , "us-central1" , "/keys/sa.json" , undefined , {
333+ signal : expect . any ( AbortSignal ) ,
334+ } )
335+ expect ( result ) . toEqual ( mockModels )
336+ } )
337+
266338 it ( "validates exhaustive provider checking with unknown provider" , async ( ) => {
267339 // This test ensures TypeScript catches unknown providers at compile time
268340 // In practice, the discriminated union should prevent this at compile time
@@ -1136,6 +1208,103 @@ describe("NanoGPT key-scoped cache isolation", () => {
11361208 } )
11371209} )
11381210
1211+ describe ( "Gemini url+key-scoped cache isolation" , ( ) => {
1212+ // Gemini belongs to BOTH URL_SCOPED_PROVIDERS and KEY_SCOPED_PROVIDERS (modelCache.ts):
1213+ // its catalog can differ per API key and a custom base URL (googleGeminiBaseUrl) can
1214+ // point at an entirely different server, so neither dimension may collapse into a
1215+ // shared cache identity. Mirrors the MiMo/NanoGPT isolation tests above.
1216+ const geminiCatalog = {
1217+ "gemini-2.5-flash" : {
1218+ maxTokens : 64_000 ,
1219+ contextWindow : 1_048_576 ,
1220+ supportsImages : true ,
1221+ supportsPromptCache : true ,
1222+ } ,
1223+ }
1224+
1225+ beforeEach ( ( ) => {
1226+ vi . clearAllMocks ( )
1227+ mockGetGeminiModels . mockResolvedValue ( geminiCatalog )
1228+ } )
1229+
1230+ it ( "separates cache identities by base URL and API key without exposing raw keys" , async ( ) => {
1231+ const mockCache = vi . mocked ( new ( vi . mocked ( NodeCache ) ) ( ) )
1232+ mockCache . get . mockReturnValue ( undefined )
1233+
1234+ await getModels ( { provider : providerIdentifiers . gemini } )
1235+ await getModels ( { provider : providerIdentifiers . gemini , baseUrl : "https://gemini-proxy.example" } )
1236+ await getModels ( {
1237+ provider : providerIdentifiers . gemini ,
1238+ baseUrl : "https://gemini-proxy.example" ,
1239+ apiKey : "gemini-key-a" ,
1240+ } )
1241+ await getModels ( {
1242+ provider : providerIdentifiers . gemini ,
1243+ baseUrl : "https://gemini-proxy.example" ,
1244+ apiKey : "gemini-key-b" ,
1245+ } )
1246+
1247+ const cacheKeys = mockCache . set . mock . calls . map ( ( [ key ] ) => key as string )
1248+ expect ( new Set ( cacheKeys ) . size ) . toBe ( 4 )
1249+ // Bare provider fallback when neither URL nor key is set; url-only component when
1250+ // the key is absent (catalog varies per key on the same server).
1251+ expect ( cacheKeys ) . toContain ( "gemini" )
1252+ expect ( cacheKeys ) . toContain ( "gemini:https://gemini-proxy.example" )
1253+ // url+key compound identity for each distinct key on the proxy server.
1254+ expect ( cacheKeys . filter ( ( key ) => key . startsWith ( "gemini:https://gemini-proxy.example:" ) ) ) . toHaveLength ( 2 )
1255+ // Raw secrets must never appear in the on-disk-bound cache keys.
1256+ expect ( cacheKeys . every ( ( key ) => ! key . includes ( "gemini-key-a" ) && ! key . includes ( "gemini-key-b" ) ) ) . toBe ( true )
1257+ } )
1258+
1259+ it ( "keys the catalog per base URL so two servers never share an entry" , async ( ) => {
1260+ const mockCache = vi . mocked ( new ( vi . mocked ( NodeCache ) ) ( ) )
1261+ mockCache . get . mockReturnValue ( undefined )
1262+
1263+ await getModels ( { provider : providerIdentifiers . gemini , apiKey : "shared-key" , baseUrl : "https://a.example" } )
1264+ await getModels ( { provider : providerIdentifiers . gemini , apiKey : "shared-key" , baseUrl : "https://b.example" } )
1265+
1266+ const cacheKeys = mockCache . set . mock . calls . map ( ( [ key ] ) => key as string )
1267+ expect ( new Set ( cacheKeys ) . size ) . toBe ( 2 )
1268+ expect ( cacheKeys . every ( ( key ) => key . startsWith ( "gemini:https://" ) ) ) . toBe ( true )
1269+ } )
1270+ } )
1271+
1272+ describe ( "Vertex provider-scoped cache identity" , ( ) => {
1273+ // Vertex is in NEITHER URL_SCOPED_PROVIDERS nor KEY_SCOPED_PROVIDERS (modelCache.ts):
1274+ // its options carry no apiKey/baseUrl discriminator and the gemini-* catalog is global
1275+ // to the project/region, so getCacheKey() falls back to the bare provider name and the
1276+ // 5-minute TTL bounds staleness.
1277+ const vertexCatalog = {
1278+ "gemini-3.7-flash" : {
1279+ maxTokens : 65_536 ,
1280+ contextWindow : 1_048_576 ,
1281+ supportsImages : true ,
1282+ supportsPromptCache : true ,
1283+ } ,
1284+ }
1285+
1286+ beforeEach ( ( ) => {
1287+ vi . clearAllMocks ( )
1288+ mockGetVertexModels . mockResolvedValue ( vertexCatalog )
1289+ } )
1290+
1291+ it ( "falls back to the bare provider name regardless of project, region, or credentials" , async ( ) => {
1292+ const mockCache = vi . mocked ( new ( vi . mocked ( NodeCache ) ) ( ) )
1293+ mockCache . get . mockReturnValue ( undefined )
1294+
1295+ await getModels ( { provider : providerIdentifiers . vertex , projectId : "project-a" , region : "us-central1" } )
1296+ await getModels ( {
1297+ provider : providerIdentifiers . vertex ,
1298+ projectId : "project-b" ,
1299+ region : "europe-west1" ,
1300+ keyFile : "/keys/sa.json" ,
1301+ } )
1302+
1303+ const cacheKeys = mockCache . set . mock . calls . map ( ( [ key ] ) => key as string )
1304+ expect ( cacheKeys ) . toEqual ( [ "vertex" , "vertex" ] )
1305+ } )
1306+ } )
1307+
11391308describe ( "compound cache key derivation across scoping dimensions" , ( ) => {
11401309 // Exercises every branch of getCacheKey via the public getModels() entry point.
11411310 // litellm is url-scoped AND key-scoped; openrouter is neither, so it hits the bare
0 commit comments