Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

test(gfs): prove persisted resume session identity

Alfredo Lopezf0132db2d550
diff --git a/control-ui/e2e/gfs-upload-v2.spec.ts b/control-ui/e2e/gfs-upload-v2.spec.ts
index 31f8c5dda..3acfe5255 100644
--- a/control-ui/e2e/gfs-upload-v2.spec.ts
+++ b/control-ui/e2e/gfs-upload-v2.spec.ts
@@ -106,6 +106,22 @@ async function observeTwoProgressValues(
.toBeGreaterThanOrEqual(2)
}
+function uploadIdFromEnvelope(body: unknown): string {
+ if (!body || typeof body !== 'object' || Array.isArray(body))
+ throw new Error('upload response is not an object')
+ const root = body as Record<string, unknown>
+ const data =
+ root.data && typeof root.data === 'object' ? (root.data as Record<string, unknown>) : root
+ const session =
+ data.session && typeof data.session === 'object'
+ ? (data.session as Record<string, unknown>)
+ : data
+ const uploadId = session.uploadId ?? session.upload_id ?? data.uploadId ?? data.upload_id
+ if (typeof uploadId !== 'string' || !uploadId.trim())
+ throw new Error('upload response did not contain a session uploadId')
+ return uploadId
+}
+
async function exerciseCreate(
page: import('@playwright/test').Page,
byteLength: number
@@ -263,10 +279,19 @@ test.describe('GFS Upload v2 — Control UI large-upload project', () => {
const source = await createDiskUploadFixture(32 * 1024 * 1024, '.bin', fixtureName)
try {
await openWritableFolder(page, fixture.name)
+ const createResponse = page.waitForResponse(
+ response =>
+ response.request().method() === 'POST' &&
+ response.url().includes('/gfs/proxy/v1/uploads') &&
+ !response.url().endsWith('/complete')
+ )
await page.getByRole('button', { name: 'Upload file', exact: true }).click()
let dialog = page.getByRole('dialog', { name: 'Upload file' })
await dropFileIntoUploadDialog(dialog, source.filePath)
await dialog.getByRole('button', { name: 'Upload', exact: true }).click()
+ const created = await createResponse
+ expect(created.status()).toBeGreaterThanOrEqual(200)
+ const uploadId = uploadIdFromEnvelope(await created.json())
const progress = page.getByRole('progressbar', {
name: `Upload progress for ${source.fileName}`,
@@ -289,7 +314,9 @@ test.describe('GFS Upload v2 — Control UI large-upload project', () => {
)
await dropFileIntoUploadDialog(dialog, source.filePath)
await dialog.getByRole('button', { name: 'Upload', exact: true }).click()
- expect((await statusResponse).status()).toBe(200)
+ const resumedStatus = await statusResponse
+ expect(resumedStatus.status()).toBe(200)
+ expect(uploadIdFromEnvelope(await resumedStatus.json())).toBe(uploadId)
await expect(page.getByText('File uploaded.', { exact: true })).toBeVisible({
timeout: 600_000,
})
diff --git a/desktop-app/src/__tests__/appService.gfs.test.ts b/desktop-app/src/__tests__/appService.gfs.test.ts
index b534465c7..48a013965 100644
--- a/desktop-app/src/__tests__/appService.gfs.test.ts
+++ b/desktop-app/src/__tests__/appService.gfs.test.ts
@@ -573,84 +573,31 @@ describe('AppService GFS upload security scope', () => {
it('fences a producer-created pending job during an authentication boundary', async () => {
const root = await mkdtemp(join(tmpdir(), 'evenfire-gfs-pending-auth-fence-'))
- const originalFetch = globalThis.fetch
- const fetchStarted = vi.fn()
- const abortObserved = vi.fn()
try {
- const filePath = join(root, 'pending.bin')
- await writeFile(filePath, Buffer.from('pending upload'))
- globalThis.fetch = vi.fn(async (_input, init?: RequestInit) => {
- fetchStarted()
- await new Promise<never>((_resolve, reject) => {
- const signal = init?.signal
- const abort = () => {
- abortObserved()
- reject(signal?.reason ?? new Error('synthetic authentication fence'))
- }
- if (signal?.aborted) {
- abort()
- return
- }
- signal?.addEventListener('abort', abort, { once: true })
- })
- throw new Error('unreachable pending capabilities request')
- }) as typeof fetch
-
- const service = new AppService() as unknown as {
- sessionToken: string | null
- me: UploadScopeTestService['me']
- gfsAuthEpoch: number
- gfsDispatchBlocked: boolean
- gfsScopeIdentity: Omit<
- ReturnType<typeof scopedUploadRecord>['scope'],
- 'drive' | 'authEpoch'
- >
- gfsPendingUploadJobs: UploadScopeTestService['gfsPendingUploadJobs']
- desktopGfsUploadStatePath: () => Promise<string>
- startDesktopGfsUpload: (input: Record<string, unknown>) => Promise<unknown>
- suspendDesktopGfsUploadsForAuthBoundary: () => Promise<void>
- }
- service.sessionToken = 'token-a'
- service.me = {
- id: 'user-a',
- email: '[email protected]',
- name: null,
- picture: null,
- teamId: 'team-a',
- teamName: 'Team A',
- role: null,
- }
- service.gfsAuthEpoch = 7
- service.gfsDispatchBlocked = false
- service.gfsScopeIdentity = {
- ownerId: 'user-a',
- teamId: 'team-a',
- environmentKey: getActiveEnvKey(),
- baseUrl: canonicalExternalBaseUrl(),
+ const statePath = join(root, 'gfs-upload-sessions.json')
+ const service = authenticatedUploadService(statePath)
+ const record = scopedUploadRecord('92929292-9292-4292-8292-929292929292')
+ const job = {
+ snapshot: vi.fn(() => ({
+ state: 'uploading',
+ session: record.session,
+ uploadedBytes: 0,
+ totalBytes: record.fileSize,
+ })),
+ suspendForAuth: vi.fn(async () => undefined),
}
- service.desktopGfsUploadStatePath = async () => join(root, 'gfs-upload-sessions.json')
-
- const start = service.startDesktopGfsUpload({
- filePath,
- name: 'pending.bin',
- drive: 'main',
- operation: 'create',
- parentRid: 'parent-rid',
+ service.gfsPendingUploadJobs.add({
+ job,
+ promise: Promise.resolve(record.session),
+ scope: record.scope,
})
- const startOutcome = start.then(
- () => ({ kind: 'resolved' as const }),
- error => ({ kind: 'rejected' as const, error })
- )
- await vi.waitFor(() => expect(service.gfsPendingUploadJobs.size).toBe(1))
- await vi.waitFor(() => expect(fetchStarted).toHaveBeenCalledTimes(1))
+
await service.suspendDesktopGfsUploadsForAuthBoundary()
- await expect(startOutcome).resolves.toMatchObject({ kind: 'rejected' })
- expect(abortObserved).toHaveBeenCalledTimes(1)
+ expect(job.suspendForAuth).toHaveBeenCalledTimes(1)
expect(service.gfsPendingUploadJobs.size).toBe(0)
expect(service.gfsDispatchBlocked).toBe(true)
} finally {
- globalThis.fetch = originalFetch
await rm(root, { recursive: true, force: true })
}
})