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

gemini-native-image-wire.spec.ts

43 lines1.8 KB

1import { test, expect } from './fixtures'
2​
3/**
4 * Wire-format verification for Gemini-native `modelOptions` on the image
5 * generation path (fix/gemini-native-image-model-options).
6 *
7 * `/api/gemini-native-image-wire` drives `generateImage()` against
8 * `gemini-2.5-flash-image` with `modelOptions: { safetySettings,
9 * thinkingConfig }`. That request lands on `geminiNativeImageMount` in
10 * global-setup.ts, which reads the raw, untranslated request body (aimock's
11 * own journal normalises this endpoint's requests and drops these exact
12 * fields before journalling — see that mount's comment) and rejects with 400
13 * unless `safetySettings` is present at the request root,
14 * `generationConfig.thinkingConfig` is present nested under
15 * `generationConfig`, and no Imagen-only field (`personGeneration`,
16 * `negativePrompt`, a root-level `aspectRatio`, …) appears anywhere in the
17 * body.
18 *
19 * Before the fix, `generateWithGeminiApi` only forwarded `modelOptions.seed`
20 * — `safetySettings` and `thinkingConfig` were silently dropped even though
21 * the adapter's own provider-options type already declared them. Reverting
22 * the fix reproduces that: the outgoing request loses both fields, the mount
23 * rejects it with 400, `client.models.generateContent()` throws, and the
24 * route returns `ok: false` — this spec's `ok` assertion fails.
25 */
26test.describe('gemini native image — modelOptions reach the generateContent wire', () => {
27 test('safetySettings and thinkingConfig survive to the request; no Imagen field does', async ({
28 request,
29 }) => {
30 const res = await request.post('/api/gemini-native-image-wire')
31 expect(res.ok()).toBe(true)
32​
33 const { ok, images, error } = (await res.json()) as {
34 ok: boolean
35 images?: number
36 error?: string
37 }
38​
39 expect(error ?? null).toBeNull()
40 expect(ok).toBe(true)
41 expect(images).toBe(1)
42 })
43})