Skip to content

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

TypeScript

test(desktop): manage repeated gfs shell approvals

Alfredo Lopezf8b439101419
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 4d132d835..36669d995 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
@@ -90,7 +90,9 @@ async function sendTaskAndWaitForReviewedShell(
await expect(approval).toHaveCount(1, { timeout: RESPONSE_TIMEOUT_MS })
await expect(approval).toBeVisible({ timeout: 10_000 })
- const stepper = page.getByTestId('progress-stepper').filter({ has: approval })
+ // This is a new chat and the test asserted above that no prior stepper exists.
+ // Keep the same stable turn locator after the approval button disappears.
+ const stepper = page.getByTestId('progress-stepper')
await expect(stepper).toBeVisible({ timeout: 10_000 })
await expect(stepper).toContainText('Shell requires approval')
const commandPreview = stepper.getByTestId('approval-input-preview')
@@ -98,8 +100,13 @@ async function sendTaskAndWaitForReviewedShell(
await expect(commandPreview).toContainText('.gfs-downloads/')
await expect(stepper.getByRole('note')).toHaveCount(0)
const details = stepper.getByRole('button', { name: /More details/ })
- await expect(details).toBeVisible()
- await details.click()
+ // Path requests must show discovery and transfer evidence. An attached
+ // reference is prepared before the first model turn, so its approval card can
+ // legitimately contain only the reviewed shell call.
+ if (sourceMode === 'path') {
+ await expect(details).toBeVisible()
+ await details.click()
+ }
const downloaded = completedToolStepRow(page, /gfs_download|gfs_read/)
let receiptPath: string | undefined
if (sourceMode === 'path') {
@@ -155,9 +162,35 @@ 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()
- await expect(page.getByTestId('progress-stepper')).toHaveClass(/\bstatus-completed\b/, {
- timeout: RESPONSE_TIMEOUT_MS,
- })
+ 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/)
await expect(approval).toHaveCount(0, { timeout: RESPONSE_TIMEOUT_MS })
await expect(response).toBeVisible({ timeout: RESPONSE_TIMEOUT_MS })
const expandButton = page.getByTestId('progress-expand-btn')
diff --git a/desktop-app/test/e2e-playwright/helpers/gfsApprovalReview.ts b/desktop-app/test/e2e-playwright/helpers/gfsApprovalReview.ts
index 7fae45aab..18ce8c7be 100644
--- a/desktop-app/test/e2e-playwright/helpers/gfsApprovalReview.ts
+++ b/desktop-app/test/e2e-playwright/helpers/gfsApprovalReview.ts
@@ -17,6 +17,38 @@ 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(
@@ -142,6 +174,28 @@ 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 ||
@@ -262,6 +316,8 @@ 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/gfsApprovalReview.test.ts b/desktop-app/test/gfsApprovalReview.test.ts
index 5bf07c546..8c3b1129c 100644
--- a/desktop-app/test/gfsApprovalReview.test.ts
+++ b/desktop-app/test/gfsApprovalReview.test.ts
@@ -8,7 +8,12 @@ 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 command = 'node -e \'process.stdout.write("bounded summary")\''
+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)});
+stream.resume();
+NODE`
afterEach(async () => {
vi.restoreAllMocks()
@@ -154,6 +159,52 @@ describe('attended GFS approval reviewer', () => {
expect(f.approveClick).toHaveBeenCalledTimes(1)
})
+ it('automatically reviews and clicks successive visible requests for the verified receipt', async () => {
+ const f = await fixture()
+ expect(await f.review.reviewAndApproveVisible(receiptPath)).toBe(false)
+ f.review.activate()
+ expect(await f.review.reviewAndApproveVisible(receiptPath)).toBe(true)
+ expect(f.approveClick).toHaveBeenCalledExactlyOnceWith({ timeout: expect.any(Number) })
+
+ f.state.visible = true
+ f.state.command = command.replace(
+ '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/
+ )
+ expect(f.approveClick).not.toHaveBeenCalled()
+ expect(f.denyClick).not.toHaveBeenCalled()
+ })
+
it.each([
'command',
'button',