Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(e2e): harden Upload v2 fixture cleanup
Josué4afbd17a7f32
diff --git a/gfs-controller/src/upload/uploadSession.test.ts b/gfs-controller/src/upload/uploadSession.test.tsindex 331079950..6a2e78b5b 100644--- a/gfs-controller/src/upload/uploadSession.test.ts+++ b/gfs-controller/src/upload/uploadSession.test.ts@@ -611,9 +611,9 @@ describe('GfsUploadSessionService', () => {['100 MiB', 100 * 1024 * 1024],['250 MiB', 250 * 1024 * 1024],['300 MiB', 300 * 1024 * 1024],- ['the protocol maximum', 1024 * 1024 * 1024],+ ['the maximum supported product policy', 1024 * 1024 * 1024],] as const)(- 'advertises and enforces the configured %s product limit before allocation',+ 'advertises and enforces the configured %s before allocation',async (_label, productMaxFileBytes) => {tempRoot = await mkdtemp(join(tmpdir(), 'gfsc-upload-runtime-boundary-'))const config = { ...CONFIG, productMaxFileBytes }diff --git a/tests/e2e/gfsUploadV2Fixtures.test.ts b/tests/e2e/gfsUploadV2Fixtures.test.tsnew file mode 100644index 000000000..ac0589517--- /dev/null+++ b/tests/e2e/gfsUploadV2Fixtures.test.ts@@ -0,0 +1,66 @@+import { afterEach, describe, expect, it } from 'vitest'+import { existsSync } from 'node:fs'+import { mkdtemp, readdir, rm, stat } from 'node:fs/promises'+import os from 'node:os'+import path from 'node:path'+import {+ createDiskUploadFixture,+ createOversizedDiskUploadFixture,+ removeDiskUploadFixture,+} from './gfsUploadV2Fixtures.js'++const fixturePrefix = 'evenfire-gfs-upload-v2-'++async function fixtureDirectories(): Promise<string[]> {+ return (await readdir(os.tmpdir())).filter(entry => entry.startsWith(fixturePrefix)).sort()+}++describe('GFS Upload v2 disk fixtures', () => {+ const fixtures: Array<Awaited<ReturnType<typeof createDiskUploadFixture>>> = []+ const ownedDirectories: string[] = []++ afterEach(async () => {+ for (const fixture of fixtures.splice(0)) {+ if (existsSync(fixture.directory)) await removeDiskUploadFixture(fixture)+ }+ await Promise.all(+ ownedDirectories.splice(0).map(directory => rm(directory, { recursive: true, force: true }))+ )+ })++ it('removes an owned fixture after a successful setup', async () => {+ const fixture = await createDiskUploadFixture(1, '.bin', 'cleanup-success')+ expect((await stat(fixture.filePath)).size).toBe(1)+ await removeDiskUploadFixture(fixture)+ expect(existsSync(fixture.directory)).toBe(false)+ })++ it('cleans an owned directory when fixture setup fails part-way through', async () => {+ const before = await fixtureDirectories()+ await expect(createDiskUploadFixture(1, '.bin', 'nested/partial')).rejects.toThrow()+ expect(await fixtureDirectories()).toEqual(before)+ })++ it('refuses to delete a directory the fixture did not create', async () => {+ const directory = await mkdtemp(path.join(os.tmpdir(), 'unowned-gfs-upload-v2-'))+ ownedDirectories.push(directory)+ await expect(+ removeDiskUploadFixture({+ directory,+ filePath: path.join(directory, 'payload.bin'),+ fileName: 'payload.bin',+ byteLength: 0,+ sha256: '',+ })+ ).rejects.toThrow('refusing to remove an unowned GFS v2 fixture directory')+ expect(existsSync(directory)).toBe(true)+ })++ it('validates before creating a fixture directory', async () => {+ const before = await fixtureDirectories()+ await expect(createOversizedDiskUploadFixture('.bin', 'invalid-product', 0)).rejects.toThrow(+ 'invalid GFS v2 product maximum: 0'+ )+ expect(await fixtureDirectories()).toEqual(before)+ })+})diff --git a/tests/e2e/gfsUploadV2Fixtures.ts b/tests/e2e/gfsUploadV2Fixtures.tsindex db44f97bd..7a440f132 100644--- a/tests/e2e/gfsUploadV2Fixtures.ts+++ b/tests/e2e/gfsUploadV2Fixtures.ts@@ -4,11 +4,14 @@ import { mkdtemp, rm, truncate, writeFile } from 'node:fs/promises'import os from 'node:os'import path from 'node:path'-export const GFS_UPLOAD_V2_DEFAULT_PRODUCT_MAX_BYTES = 209_715_200+/** Test-only default for runtime Upload v2 journeys; GFSC remains the product-policy authority. */+export const E2E_GFS_UPLOAD_V2_DEFAULT_PRODUCT_MAX_BYTES = 209_715_200+/** @deprecated Use E2E_GFS_UPLOAD_V2_DEFAULT_PRODUCT_MAX_BYTES in new test plumbing. */+export const GFS_UPLOAD_V2_DEFAULT_PRODUCT_MAX_BYTES = E2E_GFS_UPLOAD_V2_DEFAULT_PRODUCT_MAX_BYTESexport const GFS_UPLOAD_V2_PROTOCOL_MAX_BYTES = 1_073_741_824export const GFS_UPLOAD_V2_BOUNDARIES = [- GFS_UPLOAD_V2_DEFAULT_PRODUCT_MAX_BYTES - 1,- GFS_UPLOAD_V2_DEFAULT_PRODUCT_MAX_BYTES,+ E2E_GFS_UPLOAD_V2_DEFAULT_PRODUCT_MAX_BYTES - 1,+ E2E_GFS_UPLOAD_V2_DEFAULT_PRODUCT_MAX_BYTES,] as constexport interface DiskUploadFixture {@@ -19,6 +22,8 @@ export interface DiskUploadFixture {sha256: string}+const ownedFixtureDirectories = new Set<string>()+/*** Creates a deterministic sparse, zero-filled fixture on disk. Playwright* receives only the path, never a 200 MiB Buffer or ArrayBuffer.@@ -35,18 +40,7 @@ export async function createDiskUploadFixture() {throw new Error(`invalid GFS v2 fixture size: ${byteLength}`)}- const directory = await mkdtemp(path.join(os.tmpdir(), 'evenfire-gfs-upload-v2-'))- const fileName = `${label}-${byteLength}${extension}`- const filePath = path.join(directory, fileName)- await writeFile(filePath, Buffer.alloc(0))- await truncate(filePath, byteLength)- return {- directory,- filePath,- fileName,- byteLength,- sha256: await sha256File(filePath),- }+ return createFixture(byteLength, extension, label)}/**@@ -56,7 +50,7 @@ export async function createDiskUploadFixture(export async function createOversizedDiskUploadFixture(extension = '.parquet',label = 'gfs-v2-oversize',- productMaxBytes = GFS_UPLOAD_V2_DEFAULT_PRODUCT_MAX_BYTES+ productMaxBytes = E2E_GFS_UPLOAD_V2_DEFAULT_PRODUCT_MAX_BYTES): Promise<DiskUploadFixture> {if (!Number.isSafeInteger(productMaxBytes) ||@@ -65,18 +59,35 @@ export async function createOversizedDiskUploadFixture() {throw new Error(`invalid GFS v2 product maximum: ${productMaxBytes}`)}- const byteLength = productMaxBytes + 1+ return createFixture(productMaxBytes + 1, extension, label)+}++async function createFixture(+ byteLength: number,+ extension: string,+ label: string+): Promise<DiskUploadFixture> {const directory = await mkdtemp(path.join(os.tmpdir(), 'evenfire-gfs-upload-v2-'))+ ownedFixtureDirectories.add(directory)const fileName = `${label}-${byteLength}${extension}`const filePath = path.join(directory, fileName)- await writeFile(filePath, Buffer.alloc(0))- await truncate(filePath, byteLength)- return {- directory,- filePath,- fileName,- byteLength,- sha256: await sha256File(filePath),+ try {+ await writeFile(filePath, Buffer.alloc(0))+ await truncate(filePath, byteLength)+ return {+ directory,+ filePath,+ fileName,+ byteLength,+ sha256: await sha256File(filePath),+ }+ } catch (error) {+ try {+ await removeOwnedFixtureDirectory(directory)+ } catch (cleanupError) {+ throw new AggregateError([error, cleanupError], 'failed to clean partial GFS v2 fixture')+ }+ throw error}}@@ -87,5 +98,13 @@ export async function sha256File(filePath: string): Promise<string> {}export async function removeDiskUploadFixture(fixture: DiskUploadFixture): Promise<void> {- await rm(fixture.directory, { recursive: true, force: true })+ await removeOwnedFixtureDirectory(fixture.directory)+}++async function removeOwnedFixtureDirectory(directory: string): Promise<void> {+ if (!ownedFixtureDirectories.has(directory)) {+ throw new Error(`refusing to remove an unowned GFS v2 fixture directory: ${directory}`)+ }+ await rm(directory, { recursive: true, force: true })+ ownedFixtureDirectories.delete(directory)}diff --git a/tests/e2e/package-lock.json b/tests/e2e/package-lock.jsonindex 2b05ec0ef..5d46fa2b3 100644--- a/tests/e2e/package-lock.json+++ b/tests/e2e/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-e2e-tests",- "version": "0.1.69",+ "version": "0.1.70","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-e2e-tests",- "version": "0.1.69",+ "version": "0.1.70","devDependencies": {"@types/jsonwebtoken": "^9.0.10","@types/node": "^22.0.0",diff --git a/tests/e2e/package.json b/tests/e2e/package.jsonindex 9f389a828..ba921241d 100644--- a/tests/e2e/package.json+++ b/tests/e2e/package.json@@ -1,6 +1,6 @@{"name": "clerum-e2e-tests",- "version": "0.1.69",+ "version": "0.1.70","private": true,"type": "module","scripts": {