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,5 +1,6 @@
import { browser, expect } from '@wdio/globals';
import { isJudgeAvailable, assertWithJudge } from '../infra/llm-judge';
import { exec } from '../helpers/execute.ts';
// Phase B — LLM: LLM-judged agent responses, code generation, context tab.
// Scenarios B4-B6 + new agent/context tests. Requires ANTHROPIC_API_KEY for LLM tests.
@ -7,29 +8,29 @@ import { isJudgeAvailable, assertWithJudge } from '../infra/llm-judge';
// ─── Helpers ──────────────────────────────────────────────────────────
async function getProjectIds(): Promise<string[]> {
return browser.execute(() => {
return exec(() => {
return Array.from(document.querySelectorAll('[data-testid="project-box"]'))
.map((b) => b.getAttribute('data-project-id') ?? '').filter(Boolean);
});
}
async function focusProject(id: string): Promise<void> {
await browser.execute((pid) => {
await exec((pid) => {
(document.querySelector(`[data-project-id="${pid}"] .project-header`) as HTMLElement)?.click();
}, id);
await browser.pause(300);
}
async function getAgentStatus(id: string): Promise<string> {
return browser.execute((pid) =>
return exec((pid) =>
document.querySelector(`[data-project-id="${pid}"] [data-testid="agent-pane"]`)?.getAttribute('data-agent-status') ?? 'not-found', id);
}
async function sendPromptInProject(id: string, text: string): Promise<void> {
await focusProject(id);
await browser.execute((pid, prompt) => {
await exec((pid, prompt) => {
const ta = document.querySelector(`[data-project-id="${pid}"] [data-testid="agent-prompt"]`) as HTMLTextAreaElement | null;
if (ta) { ta.value = prompt; ta.dispatchEvent(new Event('input', { bubbles: true })); }
}, id, text);
await browser.pause(200);
await browser.execute((pid) => {
await exec((pid) => {
(document.querySelector(`[data-project-id="${pid}"] [data-testid="agent-submit"]`) as HTMLElement)?.click();
}, id);
}
@ -38,11 +39,11 @@ async function waitForAgentStatus(id: string, status: string, timeout = 60_000):
{ timeout, timeoutMsg: `Agent ${id} did not reach "${status}" in ${timeout}ms` });
}
async function getAgentMessages(id: string): Promise<string> {
return browser.execute((pid) =>
return exec((pid) =>
document.querySelector(`[data-project-id="${pid}"] [data-testid="agent-messages"]`)?.textContent ?? '', id);
}
async function switchTab(id: string, idx: number): Promise<void> {
await browser.execute((pid, i) => {
await exec((pid, i) => {
const tabs = document.querySelector(`[data-project-id="${pid}"]`)?.querySelectorAll('[data-testid="project-tabs"] .ptab');
if (tabs?.[i]) (tabs[i] as HTMLElement).click();
}, id, idx);
@ -105,7 +106,7 @@ describe('Scenario B4 — LLM-Judged Agent Response', () => {
const pid = ids[0];
const status = await getAgentStatus(pid);
if (status === 'idle') {
const hasCost = await browser.execute((id) => {
const hasCost = await exec((id) => {
return document.querySelector(`[data-project-id="${id}"] .cost-bar, [data-project-id="${id}"] .usage-meter, [data-project-id="${id}"] [data-testid="agent-cost"]`) !== null;
}, pid);
expect(typeof hasCost).toBe('boolean');
@ -116,7 +117,7 @@ describe('Scenario B4 — LLM-Judged Agent Response', () => {
const ids = await getProjectIds();
if (ids.length < 1) return;
const pid = ids[0];
const modelInfo = await browser.execute((id) => {
const modelInfo = await exec((id) => {
const box = document.querySelector(`[data-project-id="${id}"]`);
const modelEl = box?.querySelector('.model-name, .session-model, [data-testid="agent-model"]');
const strip = box?.querySelector('.status-strip');
@ -171,7 +172,7 @@ describe('Scenario B6 — Context Tab After Agent Activity', () => {
if (ids.length < 1) return;
const pid = ids[0];
await switchTab(pid, 2);
const content = await browser.execute((id) => {
const content = await exec((id) => {
return document.querySelector(`[data-project-id="${id}"] .context-stats, [data-project-id="${id}"] .token-meter, [data-project-id="${id}"] .stat-value`)?.textContent ?? '';
}, pid);
if (content) { expect(content.length).toBeGreaterThan(0); }
@ -183,7 +184,7 @@ describe('Scenario B6 — Context Tab After Agent Activity', () => {
if (ids.length < 1) return;
const pid = ids[0];
await switchTab(pid, 2);
const tokenData = await browser.execute((id) => {
const tokenData = await exec((id) => {
const box = document.querySelector(`[data-project-id="${id}"]`);
const meter = box?.querySelector('.token-meter, .context-meter, [data-testid="token-meter"]');
const stats = box?.querySelectorAll('.stat-value');
@ -200,7 +201,7 @@ describe('Scenario B6 — Context Tab After Agent Activity', () => {
if (ids.length < 1) return;
const pid = ids[0];
await switchTab(pid, 2);
const refCount = await browser.execute((id) => {
const refCount = await exec((id) => {
const box = document.querySelector(`[data-project-id="${id}"]`);
const refs = box?.querySelectorAll('.file-ref, .file-reference, [data-testid="file-refs"] li');
return refs?.length ?? 0;