fix(e2e): cross-protocol browser.execute() — works with both WebDriver + CDP

Root cause: WebDriverIO devtools protocol wraps functions in a polyfill
that puts `return` inside eval() (not a function body) → "Illegal return".

Fix: exec() wrapper in helpers/execute.ts converts function args to IIFE
strings before passing to browser.execute(). Works identically on both
WebDriver (Tauri) and CDP/devtools (Electrobun CEF).

- 35 spec files updated (browser.execute → exec)
- 4 config files updated (string-form expressions)
- helpers/actions.ts + assertions.ts updated
- 560 vitest + 116 cargo passing
This commit is contained in:
Hibryda 2026-03-22 06:33:55 +01:00
parent 407e49cc32
commit 6a8181f33a
42 changed files with 630 additions and 541 deletions

View file

@ -1,4 +1,5 @@
import { browser, expect } from '@wdio/globals';
import { exec } from '../helpers/execute.ts';
// Phase E — Part 1: Multi-agent orchestration, project tabs, and provider UI.
// Tests ProjectBox tab bar, AgentPane state, provider config, status bar fleet state.
@ -6,7 +7,7 @@ import { browser, expect } from '@wdio/globals';
// ─── Helpers ──────────────────────────────────────────────────────────
async function clickTabByText(tabText: string): Promise<void> {
await browser.execute((text) => {
await exec((text) => {
const tabs = document.querySelectorAll('[data-testid="project-tabs"] .ptab');
for (const tab of tabs) {
if (tab.textContent?.trim() === text) {
@ -19,7 +20,7 @@ async function clickTabByText(tabText: string): Promise<void> {
}
async function getActiveTabText(): Promise<string> {
return browser.execute(() => {
return exec(() => {
const box = document.querySelector('[data-testid="project-box"]');
const active = box?.querySelector('[data-testid="project-tabs"] .ptab.active');
return active?.textContent?.trim() ?? '';
@ -32,7 +33,7 @@ describe('Scenario E1 — ProjectBox Tab Bar', () => {
before(async () => {
await browser.waitUntil(
async () => {
const count = await browser.execute(() =>
const count = await exec(() =>
document.querySelectorAll('[data-testid="project-box"]').length,
);
return (count as number) >= 1;
@ -43,7 +44,7 @@ describe('Scenario E1 — ProjectBox Tab Bar', () => {
});
it('should render project-level tab bar with at least 7 tabs', async () => {
const tabCount = await browser.execute(() => {
const tabCount = await exec(() => {
const box = document.querySelector('[data-testid="project-box"]');
return box?.querySelectorAll('[data-testid="project-tabs"] .ptab')?.length ?? 0;
});
@ -51,7 +52,7 @@ describe('Scenario E1 — ProjectBox Tab Bar', () => {
});
it('should include expected base tab labels', async () => {
const tabTexts = await browser.execute(() => {
const tabTexts = await exec(() => {
const box = document.querySelector('[data-testid="project-box"]');
const tabs = box?.querySelectorAll('[data-testid="project-tabs"] .ptab');
return Array.from(tabs ?? []).map((t) => t.textContent?.trim() ?? '');
@ -86,7 +87,7 @@ describe('Scenario E1 — ProjectBox Tab Bar', () => {
await clickTabByText('Files');
expect(await getActiveTabText()).toBe('Files');
// Content panes should still be in DOM (display toggled, not unmounted)
const paneCount = await browser.execute(() => {
const paneCount = await exec(() => {
const box = document.querySelector('[data-testid="project-box"]');
return box?.querySelectorAll('.content-pane')?.length ?? 0;
});
@ -121,7 +122,7 @@ describe('Scenario E2 — Agent Session UI', () => {
});
it('should show agent pane in idle status initially', async () => {
const status = await browser.execute(() => {
const status = await exec(() => {
const el = document.querySelector('[data-testid="agent-pane"]');
return el?.getAttribute('data-agent-status') ?? 'unknown';
});
@ -129,7 +130,7 @@ describe('Scenario E2 — Agent Session UI', () => {
});
it('should show CWD in ProjectHeader', async () => {
const cwd = await browser.execute(() => {
const cwd = await exec(() => {
const header = document.querySelector('.project-header');
return header?.querySelector('.info-cwd')?.textContent?.trim() ?? '';
});
@ -137,7 +138,7 @@ describe('Scenario E2 — Agent Session UI', () => {
});
it('should show profile name in ProjectHeader if configured', async () => {
const profileInfo = await browser.execute(() => {
const profileInfo = await exec(() => {
const el = document.querySelector('.project-header .info-profile');
return { exists: el !== null, text: el?.textContent?.trim() ?? '' };
});
@ -151,7 +152,7 @@ describe('Scenario E2 — Agent Session UI', () => {
describe('Scenario E3 — Provider Configuration', () => {
before(async () => {
await browser.execute(() => {
await exec(() => {
const btn = document.querySelector('[data-testid="settings-btn"]');
if (btn) (btn as HTMLElement).click();
});
@ -161,7 +162,7 @@ describe('Scenario E3 — Provider Configuration', () => {
});
it('should show Providers section in Settings', async () => {
const hasProviders = await browser.execute(() => {
const hasProviders = await exec(() => {
const headers = document.querySelectorAll('.settings-section h2');
return Array.from(headers).some((h) => h.textContent?.trim() === 'Providers');
});
@ -169,14 +170,14 @@ describe('Scenario E3 — Provider Configuration', () => {
});
it('should show at least one provider panel', async () => {
const count = await browser.execute(() =>
const count = await exec(() =>
document.querySelectorAll('.provider-panel').length,
);
expect(count).toBeGreaterThanOrEqual(1);
});
it('should show provider name in panel header', async () => {
const name = await browser.execute(() => {
const name = await exec(() => {
const panel = document.querySelector('.provider-panel');
return panel?.querySelector('.provider-name')?.textContent?.trim() ?? '';
});
@ -184,12 +185,12 @@ describe('Scenario E3 — Provider Configuration', () => {
});
it('should expand provider panel to show enabled toggle', async () => {
await browser.execute(() => {
await exec(() => {
const header = document.querySelector('.provider-header');
if (header) (header as HTMLElement).click();
});
await browser.pause(300);
const hasToggle = await browser.execute(() => {
const hasToggle = await exec(() => {
const body = document.querySelector('.provider-body');
return body?.querySelector('.toggle-switch') !== null;
});
@ -197,7 +198,7 @@ describe('Scenario E3 — Provider Configuration', () => {
});
after(async () => {
await browser.execute(() => {
await exec(() => {
const header = document.querySelector('.provider-header');
const expanded = document.querySelector('.provider-body');
if (expanded && header) (header as HTMLElement).click();
@ -218,14 +219,14 @@ describe('Scenario E4 — Status Bar Fleet State', () => {
});
it('should show project count', async () => {
const text = await browser.execute(() => {
const text = await exec(() => {
return document.querySelector('[data-testid="status-bar"]')?.textContent ?? '';
});
expect(text).toMatch(/\d+ projects/);
});
it('should show agent state or project info', async () => {
const hasState = await browser.execute(() => {
const hasState = await exec(() => {
const text = document.querySelector('[data-testid="status-bar"]')?.textContent ?? '';
return text.includes('idle') || text.includes('running') || text.includes('projects');
});
@ -233,7 +234,7 @@ describe('Scenario E4 — Status Bar Fleet State', () => {
});
it('should not show burn rate when all agents idle', async () => {
const burnRate = await browser.execute(() => {
const burnRate = await exec(() => {
const bar = document.querySelector('[data-testid="status-bar"]');
return bar?.querySelector('.burn-rate')?.textContent ?? null;
});
@ -248,7 +249,7 @@ describe('Scenario E4 — Status Bar Fleet State', () => {
});
it('should conditionally show attention queue button', async () => {
const info = await browser.execute(() => {
const info = await exec(() => {
const btn = document.querySelector('[data-testid="status-bar"] .attention-btn');
return { exists: btn !== null, text: btn?.textContent?.trim() ?? '' };
});