Open History to see the last commit
1import path from 'path'
2import { fileURLToPath } from 'url'
3import { test, expect } from './fixtures'
4import {
5 fillPrompt,
6 clickGenerate,
7 waitForGenerationComplete,
8 featureUrl,
9} from './helpers'
10import { providersFor } from './test-matrix'
11
12const __filename = fileURLToPath(import.meta.url)
13const __dirname = path.dirname(__filename)
14const testImagePath = path.resolve(__dirname, '../test-assets/guitar-shop.png')
15
16// Image-to-video: the prompt is sent as multimodal parts (text + attached
17// image). For OpenAI/Sora the image part is uploaded as `input_reference`,
18// which switches the SDK to a multipart POST /v1/videos — exercising the
19// imagePartToFile conversion and job polling flow end-to-end.
20for (const provider of providersFor('image-to-video')) {
21 test.describe(`${provider} -- image-to-video`, () => {
22 test('sse -- animates an image via SSE connection', async ({
23 page,
24 request,
25 testId,
26 aimockPort,
27 }) => {
28 await page.goto(
29 featureUrl(provider, 'image-to-video', testId, aimockPort, 'sse'),
30 )
31 // Cold vite compiles of this route can delay hydration past fillPrompt's
32 // fallback; wait for the page to settle before interacting.
33 await page.waitForLoadState('networkidle')
34 await fillPrompt(page, 'animate this product photo')
35 await page.getByTestId('image-input').setInputFiles(testImagePath)
36 await clickGenerate(page)
37 await waitForGenerationComplete(page, 60_000)
38 const video = page.getByTestId('generated-video')
39 await expect(video).toBeVisible()
40
41 // Prove the multipart POST /v1/videos round-tripped with the prompt
42 // text intact — the SDK switches to multipart when `input_reference`
43 // carries a File, and aimock extracts `prompt` from the form data.
44 const journalRes = await request.get(
45 `http://127.0.0.1:${aimockPort}/v1/_requests`,
46 )
47 const entries = (await journalRes.json()) as Array<{
48 path?: string
49 body?: unknown
50 }>
51 const videoEntry = entries.find(
52 (e) =>
53 e.path === '/v1/videos' &&
54 JSON.stringify(e.body ?? '').includes('animate this product photo'),
55 )
56 expect(videoEntry).toBeTruthy()
57 })
58
59 test('http-stream -- animates an image via HTTP stream', async ({
60 page,
61 testId,
62 aimockPort,
63 }) => {
64 await page.goto(
65 featureUrl(
66 provider,
67 'image-to-video',
68 testId,
69 aimockPort,
70 'http-stream',
71 ),
72 )
73 // Cold vite compiles of this route can delay hydration past fillPrompt's
74 // fallback; wait for the page to settle before interacting.
75 await page.waitForLoadState('networkidle')
76 await fillPrompt(page, 'animate this product photo')
77 await page.getByTestId('image-input').setInputFiles(testImagePath)
78 await clickGenerate(page)
79 await waitForGenerationComplete(page, 60_000)
80 const video = page.getByTestId('generated-video')
81 await expect(video).toBeVisible()
82 })
83
84 test('fetcher -- animates an image via server function', async ({
85 page,
86 testId,
87 aimockPort,
88 }) => {
89 await page.goto(
90 featureUrl(provider, 'image-to-video', testId, aimockPort, 'fetcher'),
91 )
92 // Cold vite compiles of this route can delay hydration past fillPrompt's
93 // fallback; wait for the page to settle before interacting.
94 await page.waitForLoadState('networkidle')
95 await fillPrompt(page, 'animate this product photo')
96 await page.getByTestId('image-input').setInputFiles(testImagePath)
97 await clickGenerate(page)
98 await waitForGenerationComplete(page, 60_000)
99 const video = page.getByTestId('generated-video')
100 await expect(video).toBeVisible()
101 })
102 })
103}