Skip to content

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

TypeScript

test(gfs): make recovery fixtures atomic and separate review decisions

Alfredo Lopez91cfc650a286
diff --git a/desktop-app/test/e2e-playwright/helpers/gfsApprovalReview.ts b/desktop-app/test/e2e-playwright/helpers/gfsApprovalReview.ts
index 5fedc73d2..7fae45aab 100644
--- a/desktop-app/test/e2e-playwright/helpers/gfsApprovalReview.ts
+++ b/desktop-app/test/e2e-playwright/helpers/gfsApprovalReview.ts
@@ -99,68 +99,50 @@ export async function createGfsApprovalReview(
if (snapshot) await Promise.all([snapshot.button.dispose(), snapshot.denyButton.dispose()])
}
- async function handleRequest(raw: Buffer): Promise<unknown> {
- if (raw.byteLength > MAX_REQUEST_BYTES) throw new Error('Review request exceeds byte bound')
- let request: unknown
- try {
- request = JSON.parse(raw.toString('utf8'))
- } catch {
- throw new Error('Invalid review request')
- }
- if (!request || typeof request !== 'object' || Array.isArray(request))
- throw new Error('Invalid review request')
- const { action, nonce } = request as Record<string, unknown>
- if (Object.keys(request).some(key => key !== 'action' && key !== 'nonce'))
- throw new Error('Unknown review request field')
- if (action === 'release') {
- if (!result || nonce !== undefined) throw new Error('No completed result to release')
- releaseResult?.()
- return { released: true, result }
- }
- if (action === 'view') {
- if (nonce !== undefined) throw new Error('Invalid view request')
- verifyOwnedPage()
- if (result) {
- return {
- state: 'result',
- result,
- binding,
- ...(resultResponse !== undefined ? { response: resultResponse } : {}),
- }
- }
- if (!active) return { state: 'preparing', binding }
- if (deciding) return { state: 'deciding', binding }
- const current = await visibleApproval()
- if (!current) {
- await disposeButtons(pending)
- pending = undefined
- return { state: 'running', binding }
- }
- if (
- !pending ||
- pending.command !== current.command ||
- Date.now() >= pending.expiresAt ||
- !(await sameButton(pending.button, current.button)) ||
- !(await sameButton(pending.denyButton, current.denyButton))
- ) {
- await disposeButtons(pending)
- pending = {
- nonce: randomUUID(),
- command: current.command,
- button: current.button,
- denyButton: current.denyButton,
- expiresAt: Date.now() + requestTimeoutMs,
- }
- } else await disposeButtons(current)
+ async function inspectReview(): Promise<unknown> {
+ verifyOwnedPage()
+ if (result) {
return {
- state: 'waiting_approval',
+ state: 'result',
+ result,
binding,
- nonce: pending.nonce,
- command: pending.command,
- expiresAt: pending.expiresAt,
+ ...(resultResponse !== undefined ? { response: resultResponse } : {}),
+ }
+ }
+ if (!active) return { state: 'preparing', binding }
+ if (deciding) return { state: 'deciding', binding }
+ const current = await visibleApproval()
+ if (!current) {
+ await disposeButtons(pending)
+ pending = undefined
+ return { state: 'running', binding }
+ }
+ if (
+ !pending ||
+ pending.command !== current.command ||
+ Date.now() >= pending.expiresAt ||
+ !(await sameButton(pending.button, current.button)) ||
+ !(await sameButton(pending.denyButton, current.denyButton))
+ ) {
+ await disposeButtons(pending)
+ pending = {
+ nonce: randomUUID(),
+ command: current.command,
+ button: current.button,
+ denyButton: current.denyButton,
+ expiresAt: Date.now() + requestTimeoutMs,
}
+ } else await disposeButtons(current)
+ return {
+ state: 'waiting_approval',
+ binding,
+ nonce: pending.nonce,
+ command: pending.command,
+ expiresAt: pending.expiresAt,
}
- if (action !== 'approve' && action !== 'deny') throw new Error('Invalid review decision')
+ }
+
+ async function decideReview(action: 'approve' | 'deny', nonce: unknown): Promise<unknown> {
if (
!active ||
result ||
@@ -200,6 +182,38 @@ export async function createGfsApprovalReview(
}
}
+ async function handleRequest(raw: Buffer): Promise<unknown> {
+ if (raw.byteLength > MAX_REQUEST_BYTES) throw new Error('Review request exceeds byte bound')
+ let request: unknown
+ try {
+ request = JSON.parse(raw.toString('utf8'))
+ } catch {
+ throw new Error('Invalid review request')
+ }
+ if (!request || typeof request !== 'object' || Array.isArray(request))
+ throw new Error('Invalid review request')
+ const { action, nonce } = request as Record<string, unknown>
+ if (Object.keys(request).some(key => key !== 'action' && key !== 'nonce'))
+ throw new Error('Unknown review request field')
+ // Each fixed route owns its checks. Selecting an observation route cannot
+ // skip the nonce, deadline, binding or DOM checks in the decision route.
+ switch (action) {
+ case 'release':
+ if (!result || nonce !== undefined) throw new Error('No completed result to release')
+ releaseResult?.()
+ return { released: true, result }
+ case 'view':
+ if (nonce !== undefined) throw new Error('Invalid view request')
+ return inspectReview()
+ case 'approve':
+ return decideReview('approve', nonce)
+ case 'deny':
+ return decideReview('deny', nonce)
+ default:
+ throw new Error('Invalid review decision')
+ }
+ }
+
const server = createServer(socket => {
sockets.add(socket)
socket.on('close', () => sockets.delete(socket))
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.json
index 8549293fa..5e766e243 100644
--- a/mcp-host/package-lock.json
+++ b/mcp-host/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.494",
+ "version": "0.1.495",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-mcp-host",
- "version": "0.1.494",
+ "version": "0.1.495",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@anthropic-ai/sdk": "^0.32.0",
diff --git a/mcp-host/package.json b/mcp-host/package.json
index 0076aed62..17741ccc8 100644
--- a/mcp-host/package.json
+++ b/mcp-host/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.494",
+ "version": "0.1.495",
"description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude",
"main": "dist/main.js",
"engines": {
diff --git a/mcp-host/src/internalTools/gfsDownloadStoreRecovery.test.ts b/mcp-host/src/internalTools/gfsDownloadStoreRecovery.test.ts
index 1aca7b011..cf13f3cfa 100644
--- a/mcp-host/src/internalTools/gfsDownloadStoreRecovery.test.ts
+++ b/mcp-host/src/internalTools/gfsDownloadStoreRecovery.test.ts
@@ -3,6 +3,7 @@ import { type ChildProcess, spawn } from 'node:child_process'
import { createHash } from 'node:crypto'
import { constants } from 'node:fs'
import * as fs from 'node:fs/promises'
+import type { FileHandle } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import * as path from 'node:path'
import type { GfsImageSource } from '../visualInput/policy'
@@ -445,7 +446,12 @@ describe('GFS writer recovery and filesystem invariants', () => {
await fs.rename(databasePath, `${databasePath}.old`)
await expect(freshStore().initialize()).rejects.toMatchObject({ code: 'workspace_unavailable' })
await expect(fs.stat(databasePath)).rejects.toMatchObject({ code: 'ENOENT' })
- await fs.writeFile(databasePath, '', { mode: 0o600 })
+ let replacementDatabase: FileHandle | undefined
+ try {
+ replacementDatabase = await fs.open(databasePath, 'wx', 0o600)
+ } finally {
+ await replacementDatabase?.close()
+ }
await expect(freshStore().initialize()).rejects.toMatchObject({ code: 'writer_locked' })
})
diff --git a/mcp-host/src/internalTools/gfsStoreOperatorRecovery.test.ts b/mcp-host/src/internalTools/gfsStoreOperatorRecovery.test.ts
index 63d9c4541..8159e9855 100644
--- a/mcp-host/src/internalTools/gfsStoreOperatorRecovery.test.ts
+++ b/mcp-host/src/internalTools/gfsStoreOperatorRecovery.test.ts
@@ -1,7 +1,7 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { createHash } from 'node:crypto'
-import { constants } from 'node:fs'
import * as fs from 'node:fs/promises'
+import type { FileHandle } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import * as path from 'node:path'
import { GfsDownloadStore } from './gfsDownloadStore'
@@ -83,6 +83,18 @@ async function simulateWriterDeath(store: GfsDownloadStore) {
// the actual kernel connection to model loss of the old Host process.
await (store as unknown as { writerLease: { release(): Promise<void> } }).writerLease.release()
}
+
+async function expectPrivateExclusiveCreateToFail(target: string): Promise<void> {
+ let unexpectedHandle: FileHandle | undefined
+ try {
+ await expect(async () => {
+ unexpectedHandle = await fs.open(target, 'wx', 0o600)
+ }).rejects.toMatchObject({ code: 'EEXIST' })
+ } finally {
+ await unexpectedHandle?.close()
+ }
+}
+
async function legacyCopy() {
const store = fresh()
await store.initialize()
@@ -128,9 +140,7 @@ describe('local GFS operator recovery', () => {
expect(outcome.before.counts).toMatchObject({ files: 1, bytes: 7 })
expect(outcome.after.counts).toMatchObject({ files: 1, bytes: 7 })
expect((await fs.stat(markerPath)).ino).toBe(markerBefore.ino)
- await expect(
- fs.open(markerPath, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL)
- ).rejects.toMatchObject({ code: 'EEXIST' })
+ await expectPrivateExclusiveCreateToFail(markerPath)
const reopened = fresh()
await reopened.initialize()
expect(await reopened.reusableReceipt('caller-a', source, 7)).toMatchObject({
@@ -257,9 +267,7 @@ describe('local GFS operator recovery', () => {
const databasePath = path.join(root, '.gfs-download-store', 'writer-v2.sqlite')
const databaseBefore = await fs.stat(databasePath)
expect((await fs.stat(markerPath)).size).toBe(0)
- await expect(
- fs.open(markerPath, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL)
- ).rejects.toMatchObject({ code: 'EEXIST' })
+ await expectPrivateExclusiveCreateToFail(markerPath)
expect(await fs.readFile(path.join(callerRoot, receipt.path), 'utf8')).toBe('fixture')
const retried = await recoverGfsStoreUnderPhysicalFence(await recoveryInput())
expect(retried.after.counts).toMatchObject({ files: 1, bytes: 7 })