Skip to content

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

TypeScript

test(desktop): require explicit per-command gfs review

Alfredo Lopez43835dd4984d
diff --git a/desktop-app/src/__tests__/gfsLargeFileCsvFixture.test.ts b/desktop-app/src/__tests__/gfsLargeFileCsvFixture.test.ts
index 7ec0cc34e..19947b87e 100644
--- a/desktop-app/src/__tests__/gfsLargeFileCsvFixture.test.ts
+++ b/desktop-app/src/__tests__/gfsLargeFileCsvFixture.test.ts
@@ -7,6 +7,7 @@ import {
GFS_OLD_VISUAL_LIMIT,
buildGfsLargeCsvFixture,
countMissingCsvColumns,
+ csvColumnCountClaims,
hasCsvDataRecordCount,
parseCsvMetadata,
resolveGfsLargeCsvFixture,
@@ -98,6 +99,32 @@ describe('large-file CSV fixture oracle', () => {
})
describe('large-file CSV summary assertions', () => {
+ it.each([
+ ['El archivo tiene 78 columnas.', [78]],
+ ['Columnas: 79', [79]],
+ ['Columnas (77)', [77]],
+ ['**Columnas:** 78', [78]],
+ ['columns: 78', [78]],
+ ['Total de 78 columnas', [78]],
+ ['78 columnas de datos y 56.992 registros', [78]],
+ ['Columnas: notes,value', []],
+ ['Columnas:\n1. id\n2. value', []],
+ ['La columna value tiene 78 valores distintos', []],
+ ['Columnas: 7,8', []],
+ ['Columnas: 78,59', []],
+ ['Columnas: -78', []],
+ ['Columnas: 78; total: 79 columnas', [78, 79]],
+ ] as const)('extracts explicit column-count claims from %j', (summary, claims) => {
+ expect(csvColumnCountClaims(summary)).toEqual(claims)
+ })
+
+ it.each([77, 79])('rejects a contradictory count of %i despite complete names', claim => {
+ const columns = Array.from({ length: 78 }, (_, index) => `field_${index}`)
+ const summary = `Contiene ${claim} columnas: ${columns.join(', ')}`
+ expect(countMissingCsvColumns(summary, columns)).toBe(0)
+ expect(csvColumnCountClaims(summary).filter(value => value !== columns.length)).toEqual([claim])
+ })
+
it.each([
['Hay 923 registros de datos, sin contar la cabecera.', 923, true],
['**Registros de datos (sin cabecera):** 923.', 923, true],
diff --git a/desktop-app/test/e2e-playwright/gfs-agent-large-file-cli.test.ts b/desktop-app/test/e2e-playwright/gfs-agent-large-file-cli.test.ts
index 36669d995..8ce43209d 100644
--- a/desktop-app/test/e2e-playwright/gfs-agent-large-file-cli.test.ts
+++ b/desktop-app/test/e2e-playwright/gfs-agent-large-file-cli.test.ts
@@ -33,6 +33,7 @@ import {
GFS_OLD_VISUAL_LIMIT,
type GfsLargeCsvFixture,
countMissingCsvColumns,
+ csvColumnCountClaims,
hasCsvDataRecordCount,
resolveGfsLargeCsvFixture,
} from './helpers/gfsLargeFileCsvFixture'
@@ -162,35 +163,12 @@ async function sendTaskAndWaitForReviewedShell(
// Local control becomes actionable only after this test verifies the initial
// receipt and unexecuted shell. Every decision still clicks the visible UI.
reviewer?.activate()
- const responseDeadline = Date.now() + RESPONSE_TIMEOUT_MS
- let stepperClass = ''
- let lastReviewState = 'not started'
- while (Date.now() < responseDeadline) {
- if (reviewer) {
- const clicked = await reviewer.reviewAndApproveVisible(receiptPath!)
- lastReviewState = clicked ? 'clicked visible approval' : 'no actionable approval'
- }
- stepperClass = (await stepper.getAttribute('class')) ?? ''
- if (/\bstatus-completed\b/.test(stepperClass)) break
- await page.waitForFunction(
- () => {
- const currentStepper = document.querySelector('[data-testid="progress-stepper"]')
- const approve = document.querySelector<HTMLButtonElement>(
- '[data-testid="approval-approve-btn"]'
- )
- return (
- currentStepper?.classList.contains('status-completed') === true ||
- approve?.disabled === false
- )
- },
- undefined,
- { timeout: Math.max(1, responseDeadline - Date.now()), polling: 'raf' }
- )
- }
- expect(
- stepperClass,
- `Governed turn did not complete; last review state: ${lastReviewState}`
- ).toMatch(/\bstatus-completed\b/)
+ // Wait on the stable turn while the attending reviewer handles every
+ // request through the one-use local transport and visible approval button.
+ // Merely recognizing a program's keywords cannot grant execution consent.
+ await expect(stepper).toHaveClass(/\bstatus-completed\b/, {
+ timeout: RESPONSE_TIMEOUT_MS,
+ })
await expect(approval).toHaveCount(0, { timeout: RESPONSE_TIMEOUT_MS })
await expect(response).toBeVisible({ timeout: RESPONSE_TIMEOUT_MS })
const expandButton = page.getByTestId('progress-expand-btn')
@@ -434,6 +412,10 @@ test.describe('GFS large-file business analysis with attended approval', () => {
countMissingCsvColumns(responseSummary, csv.columns),
'Response must include every independently parsed CSV column'
).toBe(0)
+ expect(
+ csvColumnCountClaims(responseSummary).filter(claim => claim !== csv.columns.length),
+ 'Every stated column count must match the independently parsed header'
+ ).toEqual([])
if (csv.source === 'synthetic') {
await expect(response).toContainText(csv.lastRecordId!)
}
diff --git a/desktop-app/test/e2e-playwright/helpers/gfsApprovalReview.ts b/desktop-app/test/e2e-playwright/helpers/gfsApprovalReview.ts
index 18ce8c7be..7fae45aab 100644
--- a/desktop-app/test/e2e-playwright/helpers/gfsApprovalReview.ts
+++ b/desktop-app/test/e2e-playwright/helpers/gfsApprovalReview.ts
@@ -17,38 +17,6 @@ type Pending = {
}
const MAX_REQUEST_BYTES = 1_024
const MAX_COMMAND_BYTES = 65_536
-const ALLOWED_NODE_MODULE_ROOT = '/app/mcp-host/node_modules/'
-
-function escapeRegExp(value: string): string {
- return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
-}
-
-function assertReadonlyReceiptCommand(command: string, receiptPath: string): void {
- if (!command.includes(receiptPath))
- throw new Error('Reviewed command does not use the verified receipt')
- if (!/^node\s+-\s*<<'NODE'\n/.test(command))
- throw new Error('Reviewed command must be a Node stdin program')
- const receiptMatches = command.match(new RegExp(escapeRegExp(receiptPath), 'g')) ?? []
- if (receiptMatches.length !== 1 || receiptMatches[0] !== receiptPath)
- throw new Error('Reviewed command must reference exactly one verified receipt')
- if (command.includes('.gfs-download-store'))
- throw new Error('Reviewed command cannot access the download store')
- const forbidden = [
- /\b(?:rm|rmdir|mv|cp|mkdir|touch|chmod|chown|ln|unlink)\b/,
- /\b(?:writeFile(?:Sync)?|appendFile(?:Sync)?|truncate(?:Sync)?|rmSync|unlinkSync)\b/,
- /\b(?:child_process|spawnSync|spawn\(|execSync|exec\(|fork\(|forkSync)\b/,
- /\b(?:fetch|axios|XMLHttpRequest|net\.connect|dns\.)\b/,
- /https?:\/\//,
- /\bprocess\.env\b/,
- ]
- if (forbidden.some(pattern => pattern.test(command)))
- throw new Error('Reviewed command contains a forbidden write, process, or network operation')
- for (const match of command.matchAll(/(['"])(\/[^'"\n]+)\1/g)) {
- const value = match[2]
- if (!value.startsWith(ALLOWED_NODE_MODULE_ROOT))
- throw new Error(`Reviewed command contains an unapproved absolute path: ${value}`)
- }
-}
/** Only opt-in attended E2E uses this local reviewer transport. */
export async function createGfsApprovalReview(
@@ -174,28 +142,6 @@ export async function createGfsApprovalReview(
}
}
- async function reviewAndApproveVisible(receiptPath: string): Promise<boolean> {
- verifyOwnedPage()
- if (!active || result || deciding) return false
- const approve = page.getByTestId('approval-approve-btn')
- const approveCount = await approve.count()
- if (approveCount === 0) return false
- if (approveCount !== 1 || !(await approve.isVisible()) || !(await approve.isEnabled()))
- return false
- const current = await visibleApproval()
- if (!current) return false
- assertReadonlyReceiptCommand(current.command, receiptPath)
- pending = {
- nonce: randomUUID(),
- command: current.command,
- button: current.button,
- denyButton: current.denyButton,
- expiresAt: Date.now() + requestTimeoutMs,
- }
- await decideReview('approve', pending.nonce)
- return true
- }
-
async function decideReview(action: 'approve' | 'deny', nonce: unknown): Promise<unknown> {
if (
!active ||
@@ -316,8 +262,6 @@ export async function createGfsApprovalReview(
activate() {
active = true
},
- /** Reviews and clicks each actionable visible request for one verified receipt. */
- reviewAndApproveVisible,
/** Result observation cannot bypass or satisfy the journey's business assertions. */
async observeResult(verdict: 'passed' | 'failed', visibleResponse?: string) {
result = verdict
diff --git a/desktop-app/test/e2e-playwright/helpers/gfsLargeFileCsvFixture.ts b/desktop-app/test/e2e-playwright/helpers/gfsLargeFileCsvFixture.ts
index 6bfe68a89..26282efca 100644
--- a/desktop-app/test/e2e-playwright/helpers/gfsLargeFileCsvFixture.ts
+++ b/desktop-app/test/e2e-playwright/helpers/gfsLargeFileCsvFixture.ts
@@ -45,6 +45,22 @@ export function hasCsvDataRecordCount(summary: string, count: number): boolean {
).test(summary)
}
+/** Extract explicit plural count claims without requiring a numeric summary. */
+export function csvColumnCountClaims(summary: string): number[] {
+ const label = String.raw`(?:columnas|columns)`
+ const number = String.raw`(?<![\p{L}\p{N}_\-\u2212])(\d{1,3}(?:[., \t]\d{3})+|\d+)(?![\p{L}\p{N}_]|[.,]\d)`
+ // Horizontal spacing cannot mistake the first numbered item below a
+ // "Columns:" heading for a count of columns.
+ const pattern = new RegExp(
+ String.raw`(?:\b${label}\b\*{0,2}[ \t]*(?:\(|:|es|=|de|son)?[ \t]*\*{0,2}[ \t]*${number}|${number}[ \t*\x60_]{1,12}\b${label}\b)`,
+ 'giu'
+ )
+ return [...summary.matchAll(pattern)]
+ .flatMap(match => [match[1], match[2]])
+ .filter((raw): raw is string => Boolean(raw))
+ .map(raw => Number(raw.replace(/[., \t]/g, '')))
+}
+
/** Count distinct header mentions without returning private field names. */
export function countMissingCsvColumns(summary: string, columns: readonly string[]): number {
const normalize = (value: string): string => value.replace(/\s+/g, ' ').trim()
diff --git a/desktop-app/test/gfsApprovalReview.test.ts b/desktop-app/test/gfsApprovalReview.test.ts
index 8c3b1129c..8071da383 100644
--- a/desktop-app/test/gfsApprovalReview.test.ts
+++ b/desktop-app/test/gfsApprovalReview.test.ts
@@ -8,7 +8,7 @@ import { createGfsApprovalReview } from './e2e-playwright/helpers/gfsApprovalRev
type Review = Awaited<ReturnType<typeof createGfsApprovalReview>>
const reviews: Review[] = []
const compiledUrl = 'file:///owned/worktree/desktop-app/ui-dist/index.html'
-const receiptPath = '.gfs-downloads/input/01234567-89ab-cdef-0123-456789abcdef/source'
+const receiptPath = '.gfs-downloads/input-01234567-89ab-cdef-0123-456789abcdef/source'
const command = `node - <<'NODE'
const fs = require('fs');
const stream = fs.createReadStream(${JSON.stringify(receiptPath)});
@@ -159,11 +159,14 @@ describe('attended GFS approval reviewer', () => {
expect(f.approveClick).toHaveBeenCalledTimes(1)
})
- it('automatically reviews and clicks successive visible requests for the verified receipt', async () => {
+ it('requires a fresh explicit decision for every successive visible request', async () => {
const f = await fixture()
- expect(await f.review.reviewAndApproveVisible(receiptPath)).toBe(false)
f.review.activate()
- expect(await f.review.reviewAndApproveVisible(receiptPath)).toBe(true)
+ const first = await request(f.review, { action: 'view' })
+ expect(f.approveClick).not.toHaveBeenCalled()
+ expect(await request(f.review, { action: 'approve', nonce: first.nonce })).toMatchObject({
+ clicked: 'approve',
+ })
expect(f.approveClick).toHaveBeenCalledExactlyOnceWith({ timeout: expect.any(Number) })
f.state.visible = true
@@ -171,37 +174,16 @@ describe('attended GFS approval reviewer', () => {
'stream.resume();',
"stream.resume(); if (/^record-/i.test('record')) globalThis.checked = true;"
)
- expect(await f.review.reviewAndApproveVisible(receiptPath)).toBe(true)
- expect(f.approveClick).toHaveBeenCalledTimes(2)
- expect(f.denyClick).not.toHaveBeenCalled()
- })
-
- it.each([
- [
- 'different receipt',
- command.replace(
- receiptPath,
- '.gfs-downloads/input/ffffffff-ffff-ffff-ffff-ffffffffffff/source'
- ),
- ],
- ['write operation', command.replace('stream.resume();', "fs.writeFileSync('out.txt', 'x');")],
- ['network operation', command.replace('stream.resume();', "fetch('https://example.invalid');")],
- [
- 'unapproved absolute path',
- command.replace('const fs', "const path = '/etc/passwd'; const fs"),
- ],
- [
- 'non-stdin command',
- `node -e ${JSON.stringify(`require('fs').createReadStream(${receiptPath})`)}`,
- ],
- ])('automatic review rejects %s without clicking', async (_name, unsafeCommand) => {
- const f = await fixture()
- f.state.command = unsafeCommand
- f.review.activate()
- await expect(f.review.reviewAndApproveVisible(receiptPath)).rejects.toThrow(
- /receipt|forbidden|absolute path|stdin/
+ const next = await request(f.review, { action: 'view' })
+ expect(next.nonce).not.toEqual(first.nonce)
+ expect(f.approveClick).toHaveBeenCalledTimes(1)
+ expect(await request(f.review, { action: 'approve', nonce: first.nonce })).toHaveProperty(
+ 'error'
)
- expect(f.approveClick).not.toHaveBeenCalled()
+ expect(await request(f.review, { action: 'approve', nonce: next.nonce })).toMatchObject({
+ clicked: 'approve',
+ })
+ expect(f.approveClick).toHaveBeenCalledTimes(2)
expect(f.denyClick).not.toHaveBeenCalled()
})