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 A — Agent: Agent pane initial state + prompt submission + NEW agent tests.
// Shares a single Tauri app session with other phase-a-* spec files.
@ -8,7 +9,7 @@ import { browser, expect } from '@wdio/globals';
async function waitForAgentStatus(status: string, timeout = 30_000): Promise<void> {
await browser.waitUntil(
async () => {
const attr = await browser.execute(() => {
const attr = await exec(() => {
const el = document.querySelector('[data-testid="agent-pane"]');
return el?.getAttribute('data-agent-status') ?? 'idle';
});
@ -29,18 +30,18 @@ async function sendAgentPrompt(text: string): Promise<void> {
await textarea.setValue(text);
await browser.pause(200);
const submitBtn = await browser.$('[data-testid="agent-submit"]');
await browser.execute((el) => (el as HTMLElement).click(), submitBtn);
await submitBtn.click();
}
async function getAgentStatus(): Promise<string> {
return browser.execute(() => {
return exec(() => {
const el = document.querySelector('[data-testid="agent-pane"]');
return el?.getAttribute('data-agent-status') ?? 'unknown';
});
}
async function getMessageCount(): Promise<number> {
return browser.execute(() => {
return exec(() => {
const area = document.querySelector('[data-testid="agent-messages"]');
return area ? area.children.length : 0;
});
@ -51,7 +52,7 @@ async function getMessageCount(): Promise<number> {
describe('Scenario 3 — Agent Pane Initial State', () => {
it('should display agent pane in idle status', async () => {
if (!(await agentPaneExists())) {
await browser.execute(() => {
await exec(() => {
const tab = document.querySelector('[data-testid="project-tabs"] .ptab');
if (tab) (tab as HTMLElement).click();
});
@ -75,7 +76,7 @@ describe('Scenario 3 — Agent Pane Initial State', () => {
it('should have empty messages area initially', async () => {
const msgArea = await browser.$('[data-testid="agent-messages"]');
await expect(msgArea).toBeExisting();
const msgCount = await browser.execute(() => {
const msgCount = await exec(() => {
const area = document.querySelector('[data-testid="agent-messages"]');
return area ? area.querySelectorAll('.message').length : 0;
});
@ -83,7 +84,7 @@ describe('Scenario 3 — Agent Pane Initial State', () => {
});
it('should show agent provider name or badge', async () => {
const hasContent = await browser.execute(() => {
const hasContent = await exec(() => {
const session = document.querySelector('[data-testid="agent-session"]');
return session !== null && (session.textContent ?? '').length > 0;
});
@ -93,7 +94,7 @@ describe('Scenario 3 — Agent Pane Initial State', () => {
it('should show cost display area (when session exists) or prompt area', async () => {
// status-strip only renders when session is non-null; before first query
// the agent pane shows only the prompt area — both are valid states
const state = await browser.execute(() => {
const state = await exec(() => {
const pane = document.querySelector('[data-testid="agent-pane"]');
if (!pane) return 'no-pane';
if (pane.querySelector('.status-strip')) return 'has-status';
@ -106,7 +107,7 @@ describe('Scenario 3 — Agent Pane Initial State', () => {
it('should show agent pane with prompt or status area', async () => {
// Context meter only visible during running state; verify pane structure instead
const hasPane = await browser.execute(() => {
const hasPane = await exec(() => {
const pane = document.querySelector('[data-testid="agent-pane"]');
return pane !== null;
});
@ -114,7 +115,7 @@ describe('Scenario 3 — Agent Pane Initial State', () => {
});
it('should have tool call/result collapsible sections area', async () => {
const ready = await browser.execute(() => {
const ready = await exec(() => {
const area = document.querySelector('[data-testid="agent-messages"]');
return area !== null && area instanceof HTMLElement;
});
@ -138,7 +139,7 @@ describe('Scenario 7 — Agent Prompt Submission', () => {
const textarea = await browser.$('[data-testid="agent-prompt"]');
await textarea.setValue('Test prompt');
await browser.pause(200);
const isDisabled = await browser.execute(() => {
const isDisabled = await exec(() => {
const btn = document.querySelector('[data-testid="agent-submit"]');
return btn ? (btn as HTMLButtonElement).disabled : true;
});
@ -204,7 +205,7 @@ describe('Scenario 7 — Agent Prompt Submission', () => {
try { await waitForAgentStatus('running', 15_000); } catch {
this.skip(); return;
}
const uiState = await browser.execute(() => {
const uiState = await exec(() => {
const textarea = document.querySelector('[data-testid="agent-prompt"]') as HTMLTextAreaElement | null;
const stopBtn = document.querySelector('[data-testid="agent-stop"]');
return {
@ -214,7 +215,7 @@ describe('Scenario 7 — Agent Prompt Submission', () => {
});
expect(uiState.textareaDisabled || uiState.stopBtnVisible).toBe(true);
try { await waitForAgentStatus('idle', 40_000); } catch {
await browser.execute(() => {
await exec(() => {
const btn = document.querySelector('[data-testid="agent-stop"]');
if (btn) (btn as HTMLElement).click();
});