Skip to content

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

TypeScript

test(e2e): make the #666 Playwright journey observe the file reference path

Alfredo Lopezd59ec726f33e
diff --git a/desktop-app/test/e2e-playwright/gfs-agent-file-read.test.ts b/desktop-app/test/e2e-playwright/gfs-agent-file-read.test.ts
index ea87e2748..a9535fe35 100644
--- a/desktop-app/test/e2e-playwright/gfs-agent-file-read.test.ts
+++ b/desktop-app/test/e2e-playwright/gfs-agent-file-read.test.ts
@@ -19,8 +19,9 @@
* - Infra guard: gfsc unhealthy ⇒ the suite THROWS (never skips, never mocks).
*/
import { expect, test } from '@playwright/test'
+import { kubectlOut } from '../../../tests/e2e/gfsUiFixtures'
import { exactNameFilter } from './helpers/agentLocators'
-import { getManagedAgentDisplayName } from './helpers/gfsAgentDiscovery'
+import { type ManagedGfsAgent, getManagedAgentDisplayName } from './helpers/gfsAgentDiscovery'
import {
type AgentGfsFixtures,
assertGfsInfraHealthy,
@@ -158,6 +159,96 @@ function toolStepRow(page: Page, toolName: string) {
.last()
}
+// The Host writes one JSON line per admitted message with file references
+// (mcp-host/src/agent/incomingAdmission.ts, `file_reference_resolved`),
+// serialized by mcp-host/src/logger.ts with JSON.stringify.
+const FILE_REFERENCE_RESOLVED_MARKER = '"event":"file_reference_resolved"'
+const KUBELET_TIMESTAMP = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/
+
+interface HostLogWindow {
+ pod: string
+ restartCount: string
+ since: string
+ baseline: number
+}
+
+/** The agent's one live Host pod; none or several fails the test. */
+function liveHostPod(agent: ManagedGfsAgent): string {
+ const pods = kubectlOut([
+ '-n',
+ agent.namespace,
+ 'get',
+ 'pods',
+ '-l',
+ `app=${agent.name}`,
+ '-o',
+ 'go-template={{range .items}}{{if not .metadata.deletionTimestamp}}{{.metadata.name}}{{"\\n"}}{{end}}{{end}}',
+ ])
+ .split('\n')
+ .map(line => line.trim())
+ .filter(Boolean)
+ const [pod] = pods
+ if (pods.length !== 1 || !pod) {
+ throw new Error(
+ `expected exactly one live Host pod for ${agent.namespace}/${agent.name}, found ${pods.length}: ${pods.join(', ')}`
+ )
+ }
+ return pod
+}
+
+function hostContainerRestarts(agent: ManagedGfsAgent, pod: string): string {
+ const restarts = kubectlOut([
+ '-n',
+ agent.namespace,
+ 'get',
+ 'pod',
+ pod,
+ '-o',
+ 'jsonpath={.status.containerStatuses[?(@.name=="mcp-host")].restartCount}',
+ ]).trim()
+ if (!/^\d+$/.test(restarts)) {
+ throw new Error(`Host pod ${agent.namespace}/${pod} has no mcp-host container status`)
+ }
+ return restarts
+}
+
+function hostLogLinesSince(agent: ManagedGfsAgent, pod: string, since: string): string[] {
+ return kubectlOut(
+ ['-n', agent.namespace, 'logs', `pod/${pod}`, '-c', 'mcp-host', `--since-time=${since}`],
+ 30_000
+ ).split('\n')
+}
+
+function fileReferenceResolvedLines(lines: string[]): string[] {
+ return lines.filter(line => line.includes(FILE_REFERENCE_RESOLVED_MARKER))
+}
+
+/**
+ * Anchors a log window at the Host's newest line (kubelet clock, so host/VM
+ * clock skew cannot hide the event) and counts the events already in it. Only
+ * the window is read, never the whole container log.
+ */
+function openHostLogWindow(agent: ManagedGfsAgent): HostLogWindow {
+ const pod = liveHostPod(agent)
+ const restartCount = hostContainerRestarts(agent, pod)
+ const newest = kubectlOut([
+ '-n',
+ agent.namespace,
+ 'logs',
+ `pod/${pod}`,
+ '-c',
+ 'mcp-host',
+ '--tail=1',
+ '--timestamps',
+ ]).trim()
+ const since = newest.split(' ', 1)[0] ?? ''
+ if (!KUBELET_TIMESTAMP.test(since)) {
+ throw new Error(`Host pod ${agent.namespace}/${pod} has no timestamped log line to anchor on`)
+ }
+ const baseline = fileReferenceResolvedLines(hostLogLinesSince(agent, pod, since)).length
+ return { pod, restartCount, since, baseline }
+}
+
test.describe('GFS agent file read (issue #775)', () => {
test.describe.configure({ mode: 'serial' })
@@ -242,14 +333,24 @@ test.describe('GFS agent file read (issue #775)', () => {
// Issue #666: the Global Files picker sends the selection as a structured
// FileReference; the Host resolves it and lists it in the turn context. The
// message names no file, so the read can only come from the reference.
- // Requires a renderer built with VITE_SHOW_GLOBAL_FILE_SYSTEM_COMPOSER_ITEM=true.
+ // Requires a renderer built with VITE_SHOW_GLOBAL_FILE_SYSTEM_COMPOSER_ITEM=true
+ // (scripts/e2e/playwright-dev.sh exports it before the Desktop build).
test('agent reads a file selected in the Global Files picker (#666)', async () => {
const { app, page } = await launchAndLogin(OWNER_EMAIL)
try {
- await test.step('user attaches the file from the Global Files picker', async () => {
+ await test.step('precondition: renderer built with the Global Files composer item', async () => {
await enterAgentChat(page, agentLabel)
await startFreshThread(page)
await page.getByRole('button', { name: 'Add context' }).click()
+ await expect(
+ page.getByRole('menuitem', { name: 'Global File System' }),
+ 'The "Add context" menu has no "Global File System" item: the Desktop renderer was ' +
+ 'built without VITE_SHOW_GLOBAL_FILE_SYSTEM_COMPOSER_ITEM=true. Rebuild the renderer ' +
+ 'with that flag (scripts/e2e/playwright-dev.sh exports it) and rerun.'
+ ).toBeVisible({ timeout: 5_000 })
+ })
+
+ await test.step('user attaches the file from the Global Files picker', async () => {
await page.getByRole('menuitem', { name: 'Global File System' }).click()
const picker = page.getByRole('dialog', { name: 'Choose files for this message' })
await expect(picker).toBeVisible({ timeout: 10_000 })
@@ -266,7 +367,9 @@ test.describe('GFS agent file read (issue #775)', () => {
})
let expandBtn: import('@playwright/test').Locator
+ let hostLog: HostLogWindow
await test.step('agent reads the attached file', async () => {
+ hostLog = openHostLogWindow(fixtures.agent)
const result = await sendGfsTask(
page,
'Quote the contents of the attached file verbatim. Do not answer from memory.'
@@ -289,6 +392,26 @@ test.describe('GFS agent file read (issue #775)', () => {
await expect(readOutput).toBeVisible({ timeout: 10_000 })
await expect(readOutput).toContainText(`E2E GFS file fixture: ${fixtures.granted.name}`)
})
+
+ await test.step('Host log proves it resolved the reference', async () => {
+ // The same container must have served the turn, or the window
+ // anchored before the send would belong to a different log.
+ expect(liveHostPod(fixtures.agent), 'Host pod replaced during the turn').toBe(hostLog.pod)
+ expect(
+ hostContainerRestarts(fixtures.agent, hostLog.pod),
+ 'mcp-host container restarted during the turn'
+ ).toBe(hostLog.restartCount)
+ const events = fileReferenceResolvedLines(
+ hostLogLinesSince(fixtures.agent, hostLog.pod, hostLog.since)
+ )
+ expect(events.length).toBeGreaterThan(hostLog.baseline)
+ const newest = JSON.parse(events[events.length - 1] as string) as {
+ referenceCount?: unknown
+ availabilities?: unknown
+ }
+ expect(newest.referenceCount).toBe(1)
+ expect(newest.availabilities).toEqual(['available'])
+ })
} finally {
await app.close()
}
diff --git a/scripts/e2e/playwright-dev.sh b/scripts/e2e/playwright-dev.sh
index 9e5c439c3..e72c03a35 100755
--- a/scripts/e2e/playwright-dev.sh
+++ b/scripts/e2e/playwright-dev.sh
@@ -196,6 +196,10 @@ cd "$REPO/desktop-app"
if [[ "${E2E_SKIP_DESKTOP_BUILD:-0}" != "1" ]]; then
echo "[playwright-dev] Building Desktop App before Playwright so dist/ui-dist matches the current worktree"
+ # gfs-agent-file-read.test.ts (#666) selects Global Files through the
+ # composer's "Global File System" item, which the renderer shows only when
+ # this build-time flag is set. No spec depends on the item being absent.
+ export VITE_SHOW_GLOBAL_FILE_SYSTEM_COMPOSER_ITEM=true
npm run build
fi