Open History to see the last commit
1import { afterEach, describe, expect, it } from 'vitest'
2
3import { provider } from './google-vertex.ts'
4
5function pricingUrl(value: unknown): string {
6 if (typeof value !== 'object' || value === null || !('source' in value)) {
7 throw new Error('missing pricing')
8 }
9 const source = value.source
10 if (typeof source !== 'object' || source === null || !('url' in source)) {
11 throw new Error('missing pricing source')
12 }
13 if (typeof source.url !== 'string') throw new Error('missing pricing url')
14 return source.url
15}
16
17const originalFetch = globalThis.fetch
18
19afterEach(() => {
20 globalThis.fetch = originalFetch
21})
22
23const LOCATIONS = `
24<h2 id="google-models">Google model endpoint locations</h2>
25<a href="/gemini-enterprise-agent-platform/models/gemini/3-1-pro">Gemini 3.1 Pro</a>
26<code>(gemini-3.1-pro-preview)</code>
27<h2 id="genai-partner-models">Partners</h2>
28`
29
30const CARD = `
31<h1>Gemini 3.1 Pro</h1>
32<p>Model ID</p><p>gemini-3.1-pro-preview</p>
33<p>Modalities</p><p>Text</p><p>Input and output</p>
34<p>Token limits</p>
35<p>Context window</p><p>1,048,576</p>
36<p>Maximum output tokens</p><p>65,536</p>
37<p>Capabilities</p><p>Thinking</p><p>Supported</p>
38<p>Tools</p><p>Function calling</p><p>Supported</p>
39<p>Consumption options</p>
40<p>Versions</p>
41<p>gemini-3.1-pro-preview</p>
42<p>Release date: February 19, 2026</p>
43<p>Send feedback</p>
44`
45
46const THINKING = `
47<table>
48<tr><th>Model</th><th>Supported thinking_level values</th><th>Default</th></tr>
49<tr><td>Gemini 3.1 Pro</td><td>LOW , MEDIUM , HIGH</td><td>HIGH</td></tr>
50</table>
51<p>You can't turn off thinking for Gemini 2.5 Pro.</p>
52`
53
54const PRICING = `
55<table>
56<tr>
57<th>Model</th><th>Type</th><th>Region</th>
58<th>Price (/1M tokens) <= 200K input tokens</th>
59<th>Price (/1M tokens) > 200K input tokens</th>
60<th>Price (/1M tokens) <= 200K cached input tokens</th>
61<th>Price (/1M tokens) > 200K cached input tokens</th>
62</tr>
63<tr>
64<td>Gemini 3.1 Pro</td>
65<td>Input (text, image, video, audio)</td>
66<td>Global</td><td>$2.00</td><td>$4.00</td><td>$0.20</td><td>$0.40</td>
67</tr>
68<tr>
69<td></td>
70<td>Text output (response and reasoning)</td>
71<td>Global</td><td>$12.00</td><td>$18.00</td><td>N/A</td><td>N/A</td>
72</tr>
73</table>
74`
75
76const DISCOVERY = {
77 title: 'Agent Platform API',
78 version: 'v1',
79 rootUrl: 'https://aiplatform.googleapis.com/',
80 schemas: {
81 Request: { type: 'object', properties: { body: { $ref: 'Body' } } },
82 Body: { type: 'object' },
83 },
84 resources: {
85 publishers: {
86 resources: {
87 models: {
88 methods: {
89 generateContent: {
90 id: 'aiplatform.projects.locations.publishers.models.generateContent',
91 flatPath:
92 'v1/projects/{p}/locations/{l}/publishers/{pub}/models/{m}:generateContent',
93 httpMethod: 'POST',
94 request: { $ref: 'Request' },
95 response: { $ref: 'Body' },
96 },
97 },
98 },
99 },
100 },
101 },
102}
103
104describe('google-vertex', () => {
105 it('lists and specifies from Google docs, not an aggregator', async () => {
106 const urls: Array<string> = []
107 globalThis.fetch = ((url: string) => {
108 const href = String(url)
109 urls.push(href)
110 const body = href.includes('$discovery')
111 ? JSON.stringify(DISCOVERY)
112 : href.endsWith('/locations')
113 ? LOCATIONS
114 : href.endsWith('/thinking')
115 ? THINKING
116 : href.endsWith('/pricing')
117 ? PRICING
118 : CARD
119 return Promise.resolve(new Response(body, { status: 200 }))
120 }) as typeof fetch
121
122 const listed = await provider.listModels({})
123 const spec = await provider.fetchSpec({})
124 const model = listed.models.find(
125 (item) => item.rawId === 'gemini-3.1-pro-preview',
126 )
127
128 expect(listed.skipped).toBeUndefined()
129 expect(model?.displayName).toBe('Gemini 3.1 Pro')
130 expect(model?.contextWindow).toBe(1_048_576)
131 expect(model?.reasoning).toEqual({
132 mode: 'effort',
133 mandatory: true,
134 efforts: ['LOW', 'MEDIUM', 'HIGH'],
135 })
136 expect(pricingUrl(model?.pricing)).toContain('generative-ai/pricing')
137 expect(spec.specs[0]?.paths).toHaveProperty(
138 '/v1/projects/{p}/locations/{l}/publishers/{pub}/models/{m}:generateContent',
139 )
140 expect(provider.displayName).toBe('Gemini Enterprise Agent Platform')
141 expect(provider.id).toBe('google-vertex')
142 expect(urls.some((url) => /models\.dev|openrouter/i.test(url))).toBe(false)
143 expect(
144 provider.classify(
145 '/v1/projects/{p}/locations/{l}/publishers/google/models/{m}:embedContent',
146 {},
147 ),
148 ).toBe('embeddings')
149 })
150})