Skip to content

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

TypeScript

fix(test): r4-h1 own opened fixture handles immediately

Josué0f2a799137f7
diff --git a/tests/e2e/gfsUploadV2FixtureLease.ts b/tests/e2e/gfsUploadV2FixtureLease.ts
index 12ecb382c..c37b82fb5 100644
--- a/tests/e2e/gfsUploadV2FixtureLease.ts
+++ b/tests/e2e/gfsUploadV2FixtureLease.ts
@@ -32,15 +32,25 @@ export function registerFixtureLeaseForTest(
fixture: FixtureLeaseTarget,
handle: FileHandle
): FixtureHandle {
- const ownedHandle = fixtureHandleForTest?.(handle, fixture) ?? handle
- fixtureLeases.set(fixture, {
- handle: ownedHandle,
+ const lease: FixtureLease = {
+ handle,
state: 'active',
neutralized: false,
- })
+ }
+ fixtureLeases.set(fixture, lease)
+ const ownedHandle = fixtureHandleForTest?.(handle, fixture) ?? handle
+ lease.handle = ownedHandle
return ownedHandle
}
+export async function closeUnregisteredFixtureHandleForTest(handle: FileHandle): Promise<void> {
+ await handle.close()
+}
+
+export function hasFixtureLeaseForTest(fixture: FixtureLeaseTarget): boolean {
+ return fixtureLeases.has(fixture)
+}
+
export async function disposeFixtureLeaseForTest(fixture: FixtureLeaseTarget): Promise<void> {
const lease = fixtureLeases.get(fixture)
if (!lease) {
diff --git a/tests/e2e/gfsUploadV2Fixtures.test.ts b/tests/e2e/gfsUploadV2Fixtures.test.ts
index 8bb51759d..5a63fe29d 100644
--- a/tests/e2e/gfsUploadV2Fixtures.test.ts
+++ b/tests/e2e/gfsUploadV2Fixtures.test.ts
@@ -125,6 +125,99 @@ describe('GFS Upload v2 disk fixtures', () => {
await removeKnownFixtureDirectory(created[0]!, ['partial-handle-1.bin'])
})
+ it('closes the raw opened handle when wrapper construction fails', async () => {
+ const before = await fixtureDirectories()
+ const wrapperFailure = new Error('synthetic fixture wrapper failure')
+ let rawHandle: FileHandle | undefined
+ setFixtureHandleForTest(handle => {
+ rawHandle = handle
+ throw wrapperFailure
+ })
+
+ await expect(createDiskUploadFixture(1, '.bin', 'partial-wrapper')).rejects.toBe(wrapperFailure)
+
+ expect(rawHandle).toBeDefined()
+ await expect(rawHandle!.stat()).rejects.toThrow()
+ const created = (await fixtureDirectories()).filter(directory => !before.includes(directory))
+ expect(created).toHaveLength(1)
+ const partialFile = path.join(created[0]!, 'partial-wrapper-1.bin')
+ expect((await stat(partialFile)).size).toBe(0)
+ await removeKnownFixtureDirectory(created[0]!, ['partial-wrapper-1.bin'])
+ })
+
+ it('closes the retained handle when the after-handle setup hook fails', async () => {
+ const before = await fixtureDirectories()
+ const setupFailure = new Error('synthetic setup hook failure')
+ let rawHandle: FileHandle | undefined
+ setFixtureHandleForTest(handle => {
+ rawHandle = handle
+ return {
+ async truncate(length: number): Promise<void> {
+ await handle.truncate(length)
+ },
+ async close(): Promise<void> {
+ await handle.close()
+ },
+ }
+ })
+ setAfterFixtureHandleForTest?.(() => {
+ throw setupFailure
+ })
+
+ await expect(createDiskUploadFixture(1, '.bin', 'partial-hook')).rejects.toBe(setupFailure)
+
+ expect(rawHandle).toBeDefined()
+ await expect(rawHandle!.stat()).rejects.toThrow()
+ const created = (await fixtureDirectories()).filter(directory => !before.includes(directory))
+ expect(created).toHaveLength(1)
+ await removeKnownFixtureDirectory(created[0]!, ['partial-hook-1.bin'])
+ })
+
+ it('closes the retained handle when hashing fails after setup', async () => {
+ const before = await fixtureDirectories()
+ let rawHandle: FileHandle | undefined
+ let retainedPath = ''
+ setFixtureHandleForTest(handle => {
+ rawHandle = handle
+ return {
+ async truncate(length: number): Promise<void> {
+ await handle.truncate(length)
+ },
+ async close(): Promise<void> {
+ await handle.close()
+ },
+ }
+ })
+ setAfterFixtureHandleForTest?.(async fixture => {
+ retainedPath = `${fixture.filePath}-retained`
+ await rename(fixture.filePath, retainedPath)
+ })
+
+ await expect(createDiskUploadFixture(1, '.bin', 'partial-hash')).rejects.toMatchObject({
+ code: 'ENOENT',
+ })
+
+ expect(rawHandle).toBeDefined()
+ await expect(rawHandle!.stat()).rejects.toThrow()
+ expect((await stat(retainedPath)).size).toBe(0)
+ const created = (await fixtureDirectories()).filter(directory => !before.includes(directory))
+ expect(created).toHaveLength(1)
+ await removeKnownFixtureDirectory(created[0]!, ['partial-hash-1.bin-retained'])
+ })
+
+ it('uses exactly one disposal surface after a successful wrapper transition', async () => {
+ const calls = useScriptedFixtureHandle({})
+ const fixture = await createDiskUploadFixture(1, '.bin', 'cleanup-wrapper-transition')
+
+ try {
+ await removeDiskUploadFixture(fixture)
+ await expect(removeDiskUploadFixture(fixture)).resolves.toBeUndefined()
+ expect(calls).toEqual({ truncate: 2, close: 1 })
+ } finally {
+ await removeKnownFixtureDirectory(fixture.directory, [fixture.fileName])
+ }
+ })
+
it('rejects a fabricated fixture object with copied pathname data', async () => {
const fixture = await createDiskUploadFixture(32, '.bin', 'cleanup-fabricated')
const fabricated = { ...fixture }
diff --git a/tests/e2e/gfsUploadV2Fixtures.ts b/tests/e2e/gfsUploadV2Fixtures.ts
index 68d22956a..e66a3325b 100644
--- a/tests/e2e/gfsUploadV2Fixtures.ts
+++ b/tests/e2e/gfsUploadV2Fixtures.ts
@@ -4,7 +4,9 @@ import { mkdtemp, open } from 'node:fs/promises'
import os from 'node:os'
import path from 'node:path'
import {
+ closeUnregisteredFixtureHandleForTest,
disposeFixtureLeaseForTest,
+ hasFixtureLeaseForTest,
registerFixtureLeaseForTest,
setFixtureHandleForTest,
} from './gfsUploadV2FixtureLease.js'
@@ -85,8 +87,9 @@ async function createFixture(
const fileName = `${label}-${byteLength}${extension}`
const filePath = path.join(directory, fileName)
let fixture: DiskUploadFixture | undefined
+ let handle: Awaited<ReturnType<typeof open>> | undefined
try {
- const handle = await open(
+ handle = await open(
filePath,
constants.O_CREAT | constants.O_EXCL | constants.O_RDWR | constants.O_NOFOLLOW,
0o600
@@ -104,7 +107,7 @@ async function createFixture(
fixture.sha256 = await sha256File(filePath)
return fixture
} catch (error) {
- if (fixture) {
+ if (fixture && hasFixtureLeaseForTest(fixture)) {
try {
await disposeFixtureLeaseForTest(fixture)
} catch (cleanupError) {
@@ -113,6 +116,15 @@ async function createFixture(
'failed to neutralize partial GFS v2 fixture'
)
}
+ } else if (handle) {
+ try {
+ await closeUnregisteredFixtureHandleForTest(handle)
+ } catch (cleanupError) {
+ throw new AggregateError(
+ [error, cleanupError],
+ 'failed to close unregistered GFS v2 fixture handle'
+ )
+ }
}
throw error
}
diff --git a/tests/e2e/package-lock.json b/tests/e2e/package-lock.json
index 9dcc26ff6..dc83acae0 100644
--- a/tests/e2e/package-lock.json
+++ b/tests/e2e/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-e2e-tests",
- "version": "0.1.74",
+ "version": "0.1.75",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-e2e-tests",
- "version": "0.1.74",
+ "version": "0.1.75",
"devDependencies": {
"@types/jsonwebtoken": "^9.0.10",
"@types/node": "^22.0.0",
diff --git a/tests/e2e/package.json b/tests/e2e/package.json
index 8ed74e91e..6a2a745a0 100644
--- a/tests/e2e/package.json
+++ b/tests/e2e/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-e2e-tests",
- "version": "0.1.74",
+ "version": "0.1.75",
"private": true,
"type": "module",
"scripts": {