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