Open History to see the last commit
1import { expect, test } from '@playwright/test'
2
3/**
4 * Server-side sandbox instance durability.
5 *
6 * Two independent runs (separate HTTP requests → fresh middleware contexts) for
7 * the same thread. Shared state is only the harness route's module-singleton
8 * `SandboxInstanceStore` passed to `withSandbox`, plus `withLocks`. The
9 * second run must RESUME the sandbox the first created.
10 *
11 * Provider-free (fixed AG-UI stream + fake sandbox provider); exempt from aimock.
12 */
13interface DurabilityResult {
14 create: number
15 resume: number
16 providerSandboxId: string | null
17 latestRunId: string | null
18}
19
20test.describe('sandbox instance durability (server-side resume)', () => {
21 test('a second run resumes the persisted sandbox instead of creating a new one', async ({
22 request,
23 }) => {
24 const threadId = `sandbox-durability-${Date.now()}`
25
26 const first = await request.post('/api/sandbox-durability', {
27 data: { threadId, runId: 'run-1' },
28 })
29 expect(first.ok()).toBe(true)
30 const firstBody = (await first.json()) as DurabilityResult
31 expect(firstBody.create).toBe(1)
32 expect(firstBody.resume).toBe(0)
33 expect(firstBody.providerSandboxId).not.toBeNull()
34
35 const second = await request.post('/api/sandbox-durability', {
36 data: { threadId, runId: 'run-2' },
37 })
38 expect(second.ok()).toBe(true)
39 const secondBody = (await second.json()) as DurabilityResult
40
41 expect(secondBody.create).toBe(1)
42 expect(secondBody.resume).toBe(1)
43 expect(secondBody.providerSandboxId).toBe(firstBody.providerSandboxId)
44 expect(secondBody.latestRunId).toBe('run-2')
45 })
46})