# E2E Testing — CEF Mode

## Overview

The Electrobun build supports two rendering backends:

| Backend | Use case | E2E automation | WebGL | xterm limit |
|---------|----------|---------------|-------|-------------|
| **WebKitGTK** (default) | Production | None (no WebDriver) | No | 4 instances |
| **CEF** (opt-in) | Dev/test | CDP via port 9222 | Yes | Unlimited |

Production always ships with WebKitGTK — lighter footprint, no Chromium dependency, system-native rendering. CEF mode is for development and CI testing only.

## Enabling CEF Mode

Set the `AGOR_CEF` environment variable before building or running:

```bash
# Build with CEF
AGOR_CEF=1 electrobun build --env=dev

# Dev mode with CEF
AGOR_CEF=1 electrobun dev
```

This does three things in `electrobun.config.ts`:
1. Sets `bundleCEF: true` — downloads and bundles CEF libraries
2. Sets `defaultRenderer: "cef"` — uses CEF instead of WebKitGTK
3. Adds `chromiumFlags` — enables `--remote-debugging-port=9222` and `--remote-allow-origins=*`

## Running E2E Tests

```bash
# Run Electrobun E2E tests (sets AGOR_CEF=1 automatically)
npm run test:e2e:electrobun

# Run both Tauri and Electrobun E2E suites
npm run test:e2e:both

# Full test suite including E2E
npm run test:all:e2e
```

The test runner (`wdio.electrobun.conf.js`):
1. Creates an isolated test fixture (temp dirs, test groups.json)
2. Builds the app if no binary exists
3. Launches the app with `AGOR_CEF=1` and `AGOR_TEST=1`
4. Waits for CDP port 9222 to respond
5. Connects WebDriverIO via `automationProtocol: 'devtools'`
6. Runs all shared spec files
7. Kills the app and cleans up fixtures

## CI Setup

```yaml
- name: E2E (Electrobun + CEF)
  run: xvfb-run AGOR_CEF=1 npm run test:e2e:electrobun
  env:
    AGOR_TEST: '1'
```

CEF requires a display server. Use `xvfb-run` on headless CI.

## Port Assignments

| Port | Service |
|------|---------|
| 9222 | CDP remote debugging (CEF) |
| 9760 | Vite dev server (HMR) |
| 9761 | Reserved (was WebKitWebDriver) |

## Troubleshooting

**"CDP port 9222 not ready after 30000ms"** — The app failed to start or CEF was not bundled. Check that the build used `AGOR_CEF=1`. Look for `[LAUNCHER] ERROR: CEF libraries found but LD_PRELOAD not set` in stderr.

**"No binary found"** — The test runner falls back to `electrobun dev`, which builds and launches in one step. This is slower but works without a pre-built binary.

**Tests pass with CEF but fail with WebKitGTK** — Expected. WebKitGTK has no WebDriver/CDP support in Electrobun. E2E tests only run against CEF. Manual testing covers WebKitGTK.
