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