Skip to content
Source
Sign inSign up
TanStack/schemas
Open History to see the last commit

gemini-bindings.test.ts

331 lines10.5 KB

1import { describe, expect, it } from 'vitest'
2​
3import {
4 attachGeminiPublishedFacts,
5 parseAutomaticRoutes,
6 parseChangelogAliases,
7 parseGeminiReleaseDates,
8 htmlTables,
9 parseGemmaModalities,
10} from './gemini-bindings.ts'
11import type { GeminiPublishedBindings } from './gemini-bindings.ts'
12​
13const CHANGELOG = `This page documents updates to the Gemini API.
14​
15## May 19, 2026
16​
17- Released \`gemini-3.5-flash\`, the generally available version.
18 This is now the model behind \`gemini-flash-latest\`.
19​
20## March 9, 2026
21​
22- The \`gemini-3-pro-preview\` now points to \`gemini-3.1-pro-preview\`.
23​
24## January 21, 2026
25​
26- Changed the \`latest\` aliases:
27​
28 - \`gemini-pro-latest\` switched to \`gemini-3-pro-preview\`
29 - \`gemini-flash-latest\` switched to \`gemini-3-flash-preview\`
30​
31- Released \`gemini-2.0-flash-thinking-exp-01-21\`, the latest preview version of the model behind the [Gemini 2.0 Flash Thinking Model](https://example.com).
33​
34const GEMMA = `Gemma 4 models are multimodal, handling text and image input
35and generating text output.
36​
37| Property | E2B | E4B | 12B Unified | 31B Dense |
38|---|---|---|---|---|
39| **Supported Modalities** | Text, Image, Audio | Text, Image, Audio | Text, Image, Audio | Text, Image |
40​
41| Property | 26B A4B MoE |
42|---|---|
43| **Supported Modalities** | Text, Image |
45​
46interface Listed {
47 rawId: string
48 modalities: { input: Array<string>; output: Array<string> } | null
49 aliases?: Array<string> | null
50 pricing?: unknown
51 factSources?: {
52 modalities?: {
53 derivation: 'docs-derived'
54 sourceUrl?: string
55 sourceHash?: string
56 path?: string
57 }
58 pricing?: {
59 derivation: 'docs-derived'
60 sourceUrl?: string
61 sourceHash?: string
62 path?: string
63 }
64 }
65 absent?: { modalities?: 'unavailable'; pricing?: 'cleared' }
67​
68function bindings(
69 over: Partial<GeminiPublishedBindings> = {},
70): GeminiPublishedBindings {
71 return {
72 aliases: {},
73 changelog: {
74 url: 'https://aistudio.google.com/docs/changelog.md',
75 hash: 'changelog',
76 },
77 gemma: {},
78 gemmaSource: {
79 url: 'https://ai.google.dev/gemma/docs/core/model_card_4',
80 hash: 'gemma',
81 },
82 docsFailures: { failed: 0, skipped: 0, first: [] },
83 ...over,
84 }
86​
87describe('gemini published bindings', () => {
88 it('routes only an automatic-routing sentence, one id per row', () => {
89 const routes = parseAutomaticRoutes(`
90| \`gemini-3.7-flash\` | August 13, 2026 | N/A | \`gemini-3.8-flash\` (automatically routes API requests to \`gemini-3.8-flash\`) |
91| \`gemini-3.5-flash\` | May 19, 2026 | N/A | \`gemini-3.6-flash\` (automatically routed to \`gemini-3.6-flash\`) |
92| \`gemini-omni-flash-preview\` | June 30, 2026 | October 22, 2026 | \`gemini-omni-1.1-flash\` |
93​
94Requests to \`gemini-2.0-flash\` are shut down. The recommended replacement is \`gemini-3.6-flash\`.
95`)
96 expect([...routes]).toEqual([
97 ['gemini-3.7-flash', 'gemini-3.8-flash'],
98 ['gemini-3.5-flash', 'gemini-3.6-flash'],
99 ])
100 })
101​
102 it('reads a Release date column and skips a parenthetical id', () => {
103 const dates = parseGeminiReleaseDates(`
104{% table %}
105 * Model
106 * Release date
107 * Shutdown date
108 ---
109 * \`gemini-4-argon\`
110 * October 13, 2026
111 * No shutdown date announced
112 ---
113 * \`gemini-3.8-flash\` (\`gemini-3.7-flash\` is routed)
114 * September 2, 2026
115 * No shutdown date announced
116 ---
117 * \`gemini-3.5-transcribe\`
118 * August 2026
119 * No shutdown date announced
120 ---
121 * \`embedding-gecko-001\`
122 *
123 * No shutdown date announced
124{% /table %}
125`)
126 expect([...dates]).toEqual([
127 ['gemini-4-argon', '2026-10-13'],
128 ['gemini-3.8-flash', '2026-09-02'],
129 ['gemini-3.5-transcribe', '2026-08-01'],
130 ])
131 })
132​
133 it('keeps the newest changelog alias and ignores a later hop', () => {
134 const aliases = parseChangelogAliases(CHANGELOG)
135 expect(aliases.get('gemini-flash-latest')).toBe('gemini-3.5-flash')
136 expect(aliases.get('gemini-pro-latest')).toBe('gemini-3-pro-preview')
137 expect(aliases.has('gemini-flash-lite-latest')).toBe(false)
138 expect(aliases.has('gemini-3-pro-preview')).toBe(false)
139 expect(aliases.has('gemini-2.0-flash-thinking-exp-01-21')).toBe(false)
140 })
141​
142 it('refuses a changelog that is not the Gemini API changelog', () => {
143 expect(() => parseChangelogAliases('# Models\n')).toThrow(
144 /not the Gemini API changelog/,
145 )
146 })
147​
148 it('reads Gemma size columns and does not treat E2B as 2B', () => {
149 const modalities = parseGemmaModalities(GEMMA)
150 expect(modalities.get('gemma-4-31b-it')).toEqual({
151 input: ['text', 'image'],
152 output: ['text'],
153 })
154 expect(modalities.get('gemma-4-26b-a4b-it')).toEqual({
155 input: ['text', 'image'],
156 output: ['text'],
157 })
158 expect(modalities.get('gemma-4-12b-it')?.input).toEqual([
159 'text',
160 'image',
161 'audio',
162 ])
163 expect(modalities.has('gemma-4-2b-it')).toBe(false)
164 expect(modalities.has('gemma-4-4b-it')).toBe(false)
165 })
166​
167 it('reads the Gemma card served as HTML (#568)', () => {
168 const html = `<p>Gemma 4 models, generating text output.</p>
169<table><thead><tr><th style="text-align: left">Property</th><th>E2B</th><th>31B Dense</th></tr></thead>
170<tbody><tr><td><strong>Supported Modalities</strong></td><td>Text, Image, Audio</td><td>Text, Image</td></tr></tbody></table>`
171 const modalities = parseGemmaModalities(htmlTables(html))
172 expect([...modalities]).toEqual([
173 ['gemma-4-31b-it', { input: ['text', 'image'], output: ['text'] }],
174 ])
175 })
176​
177 it('returns no Gemma modalities when the card has no such row', () => {
178 expect(
179 parseGemmaModalities('Gemma 4 models, generating text output.\n').size,
180 ).toBe(0)
181 })
182​
183 it('throws when a Gemma modality cell is not a medium', () => {
184 expect(() =>
185 parseGemmaModalities(`generating text output
186| Property | 31B Dense |
187| **Supported Modalities** | Text, Hologram |
188`),
189 ).toThrow(/unknown modality/)
190 })
191​
192 it('copies alias modalities and records the alias on the dated row', () => {
193 const modalities = {
194 input: ['text', 'image', 'audio', 'video', 'file'],
195 output: ['text'],
196 }
197 const models = attachGeminiPublishedFacts<Listed>(
198 [
199 {
200 rawId: 'gemini-3.5-flash',
201 modalities,
202 factSources: {
203 modalities: {
204 derivation: 'docs-derived' as const,
205 sourceUrl:
206 'https://aistudio.google.com/docs/models/gemini-3.5-flash.md',
207 sourceHash: 'page',
208 path: 'Supported data types',
209 },
210 },
211 },
212 { rawId: 'gemini-flash-latest', modalities: null },
213 {
214 rawId: 'gemini-3-pro-preview',
215 modalities: { input: ['text'], output: ['text'] },
216 factSources: {
217 modalities: {
218 derivation: 'docs-derived' as const,
219 sourceUrl:
220 'https://aistudio.google.com/docs/models/gemini-3-pro-preview.md',
221 path: 'Supported data types',
222 },
223 },
224 },
225 { rawId: 'gemini-pro-latest', modalities: null },
226 { rawId: 'gemini-flash-lite-latest', modalities: null },
227 { rawId: 'gemma-4-31b-it', modalities: null },
228 ],
229 bindings({
230 aliases: {
231 'gemini-flash-latest': 'gemini-3.5-flash',
232 'gemini-pro-latest': 'gemini-3-pro-preview',
233 },
234 gemma: {
235 'gemma-4-31b-it': { input: ['text', 'image'], output: ['text'] },
236 },
237 }),
238 )
239 const flash = models.find((model) => model.rawId === 'gemini-flash-latest')
240 expect(flash?.modalities).toEqual(modalities)
241 expect(flash?.factSources?.modalities).toEqual({
242 derivation: 'docs-derived',
243 sourceUrl: 'https://aistudio.google.com/docs/models/gemini-3.5-flash.md',
244 sourceHash: 'page',
245 path: 'Supported data types; alias of gemini-3.5-flash',
246 })
247 expect(
248 models.find((model) => model.rawId === 'gemini-3.5-flash')?.aliases,
249 ).toEqual(['gemini-flash-latest'])
250 expect(
251 models.find((model) => model.rawId === 'gemini-pro-latest')?.modalities,
252 ).toEqual({ input: ['text'], output: ['text'] })
253 expect(
254 models.find((model) => model.rawId === 'gemini-flash-lite-latest')
255 ?.modalities,
256 ).toBeNull()
257 expect(
258 models.find((model) => model.rawId === 'gemma-4-31b-it')?.modalities,
259 ).toEqual({ input: ['text', 'image'], output: ['text'] })
260 })
261​
262 it('copies an alias price from the changelog target (#661)', () => {
263 const models = attachGeminiPublishedFacts<Listed>(
264 [
265 {
266 rawId: 'gemini-3-flash-preview',
267 modalities: null,
268 pricing: { price: 1 },
269 factSources: {
270 pricing: {
271 derivation: 'docs-derived',
272 sourceUrl: 'https://aistudio.google.com/docs/pricing.md',
273 sourceHash: 'pricing-page',
274 path: 'Input price',
275 },
276 },
277 },
278 {
279 rawId: 'gemini-flash-latest',
280 modalities: null,
281 pricing: null,
282 absent: { pricing: 'cleared' },
283 },
284 ],
285 bindings({
286 aliases: { 'gemini-flash-latest': 'gemini-3-flash-preview' },
287 }),
288 )
289 const alias = models.find((model) => model.rawId === 'gemini-flash-latest')
290 expect(alias?.pricing).toEqual({ price: 1 })
291 expect(alias?.absent).toBeUndefined()
292 expect(alias?.factSources?.pricing).toEqual({
293 derivation: 'docs-derived',
294 sourceUrl: 'https://aistudio.google.com/docs/pricing.md',
295 sourceHash: 'pricing-page',
296 path: 'Input price; alias of gemini-3-flash-preview',
297 })
298 })
299​
300 it('keeps stored modalities when the changelog or Gemma card fails', () => {
301 const models = attachGeminiPublishedFacts<Listed>(
302 [
303 { rawId: 'gemini-flash-latest', modalities: null },
304 {
305 rawId: 'gemini-3.5-flash',
306 modalities: { input: ['text'], output: ['text'] },
307 },
308 { rawId: 'gemma-4-31b-it', modalities: null },
309 {
310 rawId: 'gemma-4-26b-a4b-it',
311 modalities: { input: ['text'], output: ['text'] },
312 },
313 ],
314 bindings({ aliases: null, gemma: null }),
315 )
316 expect(
317 models.find((model) => model.rawId === 'gemini-flash-latest')?.absent
318 ?.modalities,
319 ).toBe('unavailable')
320 expect(
321 models.find((model) => model.rawId === 'gemini-3.5-flash')?.absent,
322 ).toBeUndefined()
323 expect(
324 models.find((model) => model.rawId === 'gemma-4-31b-it')?.absent
325 ?.modalities,
326 ).toBe('unavailable')
327 expect(
328 models.find((model) => model.rawId === 'gemma-4-26b-a4b-it')?.modalities,
329 ).toEqual({ input: ['text'], output: ['text'] })
330 })
331})