Skip to content

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

TypeScript

test(e2e): verify GFS download SHA, Host restart and per-user copies

Alfredo Lopez787fb51ecded
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 ff13e2f80..f020a6230 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
@@ -16,14 +16,25 @@
* file are named preconditions. No provider-route mock, storage mutation,
* direct API trigger, or broad network mock is used.
*/
-import { type Locator, type Page, expect, test } from '@playwright/test'
+import { type ElectronApplication, type Locator, type Page, expect, test } from '@playwright/test'
+import { createHash } from 'node:crypto'
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join, resolve } from 'node:path'
import { pathToFileURL } from 'node:url'
-import { getGfsChildResourceSummary, getGfsGrantSummary } from '../../../tests/e2e/gfsUiFixtures'
+import {
+ UUID_RE,
+ firstDataLine,
+ getGfsChildResourceSummary,
+ getGfsGrantSummary,
+ kubectlOut,
+ runControlPostgresSql,
+ seedGfsGrant,
+ sqlLiteral,
+} from '../../../tests/e2e/gfsUiFixtures'
+import { E2E_TEST_EMAIL } from '../../../tests/e2e/testUser'
import { exactNameFilter } from './helpers/agentLocators'
-import { getManagedAgentDisplayName } from './helpers/gfsAgentDiscovery'
+import { type ManagedGfsAgent, getManagedAgentDisplayName } from './helpers/gfsAgentDiscovery'
import { createGfsApprovalReview } from './helpers/gfsApprovalReview'
import { assertGfsInfraHealthy } from './helpers/gfsFixtures'
import {
@@ -42,7 +53,13 @@ import {
import { openAgentsPage, openResourcesNavItem } from './navigationHelpers'
import { launchAndLogin } from './workflowUi'
-const OWNER_EMAIL = '[email protected]'
+// The seeded Desktop user of the profile ([email protected] on the minimal
+// seed) owns the upload.
+const OWNER_EMAIL = E2E_TEST_EMAIL
+// Named precondition for the two-users journey, created by SQL below.
+const SECOND_USER_EMAIL = '[email protected]'
+const HOST_WORKSPACE = '/workspace'
+const HOST_RESTART_TIMEOUT_MS = 300_000
const RESPONSE_TIMEOUT_MS = 420_000
const PROGRESS_TIMEOUT_MS = 45_000
// A 16 KiB ceiling bounds header/count metadata well below the 3.8 MB input.
@@ -81,7 +98,7 @@ async function sendTaskAndWaitForReviewedShell(
resourceId: string,
sourceMode: 'path' | 'reference',
reviewer?: Awaited<ReturnType<typeof createGfsApprovalReview>>
-): Promise<{ response: Locator; expandButton: Locator }> {
+): Promise<{ response: Locator; expandButton: Locator; receiptId: string }> {
const response = page.getByTestId('agent-response')
const approval = page.getByTestId('approval-approve-btn')
// This is a new chat. A completed stepper from a prior turn must never
@@ -154,6 +171,8 @@ async function sendTaskAndWaitForReviewedShell(
receiptPath = path!
}
await expect(commandPreview).toContainText(receiptPath!)
+ const receiptId = receiptPath!.slice('.gfs-downloads/input-'.length, -'/source'.length)
+ expect(receiptId, 'The reviewed receipt must have a UUID id').toMatch(UUID_RE)
await expect(completedToolStepRow(page, 'shell_exec')).toHaveCount(0)
// The agent creates its own program from the normal business request. A
// reviewer inspects the complete command shown on the task's single shell
@@ -180,7 +199,136 @@ async function sendTaskAndWaitForReviewedShell(
const expandButton = page.getByTestId('progress-expand-btn')
await expect(expandButton).toHaveCount(1, { timeout: PROGRESS_TIMEOUT_MS })
await expect(expandButton).toBeVisible({ timeout: PROGRESS_TIMEOUT_MS })
- return { response, expandButton }
+ return { response, expandButton, receiptId }
+}
+
+interface HostReceiptCopy {
+ userKey: string
+ sha256: string
+}
+
+/** The agent's one live, Ready Host pod; none or several fails the check. */
+function readyHostPod(agent: ManagedGfsAgent): { name: string; uid: string } | undefined {
+ const rows = kubectlOut([
+ '-n',
+ agent.namespace,
+ 'get',
+ 'pods',
+ '-l',
+ `app=${agent.name}`,
+ '-o',
+ 'go-template={{range .items}}{{if not .metadata.deletionTimestamp}}{{.metadata.name}} {{.metadata.uid}}{{range .status.conditions}}{{if eq .type "Ready"}} {{.status}}{{end}}{{end}}{{"\\n"}}{{end}}{{end}}',
+ ])
+ .split('\n')
+ .map(line => line.trim().split(' '))
+ .filter(fields => fields[0])
+ if (rows.length !== 1) return undefined
+ const [name, uid, ready] = rows[0]!
+ return ready === 'True' && name && uid ? { name, uid } : undefined
+}
+
+/**
+ * Reads the Host's copy of a receipt from its own container. The receipt id is
+ * a UUID checked above, so the glob only selects the user key directory.
+ */
+function hostReceiptCopy(agent: ManagedGfsAgent, receiptId: string): HostReceiptCopy {
+ expect(receiptId).toMatch(UUID_RE)
+ const pod = readyHostPod(agent)
+ if (!pod) throw new Error(`no single Ready Host pod for ${agent.namespace}/${agent.name}`)
+ const lines = kubectlOut(
+ [
+ '-n',
+ agent.namespace,
+ 'exec',
+ pod.name,
+ '-c',
+ 'mcp-host',
+ '--',
+ 'sh',
+ '-c',
+ `sha256sum ${HOST_WORKSPACE}/users/*/.gfs-downloads/input-${receiptId}/source`,
+ ],
+ 60_000
+ )
+ .split('\n')
+ .filter(Boolean)
+ expect(lines, `exactly one Host copy for receipt ${receiptId}`).toHaveLength(1)
+ const match = lines[0]!.match(
+ new RegExp(
+ `^([0-9a-f]{64})\\s+${HOST_WORKSPACE}/users/([0-9a-f]{16})/\\.gfs-downloads/input-${receiptId}/source$`
+ )
+ )
+ expect(match, `unexpected sha256sum output for receipt ${receiptId}`).toBeTruthy()
+ return { sha256: match![1]!, userKey: match![2]! }
+}
+
+/** The `adopted` count from the store-initialized line of the pod's Host log. */
+function storeInitializedAdopted(agent: ManagedGfsAgent, pod: string): number | undefined {
+ const line = kubectlOut(['-n', agent.namespace, 'logs', `pod/${pod}`, '-c', 'mcp-host'], 30_000)
+ .split('\n')
+ .find(value => value.includes('"msg":"GFS download store initialized"'))
+ if (!line) return undefined
+ const adopted = (JSON.parse(line) as { adopted?: unknown }).adopted
+ if (typeof adopted !== 'number') throw new Error('store-initialized log has no adopted count')
+ return adopted
+}
+
+/**
+ * Named precondition: a second Desktop user in the owner's team with the same
+ * agent and contexts as the owner, as the profile seed binds its users. The
+ * password is seeded by `launchAndLogin`.
+ */
+function ensureSecondUser(ownerEmail: string, agentName: string): string {
+ const userId = firstDataLine(
+ runControlPostgresSql(`
+ WITH owner AS (
+ SELECT id FROM users WHERE email = ${sqlLiteral(ownerEmail.toLowerCase())}
+ ), owner_team AS (
+ SELECT tm.team_id FROM team_members tm JOIN owner ON owner.id = tm.user_id
+ WHERE tm.status = 'active' ORDER BY tm.created_at ASC LIMIT 1
+ ), second_user AS (
+ INSERT INTO users(email, name) VALUES(${sqlLiteral(SECOND_USER_EMAIL)}, 'E2E GFS Second User')
+ ON CONFLICT (email) DO UPDATE SET updated_at = now()
+ RETURNING id
+ ), second_profile AS (
+ INSERT INTO profiles(user_id, display_name)
+ SELECT id, 'E2E GFS Second User' FROM second_user
+ ON CONFLICT (user_id) DO UPDATE SET updated_at = now()
+ RETURNING user_id
+ ), membership AS (
+ INSERT INTO team_members(team_id, user_id, role, status)
+ SELECT owner_team.team_id, second_user.id, 'member', 'active'
+ FROM owner_team CROSS JOIN second_user
+ ON CONFLICT (team_id, user_id) DO UPDATE SET role = 'member', status = 'active', updated_at = now()
+ RETURNING user_id
+ ), agent_access AS (
+ INSERT INTO user_agents(user_id, agent_name)
+ SELECT id, ${sqlLiteral(agentName)} FROM second_user
+ ON CONFLICT DO NOTHING
+ RETURNING user_id
+ ), contexts AS (
+ INSERT INTO user_contexts(user_id, context_id)
+ SELECT second_user.id, uc.context_id
+ FROM second_user CROSS JOIN user_contexts uc JOIN owner ON owner.id = uc.user_id
+ ON CONFLICT DO NOTHING
+ RETURNING user_id
+ )
+ SELECT membership.user_id::text
+ FROM membership JOIN second_profile ON second_profile.user_id = membership.user_id;
+ `)
+ )
+ if (!UUID_RE.test(userId)) throw new Error(`second user precondition failed: ${userId}`)
+ const bindings = firstDataLine(
+ runControlPostgresSql(`
+ SELECT (SELECT count(*) FROM user_agents WHERE user_id = ${sqlLiteral(userId)}::uuid
+ AND agent_name = ${sqlLiteral(agentName)})::text || ' ' ||
+ (SELECT count(*) FROM user_contexts WHERE user_id = ${sqlLiteral(userId)}::uuid)::text;
+ `)
+ )
+ const [agentCount, contextCount] = bindings.split(' ').map(Number)
+ expect(agentCount, 'second user must have the agent').toBe(1)
+ expect(contextCount, 'second user must have the owner contexts').toBeGreaterThan(0)
+ return userId
}
function toolStepRow(page: Page, toolName: string | RegExp): Locator {
@@ -247,6 +395,162 @@ test.describe('GFS large-file business analysis with attended approval', () => {
}
})
+ function csvSha256(): string {
+ return createHash('sha256').update(csv.buffer).digest('hex')
+ }
+
+ function analysisPrompt(sourceMode: 'path' | 'reference'): string {
+ return (
+ (sourceMode === 'path'
+ ? `Analiza el CSV "${csv.fileName}" de la carpeta "${fixtures.granted.name}" en EvenDrive. `
+ : 'Analiza el CSV que adjunté. ') +
+ 'Dime cuántos registros de datos contiene, sin contar la cabecera, y cuáles son sus columnas. ' +
+ (csv.source === 'synthetic' ? 'Incluye también el identificador del último registro. ' : '') +
+ 'Mantén el archivo original sin cambios y responde con un resumen breve.'
+ )
+ }
+
+ async function uploadCsvThroughFiles(
+ page: Page
+ ): Promise<NonNullable<ReturnType<typeof getGfsChildResourceSummary>>> {
+ await openResourcesNavItem(page, 'nav-files')
+ await expect(page.getByRole('heading', { name: 'Files', exact: true })).toBeVisible()
+ const browser = page.getByRole('region', { name: 'EvenDrive browser' })
+ await expect(browser).toBeVisible({ timeout: 30_000 })
+ await browser
+ .getByRole('button', { name: `Open ${fixtures.granted.name}`, exact: true })
+ .click()
+ await expect(
+ browser.getByRole('button', { name: `Open ${fixtures.granted.childName}`, exact: true })
+ ).toBeVisible({ timeout: 30_000 })
+ const upload = browser.getByRole('button').filter({ hasText: /^Upload file$/ })
+ await expect(upload).toBeVisible({ timeout: 30_000 })
+ const [chooser] = await Promise.all([
+ page.waitForEvent('filechooser', { timeout: 30_000 }),
+ upload.click(),
+ ])
+ await chooser.setFiles(csvUploadPath)
+ await expect(page.getByText(`Uploaded ${csv.fileName}`)).toBeVisible({
+ timeout: 30_000,
+ })
+ await expect(
+ browser.getByRole('button', { name: `Open ${csv.fileName}`, exact: true })
+ ).toBeVisible({ timeout: 30_000 })
+ const uploaded = getGfsChildResourceSummary({
+ parentResourceId: fixtures.granted.resourceId,
+ name: csv.fileName,
+ })
+ expect(uploaded).toMatchObject({
+ kind: 'file',
+ bytes: GFS_LARGE_CSV_SIZE,
+ deleted: false,
+ })
+ const hostGrant = getGfsGrantSummary({
+ resourceId: fixtures.granted.resourceId,
+ subjectType: 'host',
+ subjectId: fixtures.agent.subjectId,
+ })
+ expect(hostGrant).toMatchObject({ permissions: ['read'], inherit: true })
+ await test.info().attach('gfs-source-identity', {
+ contentType: 'application/json',
+ body: JSON.stringify({
+ resourceId: uploaded!.resourceId,
+ parentResourceId: fixtures.granted.resourceId,
+ version: uploaded!.version,
+ bytes: uploaded!.bytes,
+ hostSubjectId: fixtures.agent.subjectId,
+ hostGrant,
+ }),
+ })
+ return uploaded!
+ }
+
+ /**
+ * One path-mode analysis task in a new chat: governed download, attended
+ * shell approval, and the independent record count in the response.
+ */
+ async function analyzeByPath(
+ page: Page,
+ resourceId: string,
+ reviewer: Awaited<ReturnType<typeof createGfsApprovalReview>> | undefined
+ ): Promise<string> {
+ await enterAgentChat(page, agentLabel)
+ const { response, receiptId } = await sendTaskAndWaitForReviewedShell(
+ page,
+ analysisPrompt('path'),
+ resourceId,
+ 'path',
+ reviewer
+ )
+ const summary = await response.innerText()
+ expect(
+ hasCsvDataRecordCount(summary, csv.dataRecordCount),
+ 'Response must report the independent count as CSV data records'
+ ).toBe(true)
+ return receiptId
+ }
+
+ /** Runs a journey in one owned Desktop session with the optional reviewer. */
+ async function withDesktop<T>(
+ email: string,
+ label: string,
+ journey: (
+ page: Page,
+ reviewer: Awaited<ReturnType<typeof createGfsApprovalReview>> | undefined
+ ) => Promise<T>
+ ): Promise<T> {
+ const { app, page }: { app: ElectronApplication; page: Page } = await launchAndLogin(email)
+ let reviewer: Awaited<ReturnType<typeof createGfsApprovalReview>> | undefined
+ let verdict: 'passed' | 'failed' = 'failed'
+ try {
+ if (process.env.E2E_GFS_REVIEW_CONTROL === '1') {
+ reviewer = await createGfsApprovalReview(
+ app,
+ page,
+ pathToFileURL(resolve(__dirname, '../../ui-dist/index.html')).href
+ )
+ console.info(
+ 'GFS_APPROVAL_REVIEW_READY',
+ JSON.stringify({
+ socketPath: reviewer.socketPath,
+ session: label,
+ pid: app.process().pid,
+ })
+ )
+ }
+ const value = await journey(page, reviewer)
+ verdict = 'passed'
+ return value
+ } catch (error) {
+ if (!page.isClosed()) {
+ try {
+ await test.info().attach(`large-file-${label}-failure`, {
+ contentType: 'image/png',
+ body: await page.screenshot({ timeout: 5_000 }),
+ })
+ } catch {
+ await test.info().attach(`large-file-${label}-screenshot-unavailable`, {
+ contentType: 'text/plain',
+ body: 'The owned Electron window did not produce a screenshot within five seconds.',
+ })
+ }
+ }
+ throw error
+ } finally {
+ try {
+ if (reviewer) {
+ try {
+ await reviewer.observeResult(verdict)
+ } finally {
+ await reviewer.close()
+ }
+ }
+ } finally {
+ await app.close()
+ }
+ }
+ }
+
for (const sourceMode of ['path', 'reference'] as const) {
test(`user asks for CSV record count and columns via ${sourceMode}`, async () => {
const { app, page } = await launchAndLogin(OWNER_EMAIL)
@@ -277,60 +581,12 @@ test.describe('GFS large-file business analysis with attended approval', () => {
ownedTraceStarted = true
}
await test.step('user uploads the exact CSV through Files', async () => {
- await openResourcesNavItem(page, 'nav-files')
- await expect(page.getByRole('heading', { name: 'Files', exact: true })).toBeVisible()
- const browser = page.getByRole('region', { name: 'EvenDrive browser' })
- await expect(browser).toBeVisible({ timeout: 30_000 })
- await browser
- .getByRole('button', { name: `Open ${fixtures.granted.name}`, exact: true })
- .click()
- await expect(
- browser.getByRole('button', { name: `Open ${fixtures.granted.childName}`, exact: true })
- ).toBeVisible({ timeout: 30_000 })
- const upload = browser.getByRole('button').filter({ hasText: /^Upload file$/ })
- await expect(upload).toBeVisible({ timeout: 30_000 })
- const [chooser] = await Promise.all([
- page.waitForEvent('filechooser', { timeout: 30_000 }),
- upload.click(),
- ])
- await chooser.setFiles(csvUploadPath)
- await expect(page.getByText(`Uploaded ${csv.fileName}`)).toBeVisible({
- timeout: 30_000,
- })
- await expect(
- browser.getByRole('button', { name: `Open ${csv.fileName}`, exact: true })
- ).toBeVisible({ timeout: 30_000 })
- const uploaded = getGfsChildResourceSummary({
- parentResourceId: fixtures.granted.resourceId,
- name: csv.fileName,
- })
- expect(uploaded).toMatchObject({
- kind: 'file',
- bytes: GFS_LARGE_CSV_SIZE,
- deleted: false,
- })
- sourceBefore = uploaded!
- const hostGrant = getGfsGrantSummary({
- resourceId: fixtures.granted.resourceId,
- subjectType: 'host',
- subjectId: fixtures.agent.subjectId,
- })
- expect(hostGrant).toMatchObject({ permissions: ['read'], inherit: true })
- await test.info().attach('gfs-source-identity', {
- contentType: 'application/json',
- body: JSON.stringify({
- resourceId: uploaded!.resourceId,
- parentResourceId: fixtures.granted.resourceId,
- version: uploaded!.version,
- bytes: uploaded!.bytes,
- hostSubjectId: fixtures.agent.subjectId,
- hostGrant,
- }),
- })
+ sourceBefore = await uploadCsvThroughFiles(page)
})
let expandButton: Locator
let response: Locator
+ let receiptId: string
await test.step('exact agent downloads and processes the file after approval', async () => {
await enterAgentChat(page, agentLabel)
if (sourceMode === 'reference') {
@@ -362,24 +618,20 @@ test.describe('GFS large-file business analysis with attended approval', () => {
page.getByRole('button', { name: `Remove ${csv.fileName}`, exact: true })
).toBeVisible()
}
- const prompt =
- (sourceMode === 'path'
- ? `Analiza el CSV "${csv.fileName}" de la carpeta "${fixtures.granted.name}" en EvenDrive. `
- : 'Analiza el CSV que adjunté. ') +
- 'Dime cuántos registros de datos contiene, sin contar la cabecera, y cuáles son sus columnas. ' +
- (csv.source === 'synthetic'
- ? 'Incluye también el identificador del último registro. '
- : '') +
- 'Mantén el archivo original sin cambios y responde con un resumen breve.'
const result = await sendTaskAndWaitForReviewedShell(
page,
- prompt,
+ analysisPrompt(sourceMode),
sourceBefore.resourceId,
sourceMode,
reviewer
)
expandButton = result.expandButton
response = result.response
+ receiptId = result.receiptId
+ })
+
+ await test.step('Host copy of the receipt has the uploaded bytes', async () => {
+ expect(hostReceiptCopy(fixtures.agent, receiptId).sha256).toBe(csvSha256())
})
await test.step('tool stepper proves governed transfer and local execution', async () => {
@@ -493,4 +745,84 @@ test.describe('GFS large-file business analysis with attended approval', () => {
}
})
}
+
+ test('downloads are fresh after a Host restart and separate per user', async () => {
+ // Three attended tasks, one Host restart and two Desktop sessions.
+ test.setTimeout(RESPONSE_TIMEOUT_MS * 6 + HOST_RESTART_TIMEOUT_MS + 300_000)
+ const expectedSha256 = csvSha256()
+ let resourceId = ''
+ let r2 = ''
+ let ownerKey = ''
+
+ await withDesktop(OWNER_EMAIL, 'owner', async (page, reviewer) => {
+ await test.step('owner uploads the exact CSV through Files', async () => {
+ resourceId = (await uploadCsvThroughFiles(page)).resourceId
+ })
+
+ let r1 = ''
+ await test.step('owner download R1 has the uploaded bytes on the Host', async () => {
+ r1 = await analyzeByPath(page, resourceId, reviewer)
+ const copy = hostReceiptCopy(fixtures.agent, r1)
+ expect(copy.sha256).toBe(expectedSha256)
+ ownerKey = copy.userKey
+ })
+
+ await test.step('Host pod is deleted and a new pod adopts the retained copy', async () => {
+ const before = readyHostPod(fixtures.agent)
+ expect(before, 'a single Ready Host pod before the restart').toBeTruthy()
+ kubectlOut(['-n', fixtures.agent.namespace, 'delete', 'pod', before!.name, '--wait=false'])
+ let after: { name: string; uid: string } | undefined
+ await expect
+ .poll(
+ () => {
+ after = readyHostPod(fixtures.agent)
+ return after !== undefined && after.uid !== before!.uid
+ },
+ { timeout: HOST_RESTART_TIMEOUT_MS, intervals: [2_000, 5_000] }
+ )
+ .toBe(true)
+ // A restarted store never reuses a copy it did not publish itself;
+ // it adopts R1 for cleanup and quota only.
+ await expect
+ .poll(() => storeInitializedAdopted(fixtures.agent, after!.name), { timeout: 120_000 })
+ .toBeGreaterThanOrEqual(1)
+ await test.info().attach('host-restart', {
+ contentType: 'application/json',
+ body: JSON.stringify({ before, after }),
+ })
+ })
+
+ await test.step('owner download after the restart is a new receipt R2', async () => {
+ r2 = await analyzeByPath(page, resourceId, reviewer)
+ expect(r2, 'an adopted copy must not be reused').not.toBe(r1)
+ const copy = hostReceiptCopy(fixtures.agent, r2)
+ expect(copy.sha256).toBe(expectedSha256)
+ expect(copy.userKey, 'the same user downloads into the same user directory').toBe(ownerKey)
+ })
+ })
+
+ await test.step('named precondition: a second user with read access to the folder', () => {
+ const secondUserId = ensureSecondUser(OWNER_EMAIL, fixtures.agent.name)
+ seedGfsGrant({
+ resourceId: fixtures.granted.resourceId,
+ subjectType: 'user',
+ subjectId: secondUserId,
+ permissions: ['read'],
+ inherit: true,
+ grantedBy: 'e2e:gfs-agent-large-file',
+ })
+ })
+
+ await withDesktop(SECOND_USER_EMAIL, 'second-user', async (page, reviewer) => {
+ await test.step('second user download R3 is separate from the owner copy', async () => {
+ const r3 = await analyzeByPath(page, resourceId, reviewer)
+ expect(r3, 'another user never reuses the owner receipt').not.toBe(r2)
+ const copy = hostReceiptCopy(fixtures.agent, r3)
+ expect(copy.sha256).toBe(expectedSha256)
+ expect(copy.userKey, 'each user downloads into its own user directory').not.toBe(ownerKey)
+ // The owner's copy is still in place: R3 did not replace it.
+ expect(hostReceiptCopy(fixtures.agent, r2).userKey).toBe(ownerKey)
+ })
+ })
+ })
})