Open History to see the last commit
1import { test, expect } from './fixtures'
2import {
3 devtoolsUrl,
4 expectClassChangesOnHover,
5 expectHookNames,
6 generationCard,
7 openDevtools,
8 selectHook,
9 waitForAllGenerationHooks,
10 waitForDevtoolsHarness,
11} from './devtools-helpers'
12
13const generationHooks = [
14 { displayName: 'Image Studio', hookName: 'useGenerateImage' },
15 { displayName: 'Audio Studio', hookName: 'useGenerateAudio' },
16 { displayName: 'Speech Studio', hookName: 'useGenerateSpeech' },
17 { displayName: 'Transcription Studio', hookName: 'useTranscription' },
18 { displayName: 'Summary Studio', hookName: 'useSummarize' },
19 { displayName: 'Video Studio', hookName: 'useGenerateVideo' },
20] as const
21const customGeneration = {
22 displayName: 'Custom Generation',
23 hookName: 'useGeneration',
24} as const
25
26test.beforeEach(async ({ page }) => {
27 await page.addInitScript(() => localStorage.clear())
28})
29
30test('generation hooks register all specialized hooks with generation-only detail chrome', async ({
31 page,
32 testId,
33 aimockPort,
34}) => {
35 await page.goto(devtoolsUrl('/devtools-generation-hooks', testId, aimockPort))
36 await waitForDevtoolsHarness(page)
37 await page.getByTestId('mount-custom-generation').click()
38 await openDevtools(page)
39 await expectHookNames(page, [
40 ...generationHooks.map((hook) => hook.displayName),
41 customGeneration.displayName,
42 ])
43
44 for (const hook of generationHooks) {
45 await selectHook(page, hook.displayName)
46 await expect(
47 page.getByTestId('ai-devtools-hook-technical-name'),
48 ).toHaveText(hook.hookName)
49 await expect(page.getByTestId('ai-devtools-hook-tab')).toHaveText([
50 'Generation',
51 'State',
52 ])
53 await expect(page.getByTestId('ai-devtools-hook-metric-runs')).toBeVisible()
54 await expect(
55 page.getByTestId('ai-devtools-hook-metric-messages'),
56 ).toHaveCount(0)
57 await expect(page.getByTestId('ai-devtools-hook-metric-tools')).toHaveCount(
58 0,
59 )
60 await expect(
61 page.getByTestId('ai-devtools-hook-metric-tokens'),
62 ).toHaveCount(0)
63 await expect(page.getByTestId('ai-devtools-preview-pane')).toContainText(
64 'No output yet.',
65 )
66 }
67
68 await selectHook(page, customGeneration.displayName)
69 await expect(page.getByTestId('ai-devtools-hook-technical-name')).toHaveText(
70 customGeneration.hookName,
71 )
72})
73
74test('generation run history and output pane preserve ordered runs for every hook', async ({
75 page,
76 testId,
77 aimockPort,
78}) => {
79 await page.goto(devtoolsUrl('/devtools-generation-hooks', testId, aimockPort))
80 await waitForDevtoolsHarness(page)
81 await page.getByTestId('run-all-generation-hooks').click()
82 await waitForAllGenerationHooks(page)
83 await page.getByTestId('run-all-generation-hooks').click()
84 await waitForAllGenerationHooks(page)
85
86 await openDevtools(page)
87 for (const hook of generationHooks) {
88 await selectHook(page, hook.displayName)
89 await expect(page.getByTestId('ai-devtools-generation-run')).toHaveCount(2)
90 await expect(
91 page.getByTestId('ai-devtools-generation-run').first(),
92 ).toHaveAttribute('data-run-label', 'Run 1 of 2')
93 await expect(
94 page.getByTestId('ai-devtools-generation-run').last(),
95 ).toHaveAttribute('data-run-label', 'Run 2 of 2')
96 await expect(
97 page.getByTestId('ai-devtools-hook-metric-runs'),
98 ).toContainText('2')
99 await expect(
100 page.getByTestId('ai-devtools-generation-run').first(),
101 ).toContainText('loading no')
102 }
103
104 await selectHook(page, 'Image Studio')
105 await expect(page.getByTestId('ai-devtools-generation-output')).toHaveCount(4)
106 await expect(
107 page.getByTestId('ai-devtools-generation-output').first(),
108 ).toHaveAttribute('data-output-kind', 'image')
109 await expect(
110 page.getByTestId('ai-devtools-generation-output').first(),
111 ).toContainText('Run 1 of 2')
112 await expect(
113 page.getByTestId('ai-devtools-generation-output').last(),
114 ).toContainText('Run 2 of 2')
115
116 await selectHook(page, 'Audio Studio')
117 await expect(page.getByTestId('ai-devtools-generation-output')).toHaveCount(2)
118 await expect(
119 page.getByTestId('ai-devtools-generation-output').first(),
120 ).toHaveAttribute('data-output-kind', 'audio')
121 await expect(
122 page.getByTestId('ai-devtools-audio-output').first(),
123 ).toHaveAttribute('src', /^data:audio\/wav;base64,/)
124 await page.getByTestId('ai-devtools-audio-output').first().click()
125 await expect(page.getByTestId('ai-devtools-output-modal')).toHaveCount(0)
126
127 await selectHook(page, 'Speech Studio')
128 await expect(
129 page.getByTestId('ai-devtools-audio-output').first(),
130 ).toHaveAttribute('src', /^data:audio\/wav;base64,/)
131 await expect(generationCard(page, 'useGenerateSpeech')).toContainText('0.05s')
132
133 await selectHook(page, 'Transcription Studio')
134 await expect(
135 page.getByTestId('ai-devtools-generation-output').first(),
136 ).toContainText('Fender Stratocaster')
137
138 await selectHook(page, 'Summary Studio')
139 await expect(
140 page.getByTestId('ai-devtools-generation-output').first(),
141 ).toContainText('Fender Stratocaster')
142
143 await selectHook(page, 'Video Studio')
144 await expect(
145 page.getByTestId('ai-devtools-generation-progress').last(),
146 ).toHaveAttribute('aria-valuenow', '100')
147 await expect(
148 page.getByTestId('ai-devtools-video-output').first(),
149 ).not.toHaveAttribute('controls', '')
150})
151
152test('generation output modal, hover linking, and reset cleanup work from visible UI', async ({
153 page,
154 testId,
155 aimockPort,
156}) => {
157 await page.goto(devtoolsUrl('/devtools-generation-hooks', testId, aimockPort))
158 await waitForDevtoolsHarness(page)
159 await page.getByTestId('run-useGenerateImage').click()
160 await expect(
161 generationCard(page, 'useGenerateImage').getByTestId(
162 'generation-hook-status',
163 ),
164 ).toHaveText('success')
165
166 await openDevtools(page)
167 await selectHook(page, 'Image Studio')
168 await expectClassChangesOnHover(
169 page.getByTestId('ai-devtools-generation-run').first(),
170 page.getByTestId('ai-devtools-generation-output').first(),
171 )
172 await expectClassChangesOnHover(
173 page.getByTestId('ai-devtools-generation-output').first(),
174 page.getByTestId('ai-devtools-generation-run').first(),
175 )
176
177 await page.getByTestId('ai-devtools-generation-output').first().click()
178 await expect(page.getByTestId('ai-devtools-output-modal')).toBeVisible()
179 const backdropBox = await page
180 .getByTestId('ai-devtools-output-modal-backdrop')
181 .boundingBox()
182 expect(backdropBox?.width).toBeGreaterThan(500)
183 expect(backdropBox?.height).toBeGreaterThan(500)
184 await expect(
185 page.getByTestId('ai-devtools-image-output').last(),
186 ).toBeVisible()
187 await page.getByTestId('ai-devtools-output-modal').click()
188 await expect(page.getByTestId('ai-devtools-output-modal')).toBeVisible()
189 await page.keyboard.press('Escape')
190 await expect(page.getByTestId('ai-devtools-output-modal')).toHaveCount(0)
191
192 await page.getByTestId('ai-devtools-generation-output').first().click()
193 await page.getByTestId('ai-devtools-output-modal-close').click()
194 await expect(page.getByTestId('ai-devtools-output-modal')).toHaveCount(0)
195
196 await page.getByTestId('ai-devtools-generation-output').first().click()
197 await page
198 .getByTestId('ai-devtools-output-modal-backdrop')
199 .click({ position: { x: 4, y: 4 } })
200 await expect(page.getByTestId('ai-devtools-output-modal')).toHaveCount(0)
201
202 await page.getByTestId('reset-useGenerateImage').click()
203 await expect(
204 generationCard(page, 'useGenerateImage').getByTestId(
205 'generation-hook-output-count',
206 ),
207 ).toHaveText('0')
208 await expect(page.getByTestId('ai-devtools-generation-run')).toHaveCount(0)
209 await expect(page.getByTestId('ai-devtools-preview-pane')).toContainText(
210 'No output yet.',
211 )
212})