// Browser E2E config. Two projects: // - `mock` (default): every network edge is intercepted, no retries, one // worker. This is the lane that must stay green in CI. // - `real`: drives the real backend (uvicorn + stub pipeline). Kept separate // so the mocked lane never depends on Python. // // The `real` project and its backend webServer only exist when CW_E2E_REAL is // set (CI sets it). A bare `npm run test:e2e` therefore stays mock-only and // needs no Python deps. /* global process */ import { defineConfig, devices } from '@playwright/test'; import { fileURLToPath } from 'node:url'; import path from 'node:path'; const dashboardDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); const repoRoot = path.resolve(dashboardDir, '..'); const realBackend = !!process.env.CW_E2E_REAL; const webServers = [ { command: 'npm run build && npx vite preview --port 4173 --strictPort --host 127.0.0.1', cwd: dashboardDir, url: 'http://127.0.0.1:4173', reuseExistingServer: !process.env.CI, timeout: 120_000, stdout: 'ignore', stderr: 'pipe', }, ]; if (realBackend) { // Real `uvicorn clipwright.api.app:app` with the pipeline's stub_env on // PYTHONPATH: sitecustomize stubs the ML/network edges so the real CLI runs // with real ffmpeg, no model downloads and no outbound requests. The env // values mirror tests/e2e/pipeline's deterministic, no-ML configuration. webServers.push({ command: 'python -m uvicorn clipwright.api.app:app --host 127.0.0.1 --port 8000 --log-level warning', cwd: repoRoot, url: 'http://127.0.0.1:8000/health', reuseExistingServer: !process.env.CI, timeout: 120_000, stdout: 'ignore', stderr: 'pipe', env: { PYTHONPATH: ['tests/e2e/pipeline/stub_env', '.'].join(path.delimiter), GEMINI_API_KEY: 'test', MIN_SOURCE_SECONDS: '0', QUALITY_GATE_MIN_HEIGHT: '0', AUTO_LAYOUT: '0', SCENE_ENGINE: 'pyscenedetect', ASR_HOST_SLOTS: '0', FFMPEG_ENCODER: 'x264', TZ: 'UTC', }, }); } export default defineConfig({ testDir: './specs', // No retries anywhere: a flaky test is a bug, not a coin flip. retries: 0, // One worker keeps the shared preview server and the deterministic fixtures // predictable. workers: 1, fullyParallel: false, timeout: 30_000, expect: { timeout: 5_000 }, reporter: [['list']], outputDir: './.test-results', globalSetup: './fixtures/global-setup.js', use: { baseURL: 'http://127.0.0.1:4173', trace: 'retain-on-failure', screenshot: 'only-on-failure', video: 'retain-on-failure', }, projects: [ { name: 'mock', testIgnore: /real-backend\.spec\.js/, use: { ...devices['Desktop Chrome'] }, }, // The real lane runs the full pipeline, which needs more than the 30s // default. Gated so a mock-only run never tries to boot Python. ...(realBackend ? [{ name: 'real', testMatch: /real-backend\.spec\.js/, timeout: 120_000, use: { ...devices['Desktop Chrome'] }, }] : []), ], webServer: webServers, });