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 F — Search Overlay, Context Tab, Anchors, SSH Tab Tests (F1F3)
// Tests FTS5 search overlay interactions, context tab with anchors, and SSH tab.
@ -7,7 +8,7 @@ import { browser, expect } from '@wdio/globals';
/** Get first project box ID. */
async function getFirstProjectId(): Promise<string | null> {
return browser.execute(() => {
return exec(() => {
const box = document.querySelector('[data-testid="project-box"]');
return box?.getAttribute('data-project-id') ?? null;
});
@ -15,7 +16,7 @@ async function getFirstProjectId(): Promise<string | null> {
/** Switch to a tab in the first project box by tab text label. */
async function switchProjectTabByLabel(projectId: string, label: string): Promise<void> {
await browser.execute((id, lbl) => {
await exec((id, lbl) => {
const box = document.querySelector(`[data-project-id="${id}"]`);
const tabs = box?.querySelectorAll('[data-testid="project-tabs"] .ptab');
if (!tabs) return;
@ -56,7 +57,7 @@ describe('Scenario F1 — Search Overlay Advanced', () => {
afterEach(async () => {
// Ensure overlay is closed after each test
try {
const isVisible = await browser.execute(() => {
const isVisible = await exec(() => {
const el = document.querySelector('.search-overlay');
return el !== null && window.getComputedStyle(el).display !== 'none';
});
@ -70,7 +71,7 @@ describe('Scenario F1 — Search Overlay Advanced', () => {
});
it('should open search overlay with Ctrl+Shift+F', async () => {
await browser.execute(() => document.body.focus());
await exec(() => document.body.focus());
await browser.pause(100);
await browser.keys(['Control', 'Shift', 'f']);
await browser.pause(500);
@ -80,12 +81,12 @@ describe('Scenario F1 — Search Overlay Advanced', () => {
});
it('should show search input focused and ready', async () => {
await browser.execute(() => document.body.focus());
await exec(() => document.body.focus());
await browser.pause(100);
await browser.keys(['Control', 'Shift', 'f']);
await browser.pause(500);
const isFocused = await browser.execute(() => {
const isFocused = await exec(() => {
const input = document.querySelector('.search-input');
return input === document.activeElement;
});
@ -93,7 +94,7 @@ describe('Scenario F1 — Search Overlay Advanced', () => {
});
it('should show empty state message when no results', async () => {
await browser.execute(() => document.body.focus());
await exec(() => document.body.focus());
await browser.pause(100);
await browser.keys(['Control', 'Shift', 'f']);
await browser.pause(500);
@ -102,7 +103,7 @@ describe('Scenario F1 — Search Overlay Advanced', () => {
await input.setValue('xyznonexistent99999');
await browser.pause(500);
const emptyMsg = await browser.execute(() => {
const emptyMsg = await exec(() => {
const el = document.querySelector('.search-empty');
return el?.textContent ?? '';
});
@ -110,7 +111,7 @@ describe('Scenario F1 — Search Overlay Advanced', () => {
});
it('should close search overlay on Escape', async () => {
await browser.execute(() => document.body.focus());
await exec(() => document.body.focus());
await browser.pause(100);
await browser.keys(['Control', 'Shift', 'f']);
await browser.pause(500);
@ -124,7 +125,7 @@ describe('Scenario F1 — Search Overlay Advanced', () => {
await browser.pause(400);
// Verify it closed
const isHidden = await browser.execute(() => {
const isHidden = await exec(() => {
const el = document.querySelector('.search-overlay');
if (!el) return true;
return window.getComputedStyle(el).display === 'none';
@ -153,7 +154,7 @@ describe('Scenario F2 — Context Tab & Anchors', () => {
});
it('should show Context tab in project tab bar', async () => {
const hasContextTab = await browser.execute((id) => {
const hasContextTab = await exec((id) => {
const box = document.querySelector(`[data-project-id="${id}"]`);
const tabs = box?.querySelectorAll('[data-testid="project-tabs"] .ptab');
if (!tabs) return false;
@ -168,7 +169,7 @@ describe('Scenario F2 — Context Tab & Anchors', () => {
it('should render context visualization when Context tab activated', async () => {
await switchProjectTabByLabel(projectId, 'Context');
const hasContent = await browser.execute((id) => {
const hasContent = await exec((id) => {
const box = document.querySelector(`[data-project-id="${id}"]`);
// Look for context-tab component, stats, token meter, or anchors section
const contextTab = box?.querySelector('.context-tab');
@ -181,14 +182,14 @@ describe('Scenario F2 — Context Tab & Anchors', () => {
it('should show anchor budget scale selector in Settings', async () => {
// Open settings
await browser.execute(() => {
await exec(() => {
const btn = document.querySelector('[data-testid="settings-btn"]');
if (btn) (btn as HTMLElement).click();
});
await browser.pause(500);
// Navigate to Orchestration category
const clickedOrch = await browser.execute(() => {
const clickedOrch = await exec(() => {
const items = document.querySelectorAll('.settings-sidebar button, .settings-sidebar [role="tab"]');
for (const item of items) {
if (item.textContent?.includes('Orchestration')) {
@ -201,7 +202,7 @@ describe('Scenario F2 — Context Tab & Anchors', () => {
await browser.pause(300);
// Look for anchor budget setting
const hasAnchorBudget = await browser.execute(() => {
const hasAnchorBudget = await exec(() => {
const panel = document.querySelector('.settings-panel, .settings-content');
if (!panel) return false;
const text = panel.textContent ?? '';
@ -243,7 +244,7 @@ describe('Scenario F3 — SSH Tab', () => {
});
it('should show SSH tab in project tab bar', async () => {
const hasSshTab = await browser.execute((id) => {
const hasSshTab = await exec((id) => {
const box = document.querySelector(`[data-project-id="${id}"]`);
const tabs = box?.querySelectorAll('[data-testid="project-tabs"] .ptab');
if (!tabs) return false;
@ -258,7 +259,7 @@ describe('Scenario F3 — SSH Tab', () => {
it('should render SSH content pane when tab activated', async () => {
await switchProjectTabByLabel(projectId, 'SSH');
const hasSshContent = await browser.execute((id) => {
const hasSshContent = await exec((id) => {
const box = document.querySelector(`[data-project-id="${id}"]`);
const sshTab = box?.querySelector('.ssh-tab');
const sshHeader = box?.querySelector('.ssh-header');
@ -269,7 +270,7 @@ describe('Scenario F3 — SSH Tab', () => {
it('should show SSH connection list or empty state', async () => {
// SSH tab should show either connections or an empty state message
const sshState = await browser.execute((id) => {
const sshState = await exec((id) => {
const box = document.querySelector(`[data-project-id="${id}"]`);
const list = box?.querySelector('.ssh-list');
const empty = box?.querySelector('.ssh-empty');
@ -286,7 +287,7 @@ describe('Scenario F3 — SSH Tab', () => {
});
it('should show add SSH connection button or form', async () => {
const hasAddControl = await browser.execute((id) => {
const hasAddControl = await exec((id) => {
const box = document.querySelector(`[data-project-id="${id}"]`);
// Look for add button or SSH form
const form = box?.querySelector('.ssh-form');