Open History to see the last commit
1import { readFileSync } from 'node:fs'
2
3import { afterEach, describe, expect, it, vi } from 'vitest'
4
5import {
6 GEMINI_MODELS_INDEX_URL,
7 parsePageOutputVideo,
8} from './gemini-features.ts'
9import {
10 GEMINI_INTERACTIONS_SPEC_URL,
11 GEMINI_VIDEO_GUIDE_URL,
12 geminiVideoEndpoint,
13 geminiVideoEndpoints,
14 parseVideoModels,
15 streamVideoWarning,
16 videoModelPages,
17} from './gemini-video.ts'
18import type { OpenApiDocument } from './types.ts'
19
20/** https://aistudio.google.com/docs/models/gemini-omni-flash.md, 2026-11-16. */
21const OMNI_PAGE = readFileSync(
22 new URL('./fixtures/gemini-omni-flash.md.txt', import.meta.url),
23 'utf8',
24)
25/** https://aistudio.google.com/docs/models/genie-4.md, 2026-11-20. */
26const GENIE_PAGE = readFileSync(
27 new URL('./fixtures/gemini-genie-4.md.txt', import.meta.url),
28 'utf8',
29)
30const PAGE_URL = 'https://aistudio.google.com/docs/models/gemini-omni-flash.md'
31const GENIE_URL = 'https://aistudio.google.com/docs/models/genie-4.md'
32
33const INDEX = `
34{% table variant="model" %}
35 * Model
36 * Endpoint
37
38 ---
39
40 * [Gemini 3.5 Transcribe](/docs/models/gemini-3.5-transcribe)
41 * \`gemini-3.5-transcribe\`
42
43 ---
44
45 * [Gemini Omni Flash](/docs/models/gemini-omni-flash)
46 * \`gemini-omni-1.2-flash\`
47 \`gemini-omni-1.1-flash\`
48{% /table %}
49`
50
51/** The parts of Google's Interactions document the builder reads. */
52function spec(): OpenApiDocument {
53 return {
54 openapi: '3.0.3',
55 info: { title: 'Gemini API', version: 'v1beta' },
56 paths: {
57 '/{api_version}/interactions': {
58 post: {
59 operationId: 'CreateInteraction',
60 requestBody: {
61 content: {
62 'application/json': {
63 schema: {
64 oneOf: [
65 {
66 $ref: '#/components/schemas/CreateAgentInteractionParams',
67 },
68 {
69 $ref: '#/components/schemas/CreateModelInteractionParams',
70 },
71 ],
72 },
73 },
74 },
75 },
76 responses: {
77 '200': {
78 content: {
79 'application/json': {
80 schema: { $ref: '#/components/schemas/Interaction' },
81 },
82 },
83 },
84 },
85 },
86 },
87 },
88 components: {
89 schemas: {
90 CreateAgentInteractionParams: { type: 'object' },
91 CreateModelInteractionParams: {
92 type: 'object',
93 required: ['input', 'model'],
94 properties: {
95 model: { $ref: '#/components/schemas/ModelOption' },
96 input: { type: 'string' },
97 response_format: { $ref: '#/components/schemas/ResponseFormat' },
98 },
99 },
100 ModelOption: { type: 'string', enum: ['gemini-omni-1.1-flash'] },
101 ResponseFormat: {
102 oneOf: [{ $ref: '#/components/schemas/VideoResponseFormat' }],
103 },
104 VideoResponseFormat: {
105 type: 'object',
106 required: ['type'],
107 properties: {
108 type: { const: 'video' },
109 aspect_ratio: { type: 'string', enum: ['16:9', '9:16'] },
110 duration: { type: 'string', format: 'google-duration' },
111 resolution: { type: 'string', enum: ['360p', '720p'] },
112 },
113 },
114 Interaction: { type: 'object', properties: { id: { type: 'string' } } },
115 },
116 },
117 }
118}
119
120describe('parsePageOutputVideo', () => {
121 it('reads the whole-second range', () => {
122 expect(
123 parsePageOutputVideo(
124 '| Limits | **Output video** 3s-15s (360p, 24 FPS) |',
125 ),
126 ).toEqual({ minSeconds: 3, maxSeconds: 15 })
127 })
128
129 it('is null on a page with no output video limit', () => {
130 expect(
131 parsePageOutputVideo('| Limits | **Output token limit** 8,192 |'),
132 ).toBe(null)
133 })
134
135 it('throws on a limit it cannot read, so no unbounded schema is published', () => {
136 expect(() =>
137 parsePageOutputVideo('| Limits | **Output video** up to 15 seconds |'),
138 ).toThrow('unreadable Output video limit "up to 15 seconds"')
139 })
140
141 it('reads a resolution, fps and token rate as a stream, with no duration', () => {
142 expect(parsePageOutputVideo(GENIE_PAGE)).toEqual({
143 stream: {
144 width: 1280,
145 height: 720,
146 fps: 24,
147 tokensPerFrame: 240,
148 tokensPerSecond: 5760,
149 },
150 })
151 })
152})
153
154describe('parseVideoModels', () => {
155 it('binds genie-4 to the stream limit on its live page', () => {
156 expect(parseVideoModels(GENIE_PAGE, GENIE_URL)).toEqual([
157 {
158 rawId: 'genie-4',
159 pageUrl: GENIE_URL,
160 stream: {
161 width: 1280,
162 height: 720,
163 fps: 24,
164 tokensPerFrame: 240,
165 tokensPerSecond: 5760,
166 },
167 },
168 ])
169 })
170
171 it("binds each section's range to its own model code", () => {
172 expect(parseVideoModels(OMNI_PAGE, PAGE_URL)).toEqual([
173 {
174 rawId: 'gemini-omni-1.2-flash',
175 pageUrl: PAGE_URL,
176 minSeconds: 3,
177 maxSeconds: 15,
178 },
179 {
180 rawId: 'gemini-omni-1.1-flash',
181 pageUrl: PAGE_URL,
182 minSeconds: 3,
183 maxSeconds: 10,
184 },
185 ])
186 })
187})
188
189describe('videoModelPages', () => {
190 it('follows the ids the video guide names to their index pages', () => {
191 const guide =
192 'Use [Gemini Omni Flash](/docs/omni) (`gemini-omni-1.2-flash`). `veo-3.1-generate-preview` was shut down.'
193 expect(videoModelPages(guide, INDEX)).toEqual([PAGE_URL])
194 })
195
196 it('is empty when the guide names no indexed model', () => {
197 expect(videoModelPages('Video understanding only.', INDEX)).toEqual([])
198 })
199})
200
201describe('geminiVideoEndpoint', () => {
202 const model = {
203 rawId: 'gemini-omni-1.1-flash',
204 pageUrl: PAGE_URL,
205 minSeconds: 3,
206 maxSeconds: 5,
207 }
208
209 it('pins the model and narrows duration on the real path', () => {
210 const { endpoint } = geminiVideoEndpoint(spec(), model, 'h'.repeat(64))
211 expect(endpoint).toMatchObject({
212 publicId: 'gemini-omni-1.1-flash',
213 path: '/v1beta/interactions',
214 activity: 'video',
215 derivation: 'generated',
216 source: { url: GEMINI_INTERACTIONS_SPEC_URL, hash: 'h'.repeat(64) },
217 })
218 const input = endpoint.input as {
219 properties: Record<string, unknown>
220 $defs: Record<string, { properties: Record<string, { enum?: unknown }> }>
221 }
222 // The model request only: the agent variant is another route's body.
223 expect(input.properties.model).toMatchObject({
224 type: 'string',
225 enum: ['gemini-omni-1.1-flash'],
226 })
227 const format = input.$defs.VideoResponseFormat?.properties
228 expect(format?.duration?.enum).toEqual(['3s', '4s', '5s'])
229 expect(format?.aspect_ratio?.enum).toEqual(['16:9', '9:16'])
230 expect(format?.resolution?.enum).toEqual(['360p', '720p'])
231 expect(endpoint.output).toMatchObject({ type: 'object' })
232 })
233
234 it('throws when the document no longer has a duration string', () => {
235 const changed = spec()
236 const schemas = changed.components?.schemas as Record<
237 string,
238 { properties?: Record<string, unknown> }
239 >
240 delete schemas.VideoResponseFormat?.properties?.duration
241 expect(() => geminiVideoEndpoint(changed, model, 'h')).toThrow(
242 `${GEMINI_INTERACTIONS_SPEC_URL} has no VideoResponseFormat.duration string; gemini-omni-1.1-flash gets no schema`,
243 )
244 })
245
246 it('throws when the create operation is gone', () => {
247 expect(() =>
248 geminiVideoEndpoint({ ...spec(), paths: {} }, model, 'h'),
249 ).toThrow('has no POST /{api_version}/interactions')
250 })
251})
252
253describe('geminiVideoEndpoints', () => {
254 const MYSTERY_URL = 'https://aistudio.google.com/docs/models/mystery-video.md'
255 const LIVE_INDEX = `
256{% table variant="model" %}
257 * Model
258 * Endpoint
259
260 ---
261
262 * [Gemini Omni Flash](/docs/models/gemini-omni-flash)
263 * \`gemini-omni-1.2-flash\`
264 \`gemini-omni-1.1-flash\`
265
266 ---
267
268 * [Genie 4](/docs/models/genie-4)
269 * \`genie-4\`
270{% /table %}
271`
272 const LIVE_GUIDE = 'Use `gemini-omni-1.2-flash` and `genie-4` for video.'
273 const UNREADABLE_INDEX = `
274{% table variant="model" %}
275 * Model
276 * Endpoint
277
278 ---
279
280 * [Gemini Omni Flash](/docs/models/gemini-omni-flash)
281 * \`gemini-omni-1.2-flash\`
282 \`gemini-omni-1.1-flash\`
283
284 ---
285
286 * [Genie 4](/docs/models/genie-4)
287 * \`genie-4\`
288
289 ---
290
291 * [Mystery](/docs/models/mystery-video)
292 * \`mystery-video\`
293{% /table %}
294`
295 const MYSTERY = `
296## mystery-video
297
298| Model code | \`mystery-video\` |
299| Limits | **Output video** up to 15 seconds |
300`
301
302 afterEach(() => {
303 vi.unstubAllGlobals()
304 })
305
306 function stub(
307 pages: Record<string, string>,
308 guide = LIVE_GUIDE,
309 index = LIVE_INDEX,
310 ) {
311 vi.stubGlobal('fetch', (input: string) => {
312 const url = String(input)
313 const body: Record<string, string> = {
314 [GEMINI_INTERACTIONS_SPEC_URL]: JSON.stringify(spec()),
315 [GEMINI_VIDEO_GUIDE_URL]: guide,
316 [GEMINI_MODELS_INDEX_URL]: index,
317 ...pages,
318 }
319 const text = body[url]
320 return Promise.resolve(
321 text === undefined
322 ? new Response('missing', { status: 404 })
323 : new Response(text),
324 )
325 })
326 }
327
328 it('builds clip schemas and warns for a real-time stream', async () => {
329 stub({ [PAGE_URL]: OMNI_PAGE, [GENIE_URL]: GENIE_PAGE })
330
331 const result = await geminiVideoEndpoints()
332
333 expect(result.endpoints.map((endpoint) => endpoint.publicId)).toEqual([
334 'gemini-omni-1.2-flash',
335 'gemini-omni-1.1-flash',
336 ])
337 expect(result.warnings).toContain(streamVideoWarning('genie-4'))
338 })
339
340 it('rejects the sync when one page is unreadable', async () => {
341 stub(
342 {
343 [PAGE_URL]: OMNI_PAGE,
344 [GENIE_URL]: GENIE_PAGE,
345 [MYSTERY_URL]: MYSTERY,
346 },
347 `${LIVE_GUIDE} Also \`mystery-video\`.`,
348 UNREADABLE_INDEX,
349 )
350
351 await expect(geminiVideoEndpoints()).rejects.toThrow(
352 'unreadable Output video limit "up to 15 seconds"',
353 )
354 })
355})