Open History to see the last commit
1import { readFileSync } from 'node:fs'
2
3import { describe, expect, it } from 'vitest'
4
5import {
6 attachGeminiPublishedFacts,
7 parseAutomaticRoutes,
8 parseChangelogAliases,
9 parseGeminiReleaseDates,
10 htmlTables,
11 parseGemmaCardFacts,
12 parseGemmaModalities,
13} from './gemini-bindings.ts'
14import type { GeminiPublishedBindings } from './gemini-bindings.ts'
15import type {
16 FactAbsence,
17 ModelFact,
18 ModelFactSources,
19 ModelInfo,
20} from './types.ts'
21
22const CHANGELOG = `This page documents updates to the Gemini API.
23
24## May 19, 2026
25
26- Released \`gemini-3.5-flash\`, the generally available version.
27 This is now the model behind \`gemini-flash-latest\`.
28
29## March 9, 2026
30
31- The \`gemini-3-pro-preview\` now points to \`gemini-3.1-pro-preview\`.
32
33## January 21, 2026
34
35- Changed the \`latest\` aliases:
36
37 - \`gemini-pro-latest\` switched to \`gemini-3-pro-preview\`
38 - \`gemini-flash-latest\` switched to \`gemini-3-flash-preview\`
39
40- 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).
41`
42
43const GEMMA = `Gemma 4 models are multimodal, handling text and image input
44and generating text output.
45
46| Property | E2B | E4B | 12B Unified | 31B Dense |
47|---|---|---|---|---|
48| **Supported Modalities** | Text, Image, Audio | Text, Image, Audio | Text, Image, Audio | Text, Image |
49
50| Property | 26B A4B MoE |
51|---|---|
52| **Supported Modalities** | Text, Image |
53`
54
55interface Listed {
56 rawId: string
57 modalities: { input: Array<string>; output: Array<string> } | null
58 aliases?: Array<string> | null
59 aliasOf?: string | null
60 pricing?: unknown
61 factSources?: ModelFactSources
62 absent?: Partial<Record<ModelFact, FactAbsence>>
63}
64
65function bindings(
66 over: Partial<GeminiPublishedBindings> = {},
67): GeminiPublishedBindings {
68 return {
69 aliases: {},
70 changelog: {
71 url: 'https://aistudio.google.com/docs/changelog.md',
72 hash: 'changelog',
73 },
74 gemma: {},
75 gemmaCard: null,
76 gemmaSource: {
77 url: 'https://ai.google.dev/gemma/docs/core/model_card_4',
78 hash: 'gemma',
79 },
80 docsFailures: { failed: 0, skipped: 0, first: [] },
81 ...over,
82 }
83}
84
85describe('gemini published bindings', () => {
86 it('routes only an automatic-routing sentence, one id per row', () => {
87 const routes = parseAutomaticRoutes(`
88| \`gemini-3.7-flash\` | August 13, 2026 | N/A | \`gemini-3.8-flash\` (automatically routes API requests to \`gemini-3.8-flash\`) |
89| \`gemini-3.5-flash\` | May 19, 2026 | N/A | \`gemini-3.6-flash\` (automatically routed to \`gemini-3.6-flash\`) |
90| \`gemini-omni-flash-preview\` | June 30, 2026 | October 22, 2026 | \`gemini-omni-1.1-flash\` |
91
92Requests to \`gemini-2.0-flash\` are shut down. The recommended replacement is \`gemini-3.6-flash\`.
93`)
94 expect([...routes]).toEqual([
95 ['gemini-3.7-flash', 'gemini-3.8-flash'],
96 ['gemini-3.5-flash', 'gemini-3.6-flash'],
97 ])
98 })
99
100 it('reads a Release date column and skips a parenthetical id', () => {
101 const dates = parseGeminiReleaseDates(`
102{% table %}
103 * Model
104 * Release date
105 * Shutdown date
106 ---
107 * \`gemini-4-argon\`
108 * October 13, 2026
109 * No shutdown date announced
110 ---
111 * \`gemini-3.8-flash\` (\`gemini-3.7-flash\` is routed)
112 * September 2, 2026
113 * No shutdown date announced
114 ---
115 * \`gemini-3.5-transcribe\`
116 * August 2026
117 * No shutdown date announced
118 ---
119 * \`embedding-gecko-001\`
120 *
121 * No shutdown date announced
122{% /table %}
123`)
124 expect([...dates]).toEqual([
125 ['gemini-4-argon', '2026-10-13'],
126 ['gemini-3.8-flash', '2026-09-02'],
127 ['gemini-3.5-transcribe', '2026-08-01'],
128 ])
129 })
130
131 it('keeps the newest changelog alias and ignores a later hop', () => {
132 const aliases = parseChangelogAliases(CHANGELOG)
133 expect(aliases.get('gemini-flash-latest')).toBe('gemini-3.5-flash')
134 expect(aliases.get('gemini-pro-latest')).toBe('gemini-3-pro-preview')
135 expect(aliases.has('gemini-flash-lite-latest')).toBe(false)
136 expect(aliases.has('gemini-3-pro-preview')).toBe(false)
137 expect(aliases.has('gemini-2.0-flash-thinking-exp-01-21')).toBe(false)
138 })
139
140 it('refuses a changelog that is not the Gemini API changelog', () => {
141 expect(() => parseChangelogAliases('# Models\n')).toThrow(
142 /not the Gemini API changelog/,
143 )
144 })
145
146 it('reads Gemma size columns and does not treat E2B as 2B', () => {
147 const modalities = parseGemmaModalities(GEMMA)
148 expect(modalities.get('gemma-4-31b-it')).toEqual({
149 input: ['text', 'image'],
150 output: ['text'],
151 })
152 expect(modalities.get('gemma-4-26b-a4b-it')).toEqual({
153 input: ['text', 'image'],
154 output: ['text'],
155 })
156 expect(modalities.get('gemma-4-12b-it')?.input).toEqual([
157 'text',
158 'image',
159 'audio',
160 ])
161 expect(modalities.has('gemma-4-2b-it')).toBe(false)
162 expect(modalities.has('gemma-4-4b-it')).toBe(false)
163 })
164
165 it('reads the Gemma card served as HTML (#568)', () => {
166 const html = `<p>Gemma 4 models, generating text output.</p>
167<table><thead><tr><th style="text-align: left">Property</th><th>E2B</th><th>31B Dense</th></tr></thead>
168<tbody><tr><td><strong>Supported Modalities</strong></td><td>Text, Image, Audio</td><td>Text, Image</td></tr></tbody></table>`
169 const modalities = parseGemmaModalities(htmlTables(html))
170 expect([...modalities]).toEqual([
171 ['gemma-4-31b-it', { input: ['text', 'image'], output: ['text'] }],
172 ])
173 })
174
175 it('returns no Gemma modalities when the card has no such row', () => {
176 expect(
177 parseGemmaModalities('Gemma 4 models, generating text output.\n').size,
178 ).toBe(0)
179 })
180
181 it('throws when a Gemma modality cell is not a medium', () => {
182 expect(() =>
183 parseGemmaModalities(`generating text output
184| Property | 31B Dense |
185| **Supported Modalities** | Text, Hologram |
186`),
187 ).toThrow(/unknown modality/)
188 })
189
190 it('copies alias modalities and records the alias on the dated row', () => {
191 const modalities = {
192 input: ['text', 'image', 'audio', 'video', 'file'],
193 output: ['text'],
194 }
195 const models = attachGeminiPublishedFacts<Listed>(
196 [
197 {
198 rawId: 'gemini-3.5-flash',
199 modalities,
200 factSources: {
201 modalities: {
202 derivation: 'docs-derived' as const,
203 sourceUrl:
204 'https://aistudio.google.com/docs/models/gemini-3.5-flash.md',
205 sourceHash: 'page',
206 path: 'Supported data types',
207 },
208 },
209 },
210 { rawId: 'gemini-flash-latest', modalities: null },
211 {
212 rawId: 'gemini-3-pro-preview',
213 modalities: { input: ['text'], output: ['text'] },
214 factSources: {
215 modalities: {
216 derivation: 'docs-derived' as const,
217 sourceUrl:
218 'https://aistudio.google.com/docs/models/gemini-3-pro-preview.md',
219 path: 'Supported data types',
220 },
221 },
222 },
223 { rawId: 'gemini-pro-latest', modalities: null },
224 { rawId: 'gemini-flash-lite-latest', modalities: null },
225 { rawId: 'gemma-4-31b-it', modalities: null },
226 ],
227 bindings({
228 aliases: {
229 'gemini-flash-latest': 'gemini-3.5-flash',
230 'gemini-pro-latest': 'gemini-3-pro-preview',
231 },
232 gemma: {
233 'gemma-4-31b-it': { input: ['text', 'image'], output: ['text'] },
234 },
235 }),
236 )
237 const flash = models.find((model) => model.rawId === 'gemini-flash-latest')
238 expect(flash?.modalities).toEqual(modalities)
239 expect(flash?.factSources?.modalities).toEqual({
240 derivation: 'docs-derived',
241 sourceUrl: 'https://aistudio.google.com/docs/models/gemini-3.5-flash.md',
242 sourceHash: 'page',
243 path: 'Supported data types; alias of gemini-3.5-flash',
244 })
245 const target = models.find((model) => model.rawId === 'gemini-3.5-flash')
246 expect(target?.aliases).toEqual(['gemini-flash-latest'])
247 expect(target?.factSources?.aliases?.path).toBe('latest alias')
248 // Issue #709: each named alias points at its stated target, listed or
249 // not; a `-latest` row the changelog names nothing for says so.
250 expect(flash?.aliasOf).toBe('gemini-3.5-flash')
251 expect(flash?.factSources?.aliasOf).toEqual({
252 derivation: 'docs-derived',
253 sourceUrl: 'https://aistudio.google.com/docs/changelog.md',
254 sourceHash: 'changelog',
255 path: 'latest alias',
256 })
257 expect(
258 models.find((model) => model.rawId === 'gemini-pro-latest')?.aliasOf,
259 ).toBe('gemini-3-pro-preview')
260 const lite = models.find(
261 (model) => model.rawId === 'gemini-flash-lite-latest',
262 )
263 expect(lite?.aliasOf).toBeNull()
264 expect(lite?.factSources?.aliasOf?.path).toBe('unstated')
265 expect(
266 models.find((model) => model.rawId === 'gemma-4-31b-it')?.factSources
267 ?.aliasOf,
268 ).toBeUndefined()
269 expect(
270 models.find((model) => model.rawId === 'gemini-pro-latest')?.modalities,
271 ).toEqual({ input: ['text'], output: ['text'] })
272 expect(
273 models.find((model) => model.rawId === 'gemini-flash-lite-latest')
274 ?.modalities,
275 ).toBeNull()
276 expect(
277 models.find((model) => model.rawId === 'gemma-4-31b-it')?.modalities,
278 ).toEqual({ input: ['text', 'image'], output: ['text'] })
279 })
280
281 it('copies an alias price from the changelog target (#661)', () => {
282 const models = attachGeminiPublishedFacts<Listed>(
283 [
284 {
285 rawId: 'gemini-3-flash-preview',
286 modalities: null,
287 pricing: { price: 1 },
288 factSources: {
289 pricing: {
290 derivation: 'docs-derived',
291 sourceUrl: 'https://aistudio.google.com/docs/pricing.md',
292 sourceHash: 'pricing-page',
293 path: 'Input price',
294 },
295 },
296 },
297 {
298 rawId: 'gemini-flash-latest',
299 modalities: null,
300 pricing: null,
301 absent: { pricing: 'cleared' },
302 },
303 ],
304 bindings({
305 aliases: { 'gemini-flash-latest': 'gemini-3-flash-preview' },
306 }),
307 )
308 const alias = models.find((model) => model.rawId === 'gemini-flash-latest')
309 expect(alias?.pricing).toEqual({ price: 1 })
310 expect(alias?.absent).toBeUndefined()
311 expect(alias?.factSources?.pricing).toEqual({
312 derivation: 'docs-derived',
313 sourceUrl: 'https://aistudio.google.com/docs/pricing.md',
314 sourceHash: 'pricing-page',
315 path: 'Input price; alias of gemini-3-flash-preview',
316 })
317 })
318
319 it('keeps stored modalities when the changelog or Gemma card fails', () => {
320 const models = attachGeminiPublishedFacts<Listed>(
321 [
322 { rawId: 'gemini-flash-latest', modalities: null },
323 {
324 rawId: 'gemini-3.5-flash',
325 modalities: { input: ['text'], output: ['text'] },
326 },
327 { rawId: 'gemma-4-31b-it', modalities: null },
328 {
329 rawId: 'gemma-4-26b-a4b-it',
330 modalities: { input: ['text'], output: ['text'] },
331 },
332 ],
333 bindings({ aliases: null, gemma: null }),
334 )
335 expect(
336 models.find((model) => model.rawId === 'gemini-flash-latest')?.absent
337 ?.modalities,
338 ).toBe('unavailable')
339 // Every alias link is the changelog's: a failed read keeps them all.
340 expect(
341 models.find((model) => model.rawId === 'gemini-flash-latest')?.absent,
342 ).toEqual({
343 modalities: 'unavailable',
344 aliases: 'unavailable',
345 aliasOf: 'unavailable',
346 maker: 'unavailable',
347 openWeights: 'unavailable',
348 // Its tools are the changelog target's too (#707).
349 serverTools: 'unavailable',
350 })
351 expect(
352 models.find((model) => model.rawId === 'gemini-3.5-flash')?.absent,
353 ).toEqual({
354 aliases: 'unavailable',
355 maker: 'unavailable',
356 openWeights: 'unavailable',
357 })
358 expect(
359 models.find((model) => model.rawId === 'gemma-4-31b-it')?.absent
360 ?.modalities,
361 ).toBe('unavailable')
362 expect(
363 models.find((model) => model.rawId === 'gemma-4-26b-a4b-it')?.modalities,
364 ).toEqual({ input: ['text'], output: ['text'] })
365 })
366 it('copies alias server tools from the changelog target, or keeps them when it fails (#707)', () => {
367 type Row = Pick<
368 ModelInfo,
369 'rawId' | 'modalities' | 'serverTools' | 'factSources' | 'absent'
370 >
371 const page =
372 'https://aistudio.google.com/docs/models/gemini-3-flash-preview.md'
373 const rows: Array<Row> = [
374 {
375 rawId: 'gemini-3-flash-preview',
376 modalities: null,
377 serverTools: ['googleSearch'],
378 factSources: {
379 serverTools: {
380 googleSearch: {
381 derivation: 'docs-derived',
382 sourceUrl: page,
383 path: 'Capabilities',
384 },
385 },
386 },
387 },
388 { rawId: 'gemini-flash-latest', modalities: null, serverTools: null },
389 ]
390 const alias = attachGeminiPublishedFacts<Row>(
391 rows,
392 bindings({
393 aliases: { 'gemini-flash-latest': 'gemini-3-flash-preview' },
394 }),
395 ).find((model) => model.rawId === 'gemini-flash-latest')
396 expect(alias?.serverTools).toEqual(['googleSearch'])
397 expect(alias?.factSources?.serverTools).toEqual({
398 googleSearch: {
399 derivation: 'docs-derived',
400 sourceUrl: page,
401 path: 'Capabilities; alias of gemini-3-flash-preview',
402 },
403 })
404
405 const failed = attachGeminiPublishedFacts<Row>(
406 rows,
407 bindings({ aliases: null }),
408 ).find((model) => model.rawId === 'gemini-flash-latest')
409 expect(failed?.absent?.serverTools).toBe('unavailable')
410
411 // The target's page failed: the alias keeps its stored tools as well.
412 const unread = attachGeminiPublishedFacts<Row>(
413 [
414 {
415 rawId: 'gemini-3-flash-preview',
416 modalities: null,
417 serverTools: null,
418 absent: { serverTools: 'unavailable' },
419 },
420 { rawId: 'gemini-flash-latest', modalities: null, serverTools: null },
421 ],
422 bindings({
423 aliases: { 'gemini-flash-latest': 'gemini-3-flash-preview' },
424 }),
425 ).find((model) => model.rawId === 'gemini-flash-latest')
426 expect(unread?.absent?.serverTools).toBe('unavailable')
427 expect(unread?.factSources?.serverTools).toBeUndefined()
428 })
429})
430
431describe('gemma maker and weights (#710)', () => {
432 const HEADER = readFileSync(
433 new URL('./fixtures/gemma-4-card-header.html.txt', import.meta.url),
434 'utf8',
435 )
436 const card = parseGemmaCardFacts(HEADER)
437 const rows: Array<Listed> = [
438 { rawId: 'gemma-4-31b-it', modalities: null },
439 { rawId: 'gemini-3.5-flash', modalities: null },
440 ]
441
442 it('reads Authors, the open-weights sentence and the Hugging Face link (2026-11-21)', () => {
443 expect(card).toEqual({
444 maker: 'Google DeepMind',
445 openWeights: true,
446 weightsUrl: 'https://huggingface.co/collections/google/gemma-4',
447 })
448 expect(parseGemmaCardFacts('<p>Gemma 4</p>')).toEqual({
449 maker: null,
450 openWeights: null,
451 weightsUrl: null,
452 })
453 })
454
455 it('binds them only to the sizes the card table binds', () => {
456 const [gemma, gemini] = attachGeminiPublishedFacts(
457 rows,
458 bindings({
459 gemma: { 'gemma-4-31b-it': { input: ['text'], output: ['text'] } },
460 gemmaCard: card,
461 }),
462 )
463 expect(gemma).toMatchObject({
464 maker: 'Google DeepMind',
465 openWeights: true,
466 weightsUrl: 'https://huggingface.co/collections/google/gemma-4',
467 factSources: {
468 maker: { path: 'Authors' },
469 openWeights: { path: 'open-weights models; Hugging Face' },
470 },
471 })
472 expect(gemini).toEqual(rows[1])
473 })
474
475 it('keeps the stored facts when the card could not be read', () => {
476 const [gemma] = attachGeminiPublishedFacts(
477 rows,
478 bindings({ gemma: null, gemmaCard: null }),
479 )
480 expect(gemma?.absent).toMatchObject({
481 maker: 'unavailable',
482 openWeights: 'unavailable',
483 })
484 })
485})