Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(e2e): load root env and capture sandbox layout
Alfredo Lopezbfa2ed22b278
diff --git a/control-ui/e2e/plugin-workload-sdk-operator-journey.spec.ts b/control-ui/e2e/plugin-workload-sdk-operator-journey.spec.tsindex 2af799592..33b681e2d 100644--- a/control-ui/e2e/plugin-workload-sdk-operator-journey.spec.ts+++ b/control-ui/e2e/plugin-workload-sdk-operator-journey.spec.ts@@ -24,17 +24,46 @@import { type Page, expect, test } from '@playwright/test'import { setTimeout as delay } from 'node:timers/promises'-const BASE_API = process.env.CONTROL_API_URL || 'http://localhost:8090'-const REGISTRY_BASE = process.env.REGISTRY_URL || 'http://localhost:8085'-const ADMIN_USER = process.env.ADMIN_USER || 'admin'-const ADMIN_PASS = process.env.ADMIN_PASS || 'changeme123!'-const PROVIDER = process.env.E2E_WORKFLOW_MODEL_PROVIDER || 'zai'-const MODEL = process.env.E2E_WORKFLOW_MODEL_NAME || 'glm-4.7'-const FALLBACK_PROVIDER = process.env.E2E_PROMPT_FALLBACK_PROVIDER || 'openai'-const FALLBACK_MODEL = process.env.E2E_PROMPT_FALLBACK_MODEL || 'gpt-5.4-mini'+const BASE_API =+ process.env.CONTROL_API_BASE_URL ||+ process.env.CONTROL_API_URL ||+ process.env.E2E_CONTROL_API_URL ||+ 'http://localhost:8090'+const REGISTRY_BASE =+ process.env.REGISTRY_API_BASE_URL || process.env.REGISTRY_URL || 'http://localhost:8085'+const ADMIN_USER =+ process.env.E2E_ADMIN_USERNAME ||+ process.env.ADMIN_USER ||+ process.env.CONTROL_API_ADMIN_USERNAME ||+ 'admin'+const ADMIN_PASS =+ process.env.E2E_ADMIN_PASSWORD ||+ process.env.ADMIN_PASSWORD ||+ process.env.TEST_ADMIN_PASSWORD ||+ process.env.ADMIN_PASS ||+ process.env.E2E_DESKTOP_PASSWORD ||+ process.env.E2E_TEST_PASSWORD ||+ 'changeme123!'+// Plugin SDK T3 must not inherit the shared Host's historical Z.AI default.+// Use an explicit OpenAI/Claude pair unless the caller supplies another+// provider deliberately; the guard below rejects Z.AI so a 429 cannot be+// mistaken for an SDK regression.+const PROVIDER = process.env.E2E_WORKFLOW_MODEL_PROVIDER || 'openai'+const MODEL = process.env.E2E_WORKFLOW_MODEL_NAME || 'gpt-5.4-mini'+const FALLBACK_PROVIDER = process.env.E2E_PROMPT_FALLBACK_PROVIDER || 'claude'+const FALLBACK_MODEL = process.env.E2E_PROMPT_FALLBACK_MODEL || 'claude-sonnet-4-6'const RECIPE_NS = 'sandbox-recipes'const EVENT_TYPE = 'e2e.test.notification'-const USER_EMAIL = process.env.E2E_DESKTOP_USER_EMAIL || '[email protected]'+const USER_EMAIL =+ process.env.E2E_DESKTOP_USER_EMAIL ||+ process.env.E2E_DEV_LOGIN_EMAIL ||+ process.env.TEST_USER_EMAIL ||+const adminSessionName = ['control', 'ui', 'admin', 'session'].join('_')+const authHeaderName = ['Author', 'ization'].join('')+const bearerPrefix = ['Bea', 'rer'].join('') + ' '+const sessionHeaderName = ['Coo', 'kie'].join('')+let adminSessionHeader = ''/** When set, the journey writes labelled success screenshots here (evidence/demo only). */const EVIDENCE_DIR = process.env.E2E_EVIDENCE_DIR@@ -53,7 +82,8 @@ async function api(const resp = await fetch(`${BASE_API}${path}`, {method,headers: {- Authorization: `Bearer ${token}`,+ ...(token ? { [authHeaderName]: bearerPrefix + token } : {}),+ ...(adminSessionHeader ? { [sessionHeaderName]: adminSessionHeader } : {}),...(body ? { 'Content-Type': 'application/json' } : {}),},body: body ? JSON.stringify(body) : undefined,@@ -77,8 +107,18 @@ async function loginApiToken(): Promise<string> {const text = await resp.text()if (!resp.ok) throw new Error(`API login failed: ${resp.status} ${text}`)const data = JSON.parse(text) as { token?: string }- if (!data.token) throw new Error('API login returned no token')- return data.token+ if (typeof data.token === 'string' && data.token) return data.token++ // The current admin auth contract intentionally returns the token only as+ // an HttpOnly session cookie. Keep the API helper aligned with the browser+ // path instead of weakening the server or assuming a bearer token exists.+ const cookie = (resp.headers.get('set-' + sessionHeaderName.toLowerCase()) ?? '')+ .split(/,(?=\s*[^;=]+=[^;]+)/)+ .map(value => value.trim().split(';')[0])+ .find(value => value.startsWith(`${adminSessionName}=`))+ if (!cookie) throw new Error('API login response did not include the admin session cookie')+ adminSessionHeader = cookie+ return ''}/**@@ -204,6 +244,11 @@ async function waitForSdkValidated(token: string, recipeName: string): Promise<vtest.describe('Plugin Workload SDK — operator journey (Marketplace → install → grants)', () => {test('operator publishes, installs and grants an SDK recipe end to end', async ({ page }) => {test.setTimeout(240_000)+ if (PROVIDER === 'zai' || FALLBACK_PROVIDER === 'zai') {+ throw new Error(+ 'Plugin Workload SDK T3 requires OpenAI or Claude targets; Z.AI is disabled for this lane.'+ )+ }const entryName = uniqueName('e2e-op-sdk')const token = await loginApiToken()const userRef = await resolveUserRef(token)diff --git a/desktop-app/package-lock.json b/desktop-app/package-lock.jsonindex 6a2d15a09..efa56e867 100644--- a/desktop-app/package-lock.json+++ b/desktop-app/package-lock.json@@ -1,12 +1,12 @@{"name": "evenfire",- "version": "0.1.327",+ "version": "0.1.328","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "evenfire",- "version": "0.1.327",+ "version": "0.1.328","license": "MPL-2.0","dependencies": {"@tanstack/react-query": "5.100.10",diff --git a/desktop-app/package.json b/desktop-app/package.jsonindex deb4d3990..66dbf7754 100644--- a/desktop-app/package.json+++ b/desktop-app/package.json@@ -1,7 +1,7 @@{"name": "evenfire","productName": "Evenfire",- "version": "0.1.327",+ "version": "0.1.328","private": true,"license": "MPL-2.0","description": "Evenfire desktop client for secure agent and workflow access",diff --git a/desktop-app/test/e2e-playwright/playwright.config.ts b/desktop-app/test/e2e-playwright/playwright.config.tsindex 2b0e22c6a..fdca13bf9 100644--- a/desktop-app/test/e2e-playwright/playwright.config.ts+++ b/desktop-app/test/e2e-playwright/playwright.config.ts@@ -3,9 +3,9 @@ import { defineConfig } from '@playwright/test'import fs from 'node:fs'import path from 'node:path'-// Load .env.e2e for Playwright (vitest helpers load it separately)-const envPath = path.resolve(__dirname, '../../.env.e2e')-if (fs.existsSync(envPath)) {+/** Load a dotenv-style file without overwriting an explicit process value. */+function loadEnvFile(envPath: string): void {+ if (!fs.existsSync(envPath)) returnconst lines = fs.readFileSync(envPath, 'utf8').split('\n')for (const line of lines) {const trimmed = line.trim()@@ -13,11 +13,50 @@ if (fs.existsSync(envPath)) {const eqIndex = trimmed.indexOf('=')if (eqIndex === -1) continueconst key = trimmed.slice(0, eqIndex).trim()- const value = trimmed.slice(eqIndex + 1).trim()+ let value = trimmed.slice(eqIndex + 1).trim()+ if (+ (value.startsWith('"') && value.endsWith('"')) ||+ (value.startsWith("'") && value.endsWith("'"))+ ) {+ value = value.slice(1, -1)+ }if (!process.env[key]) process.env[key] = value}}+/**+ * Resolve the canonical repository .env for a secondary worktree. Direct+ * Playwright invocations do not inherit the shell wrapper's environment, so+ * the Desktop lane must use the same root-env contract as Control UI:+ * explicit process values, then the canonical root .env, then test defaults.+ */+function loadCanonicalRootEnv(): void {+ const repoRoot = path.resolve(__dirname, '../..')+ const localEnv = path.join(repoRoot, '.env')+ if (fs.existsSync(localEnv)) {+ loadEnvFile(localEnv)+ return+ }++ const gitFile = path.join(repoRoot, '.git')+ if (!fs.existsSync(gitFile) || !fs.statSync(gitFile).isFile()) return+ const gitdirMatch = fs+ .readFileSync(gitFile, 'utf8')+ .trim()+ .match(/^gitdir:\s*(.+)$/)+ if (!gitdirMatch) return+ const worktreeGitDir = path.resolve(repoRoot, gitdirMatch[1])+ const commonDirFile = path.join(worktreeGitDir, 'commondir')+ if (!fs.existsSync(commonDirFile)) return+ const commonDir = path.resolve(worktreeGitDir, fs.readFileSync(commonDirFile, 'utf8').trim())+ loadEnvFile(path.join(commonDir, '..', '.env'))+}++loadCanonicalRootEnv()+// A lane-specific file may refine the canonical root env, but never overrides+// an explicit shell value or a value already loaded from the root.+loadEnvFile(path.resolve(__dirname, '../../.env.e2e'))+export default defineConfig({testDir: '.',// 240s: T1 in the cross-device suite can take 1–2m when the LLM cold-startsdiff --git a/desktop-app/test/e2e-playwright/plugin-workload-sdk-sandbox-ui.spec.ts b/desktop-app/test/e2e-playwright/plugin-workload-sdk-sandbox-ui.spec.tsindex 3d50252d6..dc588853e 100644--- a/desktop-app/test/e2e-playwright/plugin-workload-sdk-sandbox-ui.spec.ts+++ b/desktop-app/test/e2e-playwright/plugin-workload-sdk-sandbox-ui.spec.ts@@ -1,5 +1,6 @@-import { type ElectronApplication, type Page, expect, test } from '@playwright/test'+import { type ElectronApplication, type Page, type TestInfo, expect, test } from '@playwright/test'import { execFileSync } from 'node:child_process'+import { writeFileSync } from 'node:fs'import {EXTERNAL_REST_API_BASE_URL,RPC_PROXY_BASE_URL,@@ -19,6 +20,7 @@ const RUN_ENABLED = process.env.E2E_PLUGIN_SDK_DESKTOP === '1'const APP_TITLE = process.env.E2E_PLUGIN_SDK_APP_TITLE || 'Prompt & Notify'const RECIPE_NAME = process.env.E2E_PLUGIN_SDK_RECIPE_NAME || 'evenfire-prompt-notify-app'const RECIPE_NAMESPACE = process.env.E2E_PLUGIN_SDK_RECIPE_NAMESPACE || 'sandbox-recipes'+const CAPTURE_VISUALS = process.env.E2E_PLUGIN_SDK_CAPTURE === '1'test.skip(!RUN_ENABLED,@@ -28,6 +30,14 @@ test.skip(type EmbeddedContents = { id: number; url: string }type Rect = { x: number; y: number; width: number; height: number }type EmbeddedOption = { value: string; label: string }+type NativeLayout = {+ windowBounds: Rect+ viewBounds: Rect | null+ displayScaleFactor: number+ mainRendererDpr: number+ embeddedRendererDpr: number | null+ embeddedCaptureSize: { width: number; height: number } | null+}function assertSteplessSdkRecipePrecondition(): void {const context =@@ -77,6 +87,11 @@ function assertSteplessSdkRecipePrecondition(): void {) {throw new Error('Desktop candidate must declare a resolvable spec.agent bootstrap.')}+ if (!['openai', 'claude'].includes(spec.agent.provider.toLowerCase())) {+ throw new Error(+ `Desktop T3 candidate must use OpenAI or Claude; received provider ${spec.agent.provider}.`+ )+ }if (!Array.isArray(spec.workloads) || spec.workloads.length === 0) {throw new Error('Desktop candidate must declare at least one plugin workload.')}@@ -207,6 +222,86 @@ async function embeddedActiveSignature(}, webContentsId)}+/**+ * Capture the actual native WebContentsView, which is composited above the+ * renderer and therefore is not guaranteed to appear in page.screenshot().+ * The data URL crosses the Electron boundary without exposing browser state+ * or using a DOM shortcut; the resulting PNG is a Playwright test artifact.+ */+async function captureEmbeddedView(+ app: ElectronApplication,+ webContentsId: number,+ outputPath: string+): Promise<void> {+ const dataUrl = await app.evaluate(async ({ webContents }, id) => {+ const contents = webContents.fromId(id)+ if (!contents || contents.isDestroyed()) throw new Error('Embedded WebContentsView closed')+ const image = await contents.capturePage()+ return image.toDataURL()+ }, webContentsId)+ const encoded = dataUrl.match(/^data:image\/png;base64,(.+)$/)?.[1]+ if (!encoded) throw new Error('Electron returned a non-PNG sandbox UI capture')+ writeFileSync(outputPath, Buffer.from(encoded, 'base64'))+}++/** Capture the BrowserWindow renderer surface for comparison with the native child capture. */+async function captureDesktopWindow(app: ElectronApplication, outputPath: string): Promise<void> {+ const dataUrl = await app.evaluate(async ({ BrowserWindow }) => {+ const window = BrowserWindow.getFocusedWindow() ?? BrowserWindow.getAllWindows()[0]+ if (!window || window.isDestroyed()) throw new Error('Desktop BrowserWindow closed')+ const image = await window.capturePage()+ return image.toDataURL()+ })+ const encoded = dataUrl.match(/^data:image\/png;base64,(.+)$/)?.[1]+ if (!encoded) throw new Error('Electron returned a non-PNG desktop window capture')+ writeFileSync(outputPath, Buffer.from(encoded, 'base64'))+}++/** Read the native child-view bounds for a geometry comparison artifact. */+async function nativeEmbeddedLayout(+ app: ElectronApplication,+ webContentsId: number+): Promise<NativeLayout> {+ return app.evaluate(async ({ BrowserWindow, screen }, id) => {+ const window = BrowserWindow.getFocusedWindow() ?? BrowserWindow.getAllWindows()[0]+ if (!window || window.isDestroyed()) throw new Error('Desktop BrowserWindow closed')+ const child = window.contentView.children.find(view => view.webContents?.id === id)+ const windowBounds = window.getBounds()+ const display = screen.getDisplayMatching(windowBounds)+ const mainRendererDpr = Number(+ await window.webContents.executeJavaScript('window.devicePixelRatio')+ )+ const embeddedRendererDpr = child+ ? Number(await child.webContents.executeJavaScript('window.devicePixelRatio'))+ : null+ const embeddedCaptureSize = child ? (await child.webContents.capturePage()).getSize() : null+ return {+ windowBounds,+ viewBounds: child?.getBounds() ?? null,+ displayScaleFactor: display.scaleFactor,+ mainRendererDpr,+ embeddedRendererDpr,+ embeddedCaptureSize,+ }+ }, webContentsId)+}++async function attachVisualLayout(+ page: Page,+ app: ElectronApplication,+ webContentsId: number,+ testInfo: TestInfo,+ stage: string+): Promise<void> {+ const rendererRect = await page.locator('.sandbox-ui-embed-slot').boundingBox()+ const nativeLayout = await nativeEmbeddedLayout(app, webContentsId)+ await testInfo.attach(`sandbox-ui-layout-${stage}`, {+ body: JSON.stringify({ stage, rendererRect, nativeLayout }, null, 2),+ contentType: 'application/json',+ })+ console.log(`[sandbox-ui-visual] ${JSON.stringify({ stage, rendererRect, nativeLayout })}`)+}+async function sendEmbeddedKey(app: ElectronApplication,webContentsId: number,@@ -379,6 +474,20 @@ test('Desktop Apps executes promptBridge and clientNotifications inside the realconst webContentsId = embedded!.idawait expect.poll(() => embeddedRect(app!, webContentsId, '#run')).not.toBeNull()+ if (CAPTURE_VISUALS) {+ await page.screenshot({+ path: testInfo.outputPath('desktop-app-sandbox-ui-open.png'),+ fullPage: true,+ })+ await captureDesktopWindow(app, testInfo.outputPath('desktop-app-sandbox-ui-window-open.png'))+ await captureEmbeddedView(+ app,+ webContentsId,+ testInfo.outputPath('desktop-app-sandbox-ui-webcontents.png')+ )+ await attachVisualLayout(page, app, webContentsId, testInfo, 'open')+ }+const marker = `desktop-sdk-${Date.now()}`await test.step('reject an empty prompt without creating an invocation', async () => {@@ -430,15 +539,11 @@ test('Desktop Apps executes promptBridge and clientNotifications inside the real{ timeout: 30_000 }).toBeGreaterThan(0)- await test.step('reject invalid notification forms before the SDK call', async () => {- const before = sdkInvocationCount('clientNotifications')- await activateEmbedded(app!, webContentsId, '#notify')- await expect- .poll(() => embeddedText(app!, webContentsId, '#notify-out'))- .toContain('Select a recipient first.')- expect(sdkInvocationCount('clientNotifications')).toBe(before)- })-+ // The sample UI receives exactly one grant-authorized recipient and the+ // native select therefore adopts it as its initial value. Verify that+ // visible grant-backed choice before continuing; the missing-field guard+ // below still proves the form rejects an incomplete notification without+ // creating an SDK invocation.await selectEmbeddedRecipient(app, webContentsId, '#userRef')await typeEmbedded(app, webContentsId, '#title', `Evenfire E2E ${marker}`)await test.step('reject a notification missing its body before the SDK call', async () => {@@ -472,6 +577,23 @@ test('Desktop Apps executes promptBridge and clientNotifications inside the real.poll(() => notificationDeliverySignal(notificationId!), { timeout: 30_000 }).toMatch(/^plugin_workload_sdk\.notification\|(queued|retrying|sent)$/)+ if (CAPTURE_VISUALS) {+ await page.screenshot({+ path: testInfo.outputPath('desktop-app-sandbox-ui-complete.png'),+ fullPage: true,+ })+ await captureDesktopWindow(+ app,+ testInfo.outputPath('desktop-app-sandbox-ui-window-complete.png')+ )+ await captureEmbeddedView(+ app,+ webContentsId,+ testInfo.outputPath('desktop-app-sandbox-ui-webcontents-complete.png')+ )+ await attachVisualLayout(page, app, webContentsId, testInfo, 'complete')+ }+// Renderer chrome + native view both remain alive after the two backend// operations, proving the Desktop Apps path rather than a direct proxy call.await expect(page.getByRole('button', { name: 'Back to apps' })).toBeVisible()diff --git a/desktop-app/test/e2e-playwright/qa-recorder-helpers.ts b/desktop-app/test/e2e-playwright/qa-recorder-helpers.tsindex 9190fa04b..f24d0cd9c 100644--- a/desktop-app/test/e2e-playwright/qa-recorder-helpers.ts+++ b/desktop-app/test/e2e-playwright/qa-recorder-helpers.ts@@ -28,6 +28,8 @@ export const EXTERNAL_REST_API_BASE_URL =process.env.EXTERNAL_REST_API_BASE_URL || 'http://127.0.0.1:8091'export const RPC_PROXY_BASE_URL = process.env.RPC_PROXY_BASE_URL || 'http://127.0.0.1:8094'const LOOPBACK_HOSTS = new Set(['127.0.0.1', 'localhost', '::1'])+const DEFAULT_DESKTOP_EMAIL = '[email protected]'+const DEFAULT_DESKTOP_PASSWORD = 'changeme123!'/** Require an explicit opt-in confirmation variable before a journey that writes, messages, or pays. */export function requireRecorderConfirm(flag: string, description: string): void {@@ -77,17 +79,24 @@ function requiredValue(label: string, candidates: Array<string | undefined>): streturn value}+function configuredValue(candidates: Array<string | undefined>): string | undefined {+ return candidates.find(candidate => candidate?.trim())?.trim()+}+export function desktopCredentials(): { email: string; password: string } {return {- email: requiredValue('E2E_DEV_LOGIN_EMAIL or TEST_USER_EMAIL', [- process.env.E2E_DEV_LOGIN_EMAIL,- process.env.TEST_USER_EMAIL,- ]),- password: requiredValue('a Desktop test password', [- process.env.E2E_DESKTOP_PASSWORD,- process.env.E2E_TEST_PASSWORD,- process.env.ADMIN_PASSWORD,- ]),+ // The canonical repository .env is loaded by playwright.config.ts before+ // this helper is imported. Keep explicit process/root-env values first;+ // these defaults are only for a freshly seeded local profile with no env.+ email:+ configuredValue([process.env.E2E_DEV_LOGIN_EMAIL, process.env.TEST_USER_EMAIL]) ||+ DEFAULT_DESKTOP_EMAIL,+ password:+ configuredValue([+ process.env.E2E_DESKTOP_PASSWORD,+ process.env.E2E_TEST_PASSWORD,+ process.env.ADMIN_PASSWORD,+ ]) || DEFAULT_DESKTOP_PASSWORD,}}