Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(desktop): cover sandbox fixture failure marker
Josuéffd1e0e58b2a
diff --git a/desktop-app/test/e2e-playwright/sdk-client-notification/sdkWorkloadFixture.ts b/desktop-app/test/e2e-playwright/sdk-client-notification/sdkWorkloadFixture.tsindex 09fcab3e4..6f49a728f 100644--- a/desktop-app/test/e2e-playwright/sdk-client-notification/sdkWorkloadFixture.ts+++ b/desktop-app/test/e2e-playwright/sdk-client-notification/sdkWorkloadFixture.ts@@ -297,7 +297,7 @@ export async function waitForSdkSandboxUiNotification(const logs = kubectl(['-n', RECIPE_NS, 'logs', pod, '--tail=80'], undefined, 30_000)const match = logs.match(/E2E_SDK_SANDBOX_UI_NOTIFICATION_OK=([0-9a-f-]{36})/i)if (match?.[1]) return match[1]- if (logs.includes('E2E_SDK_SANDBOX_UI_FAIL=')) {+ if (findSdkSandboxUiFailureMarker(logs)) {throw new Error(`sandbox-ui SDK producer failed:\n${logs.slice(-2_000)}`)}}@@ -306,6 +306,10 @@ export async function waitForSdkSandboxUiNotification(throw new Error(`sandbox-ui never emitted its client notification for recipe ${recipeName}`)}+export function findSdkSandboxUiFailureMarker(logs: string): string | null {+ return logs.match(/^E2E_SDK_SANDBOX_UI_FAIL=[^\r\n]+$/m)?.[0] ?? null+}+/*** Waits for the SDK caller to complete a promptBridge (LLM) round-trip and* returns the invocationId it logged. This is the business signal that thediff --git a/desktop-app/test/sandboxUiFixtureFailureMarker.test.ts b/desktop-app/test/sandboxUiFixtureFailureMarker.test.tsnew file mode 100644index 000000000..5ac216614--- /dev/null+++ b/desktop-app/test/sandboxUiFixtureFailureMarker.test.ts@@ -0,0 +1,177 @@+import { afterEach, describe, expect, it } from 'vitest'+import { type ChildProcess, spawn } from 'node:child_process'+import { once } from 'node:events'+import http from 'node:http'+import net from 'node:net'+import path from 'node:path'+import { findSdkSandboxUiFailureMarker } from './e2e-playwright/sdk-client-notification/sdkWorkloadFixture'++const REPO_ROOT = path.resolve(__dirname, '../..')+const FIXTURE_ENTRY = path.join(+ REPO_ROOT,+ 'tests/e2e/fixtures/workflow-plugin-sdk-e2e/src/index.js'+)++type RunningFixture = {+ logs: () => string+ stop: () => Promise<void>+ url: string+}++const fixtures: RunningFixture[] = []++async function freePort(): Promise<number> {+ const server = net.createServer()+ server.listen(0, '127.0.0.1')+ await once(server, 'listening')+ const address = server.address() as net.AddressInfo+ server.close()+ return address.port+}++async function listen(+ handler: http.RequestListener+): Promise<{ close: () => Promise<void>; url: string }> {+ const server = http.createServer(handler)+ server.listen(0, '127.0.0.1')+ await once(server, 'listening')+ const address = server.address() as net.AddressInfo+ return {+ close: async () => {+ server.close()+ await once(server, 'close')+ },+ url: `http://127.0.0.1:${address.port}`,+ }+}++async function startFixture(endpoint: string): Promise<RunningFixture> {+ const port = await freePort()+ let output = ''+ const child: ChildProcess = spawn(process.execPath, [FIXTURE_ENTRY], {+ env: {+ ...process.env,+ E2E_SDK_MODE: 'sandbox-ui',+ E2E_SDK_RUN_ID: 'test-run',+ E2E_SDK_SANDBOX_UI_MAX_ATTEMPTS: '1',+ E2E_SDK_USER_REF: 'test-user',+ PLUGIN_WORKLOAD_SDK_ENDPOINT: endpoint,+ PLUGIN_WORKLOAD_SDK_TOKEN: 'test-only-token',+ PORT: String(port),+ },+ stdio: ['ignore', 'pipe', 'pipe'],+ })+ child.stdout?.on('data', data => {+ output += data.toString()+ })+ child.stderr?.on('data', data => {+ output += data.toString()+ })+ const fixture: RunningFixture = {+ logs: () => output,+ stop: async () => {+ if (child.exitCode === null) {+ child.kill('SIGTERM')+ await once(child, 'exit')+ }+ },+ url: `http://127.0.0.1:${port}`,+ }+ fixtures.push(fixture)++ for (let attempt = 0; attempt < 50; attempt += 1) {+ try {+ if ((await fetch(`${fixture.url}/healthz`)).ok) return fixture+ } catch {+ // The fixture server is still starting.+ }+ await new Promise(resolve => setTimeout(resolve, 20))+ }+ throw new Error(`Sandbox UI fixture did not start: ${output}`)+}++async function runMissingEndpointFixture(): Promise<string> {+ let output = ''+ const child = spawn(process.execPath, [FIXTURE_ENTRY], {+ env: { ...process.env, E2E_SDK_MODE: 'sandbox-ui' },+ stdio: ['ignore', 'pipe', 'pipe'],+ })+ child.stdout?.on('data', data => {+ output += data.toString()+ })+ child.stderr?.on('data', data => {+ output += data.toString()+ })+ await once(child, 'exit')+ return output+}++afterEach(async () => {+ await Promise.all(fixtures.splice(0).map(fixture => fixture.stop()))+})++describe('Sandbox UI SDK fixture failure marker', () => {+ it('emits a safe failure marker that the waiter recognizes', async () => {+ const sdk = await listen((_request, response) => {+ response.writeHead(403, { 'content-type': 'application/json' })+ response.end(JSON.stringify({ error: 'caller_not_allowed' }))+ })+ try {+ const fixture = await startFixture(sdk.url)+ const response = await fetch(fixture.url)+ const body = await response.text()+ const logs = fixture.logs()++ expect(response.status).toBe(500)+ expect(body).toBe('Could not emit Sandbox UI notification.')+ expect(findSdkSandboxUiFailureMarker(logs)).toBe('E2E_SDK_SANDBOX_UI_FAIL=caller_not_allowed')+ expect(logs).not.toContain('test-only-token')+ } finally {+ await sdk.close()+ }+ })++ it('replaces unsafe failures with the constant marker', async () => {+ const unsafeError = 'upstream token=secret-value endpoint=https://internal.example'+ const sdk = await listen((_request, response) => {+ response.writeHead(500, { 'content-type': 'application/json' })+ response.end(JSON.stringify({ error: unsafeError }))+ })+ try {+ const fixture = await startFixture(sdk.url)+ const response = await fetch(fixture.url)+ const body = await response.text()+ const logs = fixture.logs()++ expect(response.status).toBe(500)+ expect(body).toBe('Could not emit Sandbox UI notification.')+ expect(findSdkSandboxUiFailureMarker(logs)).toBe(+ 'E2E_SDK_SANDBOX_UI_FAIL=notification_emit_failed'+ )+ expect(`${logs}\n${body}`).not.toContain(unsafeError)+ } finally {+ await sdk.close()+ }+ })++ it('preserves successful and missing-endpoint markers', async () => {+ const sdk = await listen((_request, response) => {+ response.writeHead(200, { 'content-type': 'application/json' })+ response.end(JSON.stringify({ notificationId: '11111111-1111-4111-8111-111111111111' }))+ })+ try {+ const fixture = await startFixture(sdk.url)+ const response = await fetch(fixture.url)++ expect(response.status).toBe(200)+ expect(fixture.logs()).toContain(+ 'E2E_SDK_SANDBOX_UI_NOTIFICATION_OK=11111111-1111-4111-8111-111111111111'+ )+ expect(await runMissingEndpointFixture()).toContain(+ 'E2E_SDK_SANDBOX_UI_FAIL=missing_endpoint_or_token'+ )+ } finally {+ await sdk.close()+ }+ })+})diff --git a/tests/e2e/fixtures/package-lock.json b/tests/e2e/fixtures/package-lock.jsonindex 2efdcc651..94f1ebf6c 100644--- a/tests/e2e/fixtures/package-lock.json+++ b/tests/e2e/fixtures/package-lock.json@@ -1,12 +1,12 @@{"name": "@clerum/e2e-test-fixtures",- "version": "1.0.57",+ "version": "1.0.58","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "@clerum/e2e-test-fixtures",- "version": "1.0.57",+ "version": "1.0.58","dependencies": {"@kubernetes/client-node": "^1.0.0"},diff --git a/tests/e2e/fixtures/package.json b/tests/e2e/fixtures/package.jsonindex bb03c2063..b86ee8892 100644--- a/tests/e2e/fixtures/package.json+++ b/tests/e2e/fixtures/package.json@@ -1,6 +1,6 @@{"name": "@clerum/e2e-test-fixtures",- "version": "1.0.57",+ "version": "1.0.58","description": "E2E test fixtures and utilities for Clerum testing","type": "module","main": "index.ts",diff --git a/tests/e2e/fixtures/workflow-plugin-sdk-e2e/src/index.js b/tests/e2e/fixtures/workflow-plugin-sdk-e2e/src/index.jsindex 3e13981ec..05d475af5 100644--- a/tests/e2e/fixtures/workflow-plugin-sdk-e2e/src/index.js+++ b/tests/e2e/fixtures/workflow-plugin-sdk-e2e/src/index.js@@ -18,8 +18,7 @@// E2E_SDK_QUOTA_EXCEEDED_OK (N+1 call correctly rejected)// E2E_SDK_QUOTA_EXCEEDED_FAIL=<reason>// E2E_SDK_DONE--const http = require('node:http')+import http from 'node:http'const ENDPOINT = process.env.PLUGIN_WORKLOAD_SDK_ENDPOINT || ''const TOKEN = process.env.PLUGIN_WORKLOAD_SDK_TOKEN || ''@@ -29,6 +28,7 @@ const USER_REF = process.env.E2E_SDK_USER_REF || 'e2e-test-user'const RUN_ID = process.env.E2E_SDK_RUN_ID || String(Date.now())const QUOTA_LIMIT = parseInt(process.env.E2E_SDK_QUOTA_LIMIT || '4', 10)const EXPLICIT_TARGET_REF = process.env.E2E_SDK_EXPLICIT_TARGET_REF || ''+const SANDBOX_UI_MAX_ATTEMPTS = parseInt(process.env.E2E_SDK_SANDBOX_UI_MAX_ATTEMPTS || '10', 10)// Every SDK request must fail closed if the server stops responding. The// outer shell gate also has bounded polling, but fetch itself otherwise has no// implicit deadline and could keep a fixture alive indefinitely.@@ -150,7 +150,7 @@ async function exerciseClientNotification() {* Desktop E2E establish its notification from the app it actually mounts.*/async function emitSandboxUiNotification() {- for (let attempt = 1; attempt <= 10; attempt++) {+ for (let attempt = 1; attempt <= SANDBOX_UI_MAX_ATTEMPTS; attempt++) {try {const { status, body } = await callSdk('/v1/client-notifications', {eventType: EVENT_TYPE,@@ -166,9 +166,11 @@ async function emitSandboxUiNotification() {return body.notificationId}const code = (body && (body.error || body.code)) || `http_${status}`- if (attempt === 10) throw new Error(`client notification failed: ${code}`)+ if (attempt === SANDBOX_UI_MAX_ATTEMPTS) {+ throw new Error(`client notification failed: ${code}`)+ }} catch (err) {- if (attempt === 10) throw err+ if (attempt === SANDBOX_UI_MAX_ATTEMPTS) throw err}await sleep(3000)}@@ -198,9 +200,7 @@ function startSandboxUiFixture() {: 'notification_emit_failed'log(`E2E_SDK_SANDBOX_UI_FAIL=${reason}`)res.writeHead(500, { 'content-type': 'text/plain; charset=utf-8' })- res.end(- `Could not emit Sandbox UI notification: ${error instanceof Error ? error.message : error}`- )+ res.end('Could not emit Sandbox UI notification.')}})server.listen(Number(process.env.PORT || '8080'), '0.0.0.0', () => {