Open History to see the last commit
1import { readFileSync } from 'node:fs'
2
3import { describe, expect, it } from 'vitest'
4
5import { parsePageOutputVideo } from './gemini-features.ts'
6import {
7 GEMINI_INTERACTIONS_SPEC_URL,
8 geminiVideoEndpoint,
9 parseVideoModels,
10 videoModelPages,
11} from './gemini-video.ts'
12import type { OpenApiDocument } from './types.ts'
13
14/** https://aistudio.google.com/docs/models/gemini-omni-flash.md, 2026-11-16. */
15const OMNI_PAGE = readFileSync(
16 new URL('./fixtures/gemini-omni-flash.md.txt', import.meta.url),
17 'utf8',
18)
19const PAGE_URL = 'https://aistudio.google.com/docs/models/gemini-omni-flash.md'
20
21const INDEX = `
22{% table variant="model" %}
23 * Model
24 * Endpoint
25
26 ---
27
28 * [Gemini 3.5 Transcribe](/docs/models/gemini-3.5-transcribe)
29 * \`gemini-3.5-transcribe\`
30
31 ---
32
33 * [Gemini Omni Flash](/docs/models/gemini-omni-flash)
34 * \`gemini-omni-1.2-flash\`
35 \`gemini-omni-1.1-flash\`
36{% /table %}
37`
38
39/** The parts of Google's Interactions document the builder reads. */
40function spec(): OpenApiDocument {
41 return {
42 openapi: '3.0.3',
43 info: { title: 'Gemini API', version: 'v1beta' },
44 paths: {
45 '/{api_version}/interactions': {
46 post: {
47 operationId: 'CreateInteraction',
48 requestBody: {
49 content: {
50 'application/json': {
51 schema: {
52 oneOf: [
53 {
54 $ref: '#/components/schemas/CreateAgentInteractionParams',
55 },
56 {
57 $ref: '#/components/schemas/CreateModelInteractionParams',
58 },
59 ],
60 },
61 },
62 },
63 },
64 responses: {
65 '200': {
66 content: {
67 'application/json': {
68 schema: { $ref: '#/components/schemas/Interaction' },
69 },
70 },
71 },
72 },
73 },
74 },
75 },
76 components: {
77 schemas: {
78 CreateAgentInteractionParams: { type: 'object' },
79 CreateModelInteractionParams: {
80 type: 'object',
81 required: ['input', 'model'],
82 properties: {
83 model: { $ref: '#/components/schemas/ModelOption' },
84 input: { type: 'string' },
85 response_format: { $ref: '#/components/schemas/ResponseFormat' },
86 },
87 },
88 ModelOption: { type: 'string', enum: ['gemini-omni-1.1-flash'] },
89 ResponseFormat: {
90 oneOf: [{ $ref: '#/components/schemas/VideoResponseFormat' }],
91 },
92 VideoResponseFormat: {
93 type: 'object',
94 required: ['type'],
95 properties: {
96 type: { const: 'video' },
97 aspect_ratio: { type: 'string', enum: ['16:9', '9:16'] },
98 duration: { type: 'string', format: 'google-duration' },
99 resolution: { type: 'string', enum: ['360p', '720p'] },
100 },
101 },
102 Interaction: { type: 'object', properties: { id: { type: 'string' } } },
103 },
104 },
105 }
106}
107
108describe('parsePageOutputVideo', () => {
109 it('reads the whole-second range', () => {
110 expect(
111 parsePageOutputVideo(
112 '| Limits | **Output video** 3s-15s (360p, 24 FPS) |',
113 ),
114 ).toEqual({ minSeconds: 3, maxSeconds: 15 })
115 })
116
117 it('is null on a page with no output video limit', () => {
118 expect(
119 parsePageOutputVideo('| Limits | **Output token limit** 8,192 |'),
120 ).toBe(null)
121 })
122
123 it('throws on a limit it cannot read, so no unbounded schema is published', () => {
124 expect(() =>
125 parsePageOutputVideo('| Limits | **Output video** up to 15 seconds |'),
126 ).toThrow('unreadable Output video limit "up to 15 seconds"')
127 })
128})
129
130describe('parseVideoModels', () => {
131 it("binds each section's range to its own model code", () => {
132 expect(parseVideoModels(OMNI_PAGE, PAGE_URL)).toEqual([
133 {
134 rawId: 'gemini-omni-1.2-flash',
135 pageUrl: PAGE_URL,
136 minSeconds: 3,
137 maxSeconds: 15,
138 },
139 {
140 rawId: 'gemini-omni-1.1-flash',
141 pageUrl: PAGE_URL,
142 minSeconds: 3,
143 maxSeconds: 10,
144 },
145 ])
146 })
147})
148
149describe('videoModelPages', () => {
150 it('follows the ids the video guide names to their index pages', () => {
151 const guide =
152 'Use [Gemini Omni Flash](/docs/omni) (`gemini-omni-1.2-flash`). `veo-3.1-generate-preview` was shut down.'
153 expect(videoModelPages(guide, INDEX)).toEqual([PAGE_URL])
154 })
155
156 it('is empty when the guide names no indexed model', () => {
157 expect(videoModelPages('Video understanding only.', INDEX)).toEqual([])
158 })
159})
160
161describe('geminiVideoEndpoint', () => {
162 const model = {
163 rawId: 'gemini-omni-1.1-flash',
164 pageUrl: PAGE_URL,
165 minSeconds: 3,
166 maxSeconds: 5,
167 }
168
169 it('pins the model and narrows duration on the real path', () => {
170 const { endpoint } = geminiVideoEndpoint(spec(), model, 'h'.repeat(64))
171 expect(endpoint).toMatchObject({
172 publicId: 'gemini-omni-1.1-flash',
173 path: '/v1beta/interactions',
174 activity: 'video',
175 derivation: 'generated',
176 source: { url: GEMINI_INTERACTIONS_SPEC_URL, hash: 'h'.repeat(64) },
177 })
178 const input = endpoint.input as {
179 properties: Record<string, unknown>
180 $defs: Record<string, { properties: Record<string, { enum?: unknown }> }>
181 }
182 // The model request only: the agent variant is another route's body.
183 expect(input.properties.model).toMatchObject({
184 type: 'string',
185 enum: ['gemini-omni-1.1-flash'],
186 })
187 const format = input.$defs.VideoResponseFormat?.properties
188 expect(format?.duration?.enum).toEqual(['3s', '4s', '5s'])
189 expect(format?.aspect_ratio?.enum).toEqual(['16:9', '9:16'])
190 expect(format?.resolution?.enum).toEqual(['360p', '720p'])
191 expect(endpoint.output).toMatchObject({ type: 'object' })
192 })
193
194 it('throws when the document no longer has a duration string', () => {
195 const changed = spec()
196 const schemas = changed.components?.schemas as Record<
197 string,
198 { properties?: Record<string, unknown> }
199 >
200 delete schemas.VideoResponseFormat?.properties?.duration
201 expect(() => geminiVideoEndpoint(changed, model, 'h')).toThrow(
202 `${GEMINI_INTERACTIONS_SPEC_URL} has no VideoResponseFormat.duration string; gemini-omni-1.1-flash gets no schema`,
203 )
204 })
205
206 it('throws when the create operation is gone', () => {
207 expect(() =>
208 geminiVideoEndpoint({ ...spec(), paths: {} }, model, 'h'),
209 ).toThrow('has no POST /{api_version}/interactions')
210 })
211})