fix(e2e): kill stale processes, verify app identity before tests
- onPrepare: kill stale tauri-driver on port 9750 before spawning - onPrepare: verify debug binary exists (fail fast with clear message) - before: app identity check — waits for known Agent Orchestrator elements (status-bar, project-grid, settings-panel) or matching window title - Prevents wrong-app connection when other Tauri/WebKit2GTK apps are running
This commit is contained in:
parent
ae321ad108
commit
1f21a9fb46
1 changed files with 47 additions and 3 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
import { spawn } from 'node:child_process';
|
import { spawn, execSync } from 'node:child_process';
|
||||||
import { createConnection } from 'node:net';
|
import { createConnection } from 'node:net';
|
||||||
import { resolve, dirname } from 'node:path';
|
import { resolve, dirname } from 'node:path';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
import { rmSync } from 'node:fs';
|
import { rmSync, existsSync } from 'node:fs';
|
||||||
import { createTestFixture } from './infra/fixtures.ts';
|
import { createTestFixture } from './infra/fixtures.ts';
|
||||||
|
|
||||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
@ -100,9 +100,25 @@ export const config = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build the debug binary before the test run.
|
* 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() {
|
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) {
|
if (process.env.SKIP_BUILD) {
|
||||||
console.log('SKIP_BUILD set — using existing debug binary.');
|
console.log('SKIP_BUILD set — using existing debug binary.');
|
||||||
return Promise.resolve();
|
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.
|
* Kill tauri-driver after the test run.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue