Open History to see the last commit
1import { expect, test } from '@playwright/test'
2
3/**
4 * Server-driven generation persistence (`persistence: true`).
5 *
6 * The counterpart to `generation-persistence.spec.ts` (client-driven). Here the
7 * hook keeps NO local store: as a run streams the server records the job, and on
8 * mount / after a full `page.reload()` the client restores the last run FROM THE
9 * SERVER via a `?threadId=` GET (the `reconstructGeneration` shape) straight into
10 * the normal `result` / `status` fields. The restored image renders from the
11 * durable serve URL, `localStorage` stays empty, and no run is auto-started.
12 *
13 * Provider-free: `/api/generation-persistence-server` streams a fixed AG-UI
14 * sequence and answers the restore GET from an in-memory job record (exempt from
15 * the aimock policy).
16 */
17
18test.describe('generation persistence (server-driven)', () => {
19 test('records the run server-side and restores it after reload with no local store', async ({
20 page,
21 }) => {
22 await page.goto('/generation-persistence-server')
23 await expect(page.getByTestId('hydration-marker')).toBeAttached()
24 // Empty first load: the server has no job for this thread yet.
25 await expect(page.getByTestId('status')).toHaveText('idle')
26 await expect(page.getByTestId('result-id')).toHaveText('none')
27
28 await page.getByTestId('generate-button').click()
29 await expect(page.getByTestId('status')).toHaveText('success')
30 await expect(page.getByTestId('result-id')).toHaveText('image-1')
31 await expect(page.getByTestId('generated-image')).toHaveCount(1)
32
33 // Server-driven mode writes NOTHING to browser storage — the record lives
34 // on the server. No localStorage key mentions the generation id.
35 const localKeys = await page.evaluate(() =>
36 Object.keys(window.localStorage),
37 )
38 expect(localKeys.some((k) => k.includes('generation-server'))).toBe(false)
39
40 // Reload with empty client storage: the run is restored purely from the
41 // server, into the normal fields, and the image comes from the durable URL.
42 await page.reload()
43 await expect(page.getByTestId('hydration-marker')).toBeAttached()
44 await expect(page.getByTestId('status')).toHaveText('success')
45 await expect(page.getByTestId('result-id')).toHaveText('image-1')
46 await expect(page.getByTestId('generated-image')).toHaveCount(1)
47 await expect(page.getByTestId('generated-image')).toHaveAttribute(
48 'src',
49 '/durable/generation-server/image-1.png',
50 )
51 })
52})