Skip to content

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

TypeScript

test(e2e): verify Electron GFS downloads as artifacts

Alfredo Lopez0ce4e4185824
diff --git a/desktop-app/test/e2e-playwright/gfs-desktop-operator-parity.test.ts b/desktop-app/test/e2e-playwright/gfs-desktop-operator-parity.test.ts
index 0b72fb788..83d87707d 100644
--- a/desktop-app/test/e2e-playwright/gfs-desktop-operator-parity.test.ts
+++ b/desktop-app/test/e2e-playwright/gfs-desktop-operator-parity.test.ts
@@ -1,4 +1,5 @@
import type { Locator, Page } from '@playwright/test'
+import { createHash } from 'node:crypto'
import { UUID_RE } from '../../../tests/e2e/gfsFixtureCore'
import { GFS_OPERATOR_SETUP_PATH } from './gfsDesktopOperatorParityContract'
import {
@@ -348,12 +349,35 @@ test.describe.serial('GFS Desktop linked-operator parity', () => {
await dialog
.getByRole('button', { name: `Options for ${operatorJourney.names.renamedFile}` })
.click()
- const downloadPromise = page.waitForEvent('download')
await page.getByRole('menuitem', { name: 'Download', exact: true }).click()
- const download = await downloadPromise
- expect(download.suggestedFilename()).toBe(operatorJourney.names.renamedFile)
- await download.saveAs(testInfo.outputPath(operatorJourney.names.renamedFile))
await expectToast(page, `Downloaded ${operatorJourney.names.renamedFile}`)
+ const expectedDownloadBytes = Buffer.from('# nested version two\n', 'utf8')
+ const expectedDownloadHash = createHash('sha256').update(expectedDownloadBytes).digest('hex')
+ await expect
+ .poll(
+ () =>
+ operatorJourney.readDownloadedArtifact(
+ operatorJourney.names.renamedFile,
+ expectedDownloadBytes
+ ),
+ { timeout: 30_000, intervals: [250, 500, 1_000] }
+ )
+ .toMatchObject({
+ filename: operatorJourney.names.renamedFile,
+ size: expectedDownloadBytes.byteLength,
+ sha256: expectedDownloadHash,
+ })
+ const downloadEvidence = operatorJourney.readDownloadedArtifact(
+ operatorJourney.names.renamedFile,
+ expectedDownloadBytes
+ )
+ if (!downloadEvidence) {
+ throw new Error('[GFS-OPERATOR-E2E] downloaded artifact disappeared after verification')
+ }
+ await testInfo.attach('gfs-download-evidence', {
+ body: JSON.stringify(downloadEvidence, null, 2),
+ contentType: 'application/json',
+ })
await dialog
.getByRole('button', { name: `Options for ${operatorJourney.names.renamedFile}` })
diff --git a/desktop-app/test/e2e-playwright/helpers/gfsDesktopOperatorParityFixtures.ts b/desktop-app/test/e2e-playwright/helpers/gfsDesktopOperatorParityFixtures.ts
index 6924d81f6..ec9ed310c 100644
--- a/desktop-app/test/e2e-playwright/helpers/gfsDesktopOperatorParityFixtures.ts
+++ b/desktop-app/test/e2e-playwright/helpers/gfsDesktopOperatorParityFixtures.ts
@@ -270,8 +270,10 @@ export class GfsDesktopOperatorJourney {
operatorContext: BrowserContext | null = null
operatorUserDataDir: string | null = null
operatorVideoDir: string | null = null
+ operatorDownloadsDir: string | null = null
private operatorSessionSequence = 0
private readonly operatorUserDataDirs = new Set<string>()
+ private readonly operatorDownloadsDirs = new Set<string>()
operatorLink: OperatorLinkRow | null = null
ordinaryUserId: string | null = null
ordinaryTeamId: string | null = null
@@ -368,6 +370,18 @@ export class GfsDesktopOperatorJourney {
cleanupErrors.push(error)
}
}
+ for (const downloadsDir of this.operatorDownloadsDirs) {
+ try {
+ const resolved = path.resolve(downloadsDir)
+ const allowedRoot = path.resolve(this.workerInfo.project.outputDir)
+ if (!resolved.startsWith(`${allowedRoot}${path.sep}`)) {
+ throw new Error(`refusing to remove downloads outside ${allowedRoot}`)
+ }
+ if (fs.existsSync(resolved)) fs.rmSync(resolved, { recursive: true })
+ } catch (error) {
+ cleanupErrors.push(error)
+ }
+ }
if (cleanupErrors.length > 0) {
throw new AggregateError(cleanupErrors, 'GFS operator E2E cleanup did not complete')
}
@@ -783,9 +797,12 @@ export class GfsDesktopOperatorJourney {
const sessionTag = `${this.runTag}-${this.operatorSessionSequence}`
this.operatorUserDataDir = path.join(outputRoot, `gfs-operator-user-data-${sessionTag}`)
this.operatorVideoDir = path.join(outputRoot, `gfs-operator-video-${sessionTag}`)
+ this.operatorDownloadsDir = path.join(outputRoot, `gfs-operator-downloads-${sessionTag}`)
this.operatorUserDataDirs.add(this.operatorUserDataDir)
+ this.operatorDownloadsDirs.add(this.operatorDownloadsDir)
fs.mkdirSync(this.operatorUserDataDir, { recursive: true })
fs.mkdirSync(this.operatorVideoDir, { recursive: true })
+ fs.mkdirSync(this.operatorDownloadsDir, { recursive: true })
this.operatorApp = await electron.launch({
args: [`--user-data-dir=${this.operatorUserDataDir}`, MAIN_ENTRY],
env: {
@@ -798,6 +815,18 @@ export class GfsDesktopOperatorJourney {
},
recordVideo: { dir: this.operatorVideoDir, size: { width: 1280, height: 720 } },
})
+ const configuredDownloadsDir = await this.operatorApp.evaluate(
+ ({ app: electronApp }, downloadsDir) => {
+ electronApp.setPath('downloads', downloadsDir)
+ return electronApp.getPath('downloads')
+ },
+ this.operatorDownloadsDir
+ )
+ if (path.resolve(configuredDownloadsDir) !== path.resolve(this.operatorDownloadsDir)) {
+ throw new Error(
+ `[GFS-OPERATOR-E2E] Electron did not honor the isolated downloads directory: expected ${this.operatorDownloadsDir}, got ${configuredDownloadsDir}`
+ )
+ }
this.operatorContext = this.operatorApp.context()
this.operatorPage = await this.operatorApp.firstWindow()
this.liveDesktopPages.add(this.operatorPage)
@@ -806,6 +835,32 @@ export class GfsDesktopOperatorJourney {
return this.operatorPage
}
+ readDownloadedArtifact(
+ expectedName: string,
+ expectedBytes: Buffer
+ ): {
+ filename: string
+ size: number
+ sha256: string
+ relativePath: string
+ } | null {
+ if (!this.operatorDownloadsDir) {
+ throw new Error('[GFS-OPERATOR-E2E] operator downloads directory is not initialized')
+ }
+ const entries = fs.readdirSync(this.operatorDownloadsDir, { withFileTypes: true })
+ const files = entries.filter(entry => entry.isFile()).map(entry => entry.name)
+ if (files.length !== 1 || files[0] !== expectedName) return null
+ const filePath = path.join(this.operatorDownloadsDir, expectedName)
+ const bytes = fs.readFileSync(filePath)
+ if (!bytes.equals(expectedBytes)) return null
+ return {
+ filename: expectedName,
+ size: bytes.byteLength,
+ sha256: createHash('sha256').update(bytes).digest('hex'),
+ relativePath: path.relative(this.workerInfo.project.outputDir, filePath),
+ }
+ }
+
async closeOperatorDesktop(): Promise<void> {
const app = this.operatorApp
const page = this.operatorPage