diff --git a/tests/e2e/wdio.conf.js b/tests/e2e/wdio.conf.js index e307fe0..ecca1b0 100644 --- a/tests/e2e/wdio.conf.js +++ b/tests/e2e/wdio.conf.js @@ -1,8 +1,8 @@ -import { spawn } from 'node:child_process'; +import { spawn, execSync } from 'node:child_process'; import { createConnection } from 'node:net'; import { resolve, dirname } from 'node:path'; import { fileURLToPath } from 'node:url'; -import { rmSync } from 'node:fs'; +import { rmSync, existsSync } from 'node:fs'; import { createTestFixture } from './infra/fixtures.ts'; const __dirname = dirname(fileURLToPath(import.meta.url)); @@ -100,9 +100,25 @@ export const config = { /** * Build the debug binary before the test run. - * Uses --debug --no-bundle for fastest build time. + * Kills any stale tauri-driver on our port first. */ onPrepare() { + // Kill stale tauri-driver on our port to avoid connecting to wrong app + try { + const pids = execSync(`lsof -ti:${TAURI_DRIVER_PORT} 2>/dev/null`, { encoding: 'utf8' }).trim(); + if (pids) { + console.log(`Killing stale process(es) on port ${TAURI_DRIVER_PORT}: ${pids}`); + execSync(`kill ${pids} 2>/dev/null`); + } + } catch { /* no process on port — good */ } + + // Verify binary exists + if (!existsSync(tauriBinary)) { + if (process.env.SKIP_BUILD) { + throw new Error(`Debug binary not found at ${tauriBinary}. Build first or unset SKIP_BUILD.`); + } + } + if (process.env.SKIP_BUILD) { console.log('SKIP_BUILD set — using existing debug binary.'); return Promise.resolve(); @@ -176,6 +192,34 @@ export const config = { }); }, + /** + * Verify the connected app is Agent Orchestrator (not another Tauri/WebKit2GTK app). + * Runs once after the WebDriver session is created, before any spec files. + */ + async before() { + // Wait for app to render, then check for a known element + await browser.waitUntil( + async () => { + const title = await browser.getTitle(); + const hasKnownEl = await browser.execute(() => + document.querySelector('[data-testid="status-bar"]') !== null + || document.querySelector('.project-grid') !== null + || document.querySelector('.settings-panel') !== null + ); + return hasKnownEl || title.toLowerCase().includes('agor') || title.toLowerCase().includes('orchestrator'); + }, + { + timeout: 15_000, + interval: 500, + timeoutMsg: + 'Connected app is NOT Agent Orchestrator — wrong app detected. ' + + 'Check for other Tauri/WebKit2GTK apps running on this machine. ' + + 'Kill them or ensure the correct binary is at: ' + tauriBinary, + }, + ); + console.log('App identity verified: Agent Orchestrator connected.'); + }, + /** * Kill tauri-driver after the test run. */