Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 72d1d96ba67ad08b0f5e638dbdeb5193545e427f
parent 8b728524f6a28a5e506ccdf5f7b2dba98fdd72fc
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Sat, 10 Oct 2026 14:11:19 -0400

e2e: S5b — a server set per worker (E2E_WORKERS), @serial specs after, on one worker

With E2E_WORKERS > 1 every worker slot gets its own editor test server, export
dev server and Ollama stub over its own data root (`editor/.e2e-workers/w<n>`):
slot 0 is the config's webServer entries as before, slots 1… are started by
globalSetup on ports from the unused top of the worktree's block and stopped
by globalTeardown. Playwright evaluates the config again in each worker with
TEST_PARALLEL_INDEX set, so baseURL, PLAYWRIGHT_BASE_URL, EXPORT_PORT and
testPaths() are the slot's before a spec loads — no spec changes.

`E2E_WORKERS`: a number (≤ 8) or `auto` (floor((MemAvailable − floor) / 1.5 GB),
cap 3); unset stays 1 until full runs at 1, 2 and 3 workers are measured. With
more than one worker the files in e2e/serial.ts (the checkout's build outputs,
timing under contention) run in a `serial` project, the parallel project's
teardown, on one worker. The servers' env, ports and commands are one
definition (e2e/servers.ts) for the config and globalSetup.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
M.gitignore | 2++
MENVIRONMENT.md | 1+
Mcommon/lib/envVars.ts | 1+
Meditor/e2e/exportOutLink.ts | 5+++--
Meditor/e2e/globalSetup.ts | 34+++++++++++++++++++++++++++++++++-
Meditor/e2e/globalTeardown.ts | 4++++
Aeditor/e2e/serial.ts | 38++++++++++++++++++++++++++++++++++++++
Aeditor/e2e/servers.ts | 287+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aeditor/e2e/servers.unit.ts | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Meditor/e2e/testPaths.ts | 30++++++++++++++++++++++++------
Meditor/package.json | 2+-
Meditor/playwright.config.ts | 202++++++++++++++++++++++++++++++-------------------------------------------------
12 files changed, 561 insertions(+), 135 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -117,6 +117,8 @@ yarn-error.log* # editor e2e fixtures and ephemeral state /editor/test-transcripts/ +# the other e2e worker slots' data roots and server logs (editor/e2e/servers.ts) +/editor/.e2e-workers/ /editor/test-settings.json # Disposable changelogs for the cut-release e2e (EDITOR_CHANGELOG_FILE and # EXPORT_CHANGELOG_FILE in dev:test/start:test). Keep those specs — and diff --git a/ENVIRONMENT.md b/ENVIRONMENT.md @@ -186,6 +186,7 @@ Read only by a test harness, a fake binary or a test-mode branch. Never set one | `E2E_MODE` | `start` | `start`: the editor and umtool suites run against `next start` from a build `scripts/e2e-stamp.mjs` vouches for, rebuilt through the heavy slot when the tree moved. `dev`: against `next dev`, for iterating on one spec. The export and homepage suites always run `next dev` (static exports) and say so when asked for `start`. | editor/playwright.config.ts, umtool/playwright.config.ts, scripts/e2e-stamp.mjs | | `E2E_NEXT_DIST_DIR` | `.next` | The editor's build directory for the e2e suite's start mode (`.next/e2e`), so a test build never replaces the `.next` a running editor serves from. Set by `scripts/e2e-stamp.mjs` for its build and by `editor/playwright.config.ts` for its test server — and for the editor suite's export dev server (`.next/e2e-editor`), which then runs beside the export suite's own (Next allows one `next dev` per dist dir). | editor/next.config.ts, export/next.config.ts | | `E2E_DATA_ROOT` | the editor directory | Where the editor test server's data lives: `test-transcripts/`, `test-settings.json` and the disposable changelogs sit under it. The test server's scripts and the specs' `testPaths()` read the same variable, so they agree by construction. E2E_-prefixed, never TRANSCRIPTS_DIR: a `--share-data` worktree's `.worktree-env` points that at the real corpus. | editor/package.json (dev:test, start:test), editor/e2e/testPaths.ts | +| `E2E_WORKERS` | 1 | How many workers the editor suite runs, each with a server set of its own (editor, export dev server, Ollama stub) over its own data root (`editor/.e2e-workers/w<n>`): a number (up to 8), or `auto` — floor((MemAvailable − HEAVY_MIN_FREE_MB) / 1.5 GB), 1 to 3. Specs in `editor/e2e/serial.ts` run afterwards on one worker. | editor/playwright.config.ts (editor/e2e/servers.ts) | | `E2E_BUILD_CHECKED` | — | Set by a suite's config once it has checked the start-mode build's stamp, so a worker's second load of the config does not check again. | editor/playwright.config.ts, umtool/playwright.config.ts | | `E2E_QUEUE` | on | `0` skips the machine-global e2e queue (the port check still runs). | scripts/queue-lock.mjs | | `E2E_PORT_CHECK` | on | `0` skips the pre-run check that the suite's ports are free. | scripts/queue-lock.mjs | diff --git a/common/lib/envVars.ts b/common/lib/envVars.ts @@ -184,6 +184,7 @@ const DECLARED: EnvVarDecl[] = [ { name: "E2E_MODE", audience: "test", default: "`start`", readBy: "editor/playwright.config.ts, umtool/playwright.config.ts, scripts/e2e-stamp.mjs", doc: "`start`: the editor and umtool suites run against `next start` from a build `scripts/e2e-stamp.mjs` vouches for, rebuilt through the heavy slot when the tree moved. `dev`: against `next dev`, for iterating on one spec. The export and homepage suites always run `next dev` (static exports) and say so when asked for `start`." }, { name: "E2E_NEXT_DIST_DIR", audience: "test", default: "`.next`", readBy: "editor/next.config.ts, export/next.config.ts", doc: "The editor's build directory for the e2e suite's start mode (`.next/e2e`), so a test build never replaces the `.next` a running editor serves from. Set by `scripts/e2e-stamp.mjs` for its build and by `editor/playwright.config.ts` for its test server — and for the editor suite's export dev server (`.next/e2e-editor`), which then runs beside the export suite's own (Next allows one `next dev` per dist dir)." }, { name: "E2E_DATA_ROOT", audience: "test", default: "the editor directory", readBy: "editor/package.json (dev:test, start:test), editor/e2e/testPaths.ts", doc: "Where the editor test server's data lives: `test-transcripts/`, `test-settings.json` and the disposable changelogs sit under it. The test server's scripts and the specs' `testPaths()` read the same variable, so they agree by construction. E2E_-prefixed, never TRANSCRIPTS_DIR: a `--share-data` worktree's `.worktree-env` points that at the real corpus." }, + { name: "E2E_WORKERS", audience: "test", default: "1", readBy: "editor/playwright.config.ts (editor/e2e/servers.ts)", doc: "How many workers the editor suite runs, each with a server set of its own (editor, export dev server, Ollama stub) over its own data root (`editor/.e2e-workers/w<n>`): a number (up to 8), or `auto` — floor((MemAvailable − HEAVY_MIN_FREE_MB) / 1.5 GB), 1 to 3. Specs in `editor/e2e/serial.ts` run afterwards on one worker." }, { name: "E2E_BUILD_CHECKED", audience: "test", default: "—", readBy: "editor/playwright.config.ts, umtool/playwright.config.ts", doc: "Set by a suite's config once it has checked the start-mode build's stamp, so a worker's second load of the config does not check again." }, { name: "E2E_QUEUE", audience: "test", default: "on", readBy: "scripts/queue-lock.mjs", doc: "`0` skips the machine-global e2e queue (the port check still runs)." }, { name: "E2E_PORT_CHECK", audience: "test", default: "on", readBy: "scripts/queue-lock.mjs", doc: "`0` skips the pre-run check that the suite's ports are free." }, diff --git a/editor/e2e/exportOutLink.ts b/editor/e2e/exportOutLink.ts @@ -14,13 +14,14 @@ import { testPaths } from "./helpers"; const editorDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); const exportOut = path.resolve(editorDir, "..", "export", "out"); -const testTranscripts = testPaths().transcriptsDir; +// Every slot's data root (testPaths.ts): slot 0's, and the other workers'. +const testRoots = [testPaths().transcriptsDir, path.join(editorDir, ".e2e-workers")]; export async function dropTestExportOutLink(when: "setup" | "teardown"): Promise<void> { const st = await lstat(exportOut).catch(() => null); if (!st?.isSymbolicLink()) return; const target = path.resolve(path.dirname(exportOut), await readlink(exportOut)); - if (target !== testTranscripts && !target.startsWith(`${testTranscripts}${path.sep}`)) return; + if (!testRoots.some((root) => target === root || target.startsWith(`${root}${path.sep}`))) return; await rm(exportOut, { force: true }); console.log(`[e2e ${when}] removed export/out → ${path.relative(editorDir, target)} (a test bundle)`); } diff --git a/editor/e2e/globalSetup.ts b/editor/e2e/globalSetup.ts @@ -10,10 +10,42 @@ // So this cannot clear a stale dev server ahead of the new one booting — it only // reaps fixture children, which is what actually eats the CPU. +// +// WORKER SLOTS (plans/e2e-speed.md S5). With more than one worker, slot 0's +// servers are the webServer entries; this starts slots 1…'s (e2e/servers.ts), +// each over its own data root, and globalTeardown stops them. + +import type { FullConfig } from "@playwright/test"; import { dropTestExportOutLink } from "./exportOutLink"; import { sweepFixtureProcesses } from "./fixtureProcs"; +import { resolveE2EMode, startSlot, type SlotHandle } from "./servers"; + +declare global { + // eslint-disable-next-line no-var + var __e2eSlotServers: SlotHandle[] | undefined; +} -export default async function globalSetup() { +export default async function globalSetup(config: FullConfig) { await sweepFixtureProcesses("setup"); await dropTestExportOutLink("setup"); + const workers = config.workers; + if (workers <= 1) return; + const mode = resolveE2EMode(); + const t0 = Date.now(); + const settled = await Promise.allSettled( + Array.from({ length: workers - 1 }, (_, i) => startSlot(i + 1, mode)), + ); + globalThis.__e2eSlotServers = settled.flatMap((r) => (r.status === "fulfilled" ? [r.value] : [])); + const failed = settled.find((r): r is PromiseRejectedResult => r.status === "rejected"); + if (failed) { + await stopSlotServers(); + throw failed.reason; + } + console.log(`[e2e setup] ${workers} workers: slots 1–${workers - 1}'s servers up in ${Math.round((Date.now() - t0) / 1000)}s`); +} + +export async function stopSlotServers(): Promise<void> { + const handles = globalThis.__e2eSlotServers ?? []; + globalThis.__e2eSlotServers = []; + await Promise.all(handles.map((h) => h.stop())); } diff --git a/editor/e2e/globalTeardown.ts b/editor/e2e/globalTeardown.ts @@ -12,8 +12,12 @@ import { dropTestExportOutLink } from "./exportOutLink"; import { sweepFixtureProcesses } from "./fixtureProcs"; +import { stopSlotServers } from "./globalSetup"; export default async function globalTeardown() { + // Slots 1…'s servers first (globalSetup's), so their fixtures are gone + // before the sweep looks for strays. + await stopSlotServers(); await sweepFixtureProcesses("teardown"); await dropTestExportOutLink("teardown"); } diff --git a/editor/e2e/serial.ts b/editor/e2e/serial.ts @@ -0,0 +1,38 @@ +// THE @serial SPECS (plans/e2e-speed.md S5): with more than one worker these +// run in a project of their own, AFTER the parallel one (its `teardown`, which +// Playwright runs even when a parallel test failed), on one worker. With one +// worker there is one project and this list changes nothing. +// +// Two reasons put a file here, and only these: +// - it writes into the CHECKOUT, not its slot's data root: a site's or the +// hub's build stage makes `export/out` (EXPORT_NEXT_BIN's fake copies the +// composed bundle there), a homepage build `homepage/out` — one each for +// every slot; +// - it times wall-clock behaviour that contention bends (a cooldown, a +// pacing gap, an audio check's interval), or was a load flake in a gate +// run (release 19/20 records: storage-locations, sites-crud, whisper). +// The first full runs at 2 and 3 workers decide what else belongs; a file that +// passes alone and fails beside others joins with its reason. +export const SERIAL_SPECS: readonly string[] = [ + // the checkout's build outputs + "build.spec.ts", + "deploy-page.spec.ts", + "publish.spec.ts", + "publish-lane.spec.ts", + "site-publish-preview.spec.ts", + "sites-crud.spec.ts", + "sites-homepage.spec.ts", + // timing under contention + "pacing.spec.ts", + "rate-limit.spec.ts", + "audio-check-scenarios.spec.ts", + "fetch-window.spec.ts", + "channel-storage.spec.ts", + "storage-locations.spec.ts", + "whisper.spec.ts", +]; + +const escape = (s: string) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); + +/** Matches a serial spec file's path (Playwright's testMatch/testIgnore). */ +export const SERIAL_SPEC_PATTERN = new RegExp(`(^|/)(${SERIAL_SPECS.map(escape).join("|")})$`); diff --git a/editor/e2e/servers.ts b/editor/e2e/servers.ts @@ -0,0 +1,287 @@ +// A SERVER SET PER WORKER (plans/e2e-speed.md S5). +// +// The suite ran on one worker because its shared state lives in ONE Next server +// (the job registry, worker pool, scheduler, auto-runner and auto-queue state +// are globalThis singletons there) over one data root. A directory per worker +// cannot fix the singletons; a server per worker does. So each worker slot gets +// its own set — the editor test server, the export dev server it links to, and +// the Ollama stub — over its own data root (testPaths.ts): +// +// slot 0 the config's webServer entries, on the suite's own ports (PORT, +// EXPORT_PORT, OLLAMA_STUB_PORT), over the editor directory — the +// one-worker suite, unchanged +// slot n started by globalSetup on `slotPorts(n)`, over +// `.e2e-workers/w<n>`, stopped by globalTeardown +// +// The worker finds its own: Playwright evaluates the config again in every +// worker with TEST_PARALLEL_INDEX already set, so `baseURL`, +// PLAYWRIGHT_BASE_URL, EXPORT_PORT and testPaths() are the slot's before any +// spec is loaded. Specs change nothing. +// +// How many workers: E2E_WORKERS — a number (1–8), or `auto` for what memory +// allows at start, floor((MemAvailable − HEAVY_MIN_FREE_MB) / 1.5 GB) capped +// at 3. Unset: 1, until the full runs at 1, 2 and 3 workers say the suite is +// green in parallel (then the default becomes `auto`). + +import { spawn, execFileSync, type ChildProcess } from "node:child_process"; +import { closeSync, copyFileSync, existsSync, mkdirSync, openSync, readFileSync } from "node:fs"; +import net from "node:net"; +import { join } from "node:path"; +import { PORT_BASES, portFor } from "yt-dlp-transcript-common/lib/ports.mjs"; +import { EDITOR_ROOT, slotRoot, testPathsFor } from "./testPaths"; + +// THE TEST-ONLY SERVER ENVIRONMENT (the config's header documents each key). +export const E2E_SERVER_ENV: Record<string, string> = { + E2E_TEST_ROUTES: "1", + E2E_AUDIO_CHECK_INTERVAL_MS: "300", + E2E_AUDIO_CHECK_SIZE_GATE: "4096", + E2E_AUDIO_CHECK_INTERVAL_FLOOR_MS: "50", + E2E_AUDIO_CHECK_RECOVER_STEP_MS: "100", + E2E_AUDIO_CHECK_RECOVER_AFTER: "2", + E2E_BACKOFF_BASE_MS: "20000", + E2E_CLIP_WINDOW_GAP_MS: "2000", + E2E_LIVE_CHECK: "skip", + WRANGLER_BIN: join(EDITOR_ROOT, "e2e", "fixtures", "bin", "fake-wrangler.mjs"), + ARCHILYZER_BRANCH: "main", + CLOUDFLARE_API_TOKEN: "e2e-fake-token-never-sent", + EXPORT_NEXT_BIN: join(EDITOR_ROOT, "e2e", "fixtures", "bin", "fake-next.mjs"), +}; + +/** The start-mode build directory (scripts/e2e-stamp.mjs PACKAGES.editor.distDir). */ +export const E2E_DIST_DIR = ".next/e2e"; +const EXPORT_SITES_DIR = join(EDITOR_ROOT, "e2e", "fixtures", "sites"); +const DEFAULT_SETTINGS = join(EDITOR_ROOT, "e2e", "fixtures", "test-settings.default.json"); + +export type E2EMode = "start" | "dev"; +/** An environment to read (process.env, or a test's plain object). */ +export type Env = Readonly<Record<string, string | undefined>>; + +export function resolveE2EMode(env: Env = process.env): E2EMode { + const raw = (env.E2E_MODE ?? "").trim().toLowerCase(); + if (raw === "" || raw === "start") return "start"; + if (raw === "dev") return "dev"; + throw new Error(`E2E_MODE=${env.E2E_MODE} is not a mode: use start (the default) or dev`); +} + +// ------------------------------------------------------------------ workers + +export const AUTO_WORKER_CAP = 3; +export const MAX_WORKERS = 8; +export const WORKER_ESTIMATE_MB = 1500; + +function memAvailableMb(): number | null { + try { + const m = /^MemAvailable:\s+(\d+)\s*kB/m.exec(readFileSync("/proc/meminfo", "utf8")); + return m ? Math.floor(Number(m[1]) / 1024) : null; + } catch { + return null; + } +} + +/** + * How many workers (= server sets) this run uses. `E2E_WORKERS`: a number, or + * `auto` — floor((MemAvailable − floor) / 1.5 GB), 1 to 3. Unset: 1. + */ +export function resolveWorkers( + env: Env = process.env, + readAvailable: () => number | null = memAvailableMb, +): number { + const raw = (env.E2E_WORKERS ?? "").trim().toLowerCase(); + if (raw === "" || raw === "1") return 1; + if (raw === "auto") { + const avail = readAvailable(); + const floorRaw = Number(env.HEAVY_MIN_FREE_MB); + const floor = env.HEAVY_MIN_FREE_MB != null && env.HEAVY_MIN_FREE_MB !== "" && floorRaw >= 0 ? floorRaw : 6000; + if (avail == null) return 1; + return Math.max(1, Math.min(AUTO_WORKER_CAP, Math.floor((avail - floor) / WORKER_ESTIMATE_MB))); + } + const n = Number(raw); + if (!Number.isInteger(n) || n < 1) throw new Error(`E2E_WORKERS=${env.E2E_WORKERS}: a number of workers, or auto`); + return Math.min(MAX_WORKERS, n); +} + +// -------------------------------------------------------------------- ports + +export type SlotPorts = { editor: number; export: number; ollama: number }; + +/** + * A slot's three ports. Slot 0 is the suite's own (common/lib/ports.mjs, with + * the worktree's offset). Slot n takes three from the unused top of the + * worktree's block — `x060 + 3(n−1)` … — so no other worktree's ports, and no + * other suite's, are ever touched. + */ +export function slotPorts(slot: number, env: Env = process.env): SlotPorts { + if (slot <= 0) { + return { + editor: portFor("PORT", env), + export: portFor("EXPORT_PORT", env), + ollama: portFor("OLLAMA_STUB_PORT", env), + }; + } + const offset = portFor("PORT", env) - PORT_BASES.PORT; + const base = PORT_BASES.PORT + 49 + offset + 3 * (slot - 1); + return { editor: base, export: base + 1, ollama: base + 2 }; +} + +// ------------------------------------------------------------------ servers + +export type ServerSpec = { + name: "editor" | "export" | "ollama"; + /** A shell command line, run in EDITOR_ROOT. */ + command: string; + env: Record<string, string>; + /** Ready once this answers. */ + url: string; +}; + +/** The three servers of a slot — the one definition the config and globalSetup share. */ +export function slotServers(slot: number, mode: E2EMode, env: Env = process.env): ServerSpec[] { + const ports = slotPorts(slot, env); + const paths = testPathsFor(slotRoot(slot)); + const editorEnv: Record<string, string> = { ...E2E_SERVER_ENV }; + // A start-mode server runs the stamped build (shared, read-only); a second + // `next dev` needs a dist dir of its own (Next locks `<distDir>/dev/lock`). + if (mode === "start" && !env.CI) editorEnv.E2E_NEXT_DIST_DIR = E2E_DIST_DIR; + else if (mode === "dev" && slot > 0) editorEnv.E2E_NEXT_DIST_DIR = `.next/e2e-dev-w${slot}`; + if (slot > 0) { + Object.assign(editorEnv, { + PORT: String(ports.editor), + EXPORT_PORT: String(ports.export), + OLLAMA_STUB_PORT: String(ports.ollama), + E2E_DATA_ROOT: paths.root, + }); + } + return [ + { + name: "editor", + command: mode === "start" ? "pnpm start:test" : "pnpm dev:test", + env: editorEnv, + url: `http://localhost:${ports.editor}`, + }, + { + // The export server stays `next dev` in both modes (a static export + // bakes test-settings.json in at build time; see the config). Its own + // dist dir per slot: Next allows one `next dev` per dist dir, and the + // export suite's server may be running beside this suite. + name: "export", + command: `pnpm --filter export run dev --port ${ports.export}`, + env: { + SETTINGS_FILE: paths.settingsFile, + SITES_DIR: EXPORT_SITES_DIR, + SITE_ID: "testsite", + E2E_NEXT_DIST_DIR: slot > 0 ? `.next/e2e-editor-w${slot}` : ".next/e2e-editor", + }, + url: `http://localhost:${ports.export}`, + }, + { + name: "ollama", + command: `node ${join(EDITOR_ROOT, "e2e", "fixtures", "ollama-stub.mjs")}`, + env: { OLLAMA_STUB_PORT: String(ports.ollama) }, + // /api/tags is the endpoint digestApps.ts probes, so readiness and the + // app's reachability check agree. + url: `http://127.0.0.1:${ports.ollama}/api/tags`, + }, + ]; +} + +// ------------------------------------------------- slot servers (globalSetup) + +export type SlotHandle = { slot: number; stop: () => Promise<void> }; + +function portBusy(port: number): Promise<boolean> { + return new Promise((resolve) => { + const server = net.createServer(); + server.once("error", (err: NodeJS.ErrnoException) => resolve(err.code === "EADDRINUSE")); + server.listen({ port, host: "0.0.0.0", exclusive: true }, () => server.close(() => resolve(false))); + }); +} + +function culprit(port: number): string { + try { + const out = execFileSync("ss", ["-ltnpH", `sport = :${port}`], { encoding: "utf8" }); + const pid = /pid=(\d+)/.exec(out)?.[1]; + return pid ? `pid ${pid} (kill ${pid})` : "owner unknown — ss -ltnp"; + } catch { + return "owner unknown — ss -ltnp"; + } +} + +async function waitUntilUp(url: string, child: ChildProcess, timeoutMs: number, log: string): Promise<void> { + const t0 = Date.now(); + for (;;) { + if (child.exitCode != null || child.signalCode != null) { + throw new Error(`e2e servers: ${url} exited before it answered (${child.exitCode ?? child.signalCode}); see ${log}`); + } + try { + const res = await fetch(url, { signal: AbortSignal.timeout(5_000) }); + await res.arrayBuffer().catch(() => {}); + return; + } catch { + /* not up yet */ + } + if (Date.now() - t0 > timeoutMs) throw new Error(`e2e servers: ${url} did not answer in ${timeoutMs / 1000}s; see ${log}`); + await new Promise((r) => setTimeout(r, 500)); + } +} + +function stopGroup(child: ChildProcess): Promise<void> { + return new Promise((resolve) => { + if (child.exitCode != null || child.signalCode != null || !child.pid) return resolve(); + const kill = (sig: NodeJS.Signals) => { + try { + process.kill(-child.pid!, sig); // the whole group: pnpm, next, its workers + } catch { + /* gone */ + } + }; + const hard = setTimeout(() => kill("SIGKILL"), 10_000); + child.once("exit", () => { + clearTimeout(hard); + resolve(); + }); + kill("SIGTERM"); + }); +} + +/** + * Start slot `slot`'s servers over its own data root and wait until each + * answers. Refuses (naming the pid) a port that is already bound: nothing + * else may answer as this slot's server. + */ +export async function startSlot(slot: number, mode: E2EMode, timeoutMs = 120_000): Promise<SlotHandle> { + const specs = slotServers(slot, mode); + const ports = slotPorts(slot); + for (const p of [ports.editor, ports.export, ports.ollama]) { + if (await portBusy(p)) { + throw new Error(`e2e servers: slot ${slot}'s port ${p} is already in use — ${culprit(p)}; a leftover from a killed run?`); + } + } + const paths = testPathsFor(slotRoot(slot)); + mkdirSync(join(paths.transcriptsDir, "channels"), { recursive: true }); + if (!existsSync(paths.settingsFile)) copyFileSync(DEFAULT_SETTINGS, paths.settingsFile); + const children: ChildProcess[] = []; + const stop = async () => { + await Promise.all(children.map(stopGroup)); + }; + try { + await Promise.all( + specs.map(async (s) => { + const log = join(paths.root, `server-${s.name}.log`); + const fd = openSync(log, "w"); + const child = spawn("sh", ["-c", s.command], { + cwd: EDITOR_ROOT, + env: { ...process.env, ...s.env }, + stdio: ["ignore", fd, fd], + detached: true, // its own process group, so stop() reaps the tree + }); + closeSync(fd); + children.push(child); + await waitUntilUp(s.url, child, timeoutMs, log); + }), + ); + } catch (err) { + await stop(); + throw err; + } + return { slot, stop }; +} diff --git a/editor/e2e/servers.unit.ts b/editor/e2e/servers.unit.ts @@ -0,0 +1,90 @@ +// Unit tests for the per-worker server sets (e2e/servers.ts), the data roots +// (e2e/testPaths.ts) and the @serial list (e2e/serial.ts). Named `.unit.ts` so +// Playwright's own testMatch never collects it; run by `pnpm --filter editor test`. +import assert from "node:assert/strict"; +import { existsSync } from "node:fs"; +import { join } from "node:path"; +import test from "node:test"; +import { SERIAL_SPECS, SERIAL_SPEC_PATTERN } from "./serial"; +import { resolveWorkers, slotPorts, slotServers } from "./servers"; +import { EDITOR_ROOT, slotRoot, testPaths } from "./testPaths"; + +test("resolveWorkers: 1 by default, a number capped at 8, auto from memory capped at 3", () => { + assert.equal(resolveWorkers({}), 1); + assert.equal(resolveWorkers({ E2E_WORKERS: "2" }), 2); + assert.equal(resolveWorkers({ E2E_WORKERS: "99" }), 8); + assert.throws(() => resolveWorkers({ E2E_WORKERS: "two" }), /a number of workers, or auto/); + const auto = (mb: number | null, env: Record<string, string> = {}) => + resolveWorkers({ E2E_WORKERS: "auto", ...env }, () => mb); + assert.equal(auto(12_000), 3); // (12000 − 6000) / 1500 = 4, capped + assert.equal(auto(9_100), 2); + assert.equal(auto(7_400), 1); + assert.equal(auto(3_000), 1); + assert.equal(auto(null), 1); + assert.equal(auto(9_100, { HEAVY_MIN_FREE_MB: "3000" }), 3); +}); + +test("slotPorts: slot 0 is the suite's own; slot n takes three from the top of the worktree's block", () => { + assert.deepEqual(slotPorts(0, {}), { editor: 3011, export: 3010, ollama: 11435 }); + assert.deepEqual(slotPorts(1, {}), { editor: 3060, export: 3061, ollama: 3062 }); + assert.deepEqual(slotPorts(2, {}), { editor: 3063, export: 3064, ollama: 3065 }); + // A worktree at offset 2000 (PORT=5011, the injector's): its own block. + const wt = { PORT: "5011", EXPORT_PORT: "5010", OLLAMA_STUB_PORT: "13435" }; + assert.deepEqual(slotPorts(0, wt), { editor: 5011, export: 5010, ollama: 13435 }); + assert.deepEqual(slotPorts(3, wt), { editor: 5066, export: 5067, ollama: 5068 }); + // Eight slots stay inside the block of a hundred. + assert.ok(slotPorts(7, {}).ollama < 3100); +}); + +test("slotServers: slot 0 is the webServer of before; slot n is its own data root, ports and dist dirs", () => { + const [editor0, export0, ollama0] = slotServers(0, "start", {}); + assert.equal(editor0.command, "pnpm start:test"); + assert.equal(editor0.url, "http://localhost:3011"); + assert.equal(editor0.env.E2E_NEXT_DIST_DIR, ".next/e2e"); + assert.equal(editor0.env.E2E_DATA_ROOT, undefined); + assert.equal(editor0.env.PORT, undefined); + assert.equal(export0.env.SETTINGS_FILE, join(EDITOR_ROOT, "test-settings.json")); + assert.equal(export0.env.E2E_NEXT_DIST_DIR, ".next/e2e-editor"); + assert.equal(ollama0.url, "http://127.0.0.1:11435/api/tags"); + + const [editor2, export2, ollama2] = slotServers(2, "dev", {}); + assert.equal(editor2.command, "pnpm dev:test"); + assert.equal(editor2.env.E2E_DATA_ROOT, join(EDITOR_ROOT, ".e2e-workers", "w2")); + assert.equal(editor2.env.PORT, "3063"); + assert.equal(editor2.env.OLLAMA_STUB_PORT, "3065"); + assert.equal(editor2.env.E2E_NEXT_DIST_DIR, ".next/e2e-dev-w2"); + assert.equal(export2.command, "pnpm --filter export run dev --port 3064"); + assert.equal(export2.env.SETTINGS_FILE, join(EDITOR_ROOT, ".e2e-workers", "w2", "test-settings.json")); + assert.equal(export2.env.E2E_NEXT_DIST_DIR, ".next/e2e-editor-w2"); + assert.equal(ollama2.env.OLLAMA_STUB_PORT, "3065"); + // A start-mode slot serves the one stamped build. + assert.equal(slotServers(2, "start", {})[0].env.E2E_NEXT_DIST_DIR, ".next/e2e"); +}); + +test("testPaths: the editor directory for slot 0, the slot's own root for a worker, E2E_DATA_ROOT over both", () => { + const saved = { idx: process.env.TEST_PARALLEL_INDEX, root: process.env.E2E_DATA_ROOT }; + try { + delete process.env.E2E_DATA_ROOT; + delete process.env.TEST_PARALLEL_INDEX; + assert.equal(testPaths().transcriptsDir, join(EDITOR_ROOT, "test-transcripts")); + process.env.TEST_PARALLEL_INDEX = "0"; + assert.equal(testPaths().settingsFile, join(EDITOR_ROOT, "test-settings.json")); + process.env.TEST_PARALLEL_INDEX = "2"; + assert.equal(testPaths().root, slotRoot(2)); + assert.equal(testPaths().transcriptsDir, join(EDITOR_ROOT, ".e2e-workers", "w2", "test-transcripts")); + process.env.E2E_DATA_ROOT = "/somewhere/else"; + assert.equal(testPaths().settingsFile, "/somewhere/else/test-settings.json"); + } finally { + if (saved.idx == null) delete process.env.TEST_PARALLEL_INDEX; + else process.env.TEST_PARALLEL_INDEX = saved.idx; + if (saved.root == null) delete process.env.E2E_DATA_ROOT; + else process.env.E2E_DATA_ROOT = saved.root; + } +}); + +test("the @serial list names spec files that exist, and matches whole names only", () => { + for (const f of SERIAL_SPECS) assert.ok(existsSync(join(EDITOR_ROOT, "e2e", f)), f); + assert.ok(SERIAL_SPEC_PATTERN.test("/x/editor/e2e/pacing.spec.ts")); + assert.ok(!SERIAL_SPEC_PATTERN.test("/x/editor/e2e/my-pacing.spec.ts")); + assert.ok(!SERIAL_SPEC_PATTERN.test("/x/editor/e2e/build.spec.tsx")); +}); diff --git a/editor/e2e/testPaths.ts b/editor/e2e/testPaths.ts @@ -5,11 +5,18 @@ import { fileURLToPath } from "node:url"; // and the config (plans/e2e-speed.md S5: a server per worker needs every path a // spec touches to come from the worker's own root, not a literal). // -// The root is the editor directory unless E2E_DATA_ROOT names another; under it -// sit the same names the suite has always used. `dev:test` / `start:test` read -// the same variable (`${E2E_DATA_ROOT:-$(pwd)}`), so a server and the specs -// that drive it agree by construction. Nothing sets it yet: one worker, the -// editor directory, exactly the paths of before. +// The root is the editor directory for the first worker (slot 0), and +// `.e2e-workers/w<slot>` for the others (one server set per worker, started by +// globalSetup — e2e/servers.ts); E2E_DATA_ROOT, when set, wins. Under it sit +// the same names the suite has always used. `dev:test` / `start:test` read the +// same variable (`${E2E_DATA_ROOT:-$(pwd)}`), so a server and the specs that +// drive it agree by construction. One worker: the editor directory, exactly +// the paths of before. +// +// The slot is Playwright's TEST_PARALLEL_INDEX (0 … workers−1, kept by a +// restarted worker; not TEST_WORKER_INDEX, which grows with every restart). It +// is set before the worker loads anything, so a spec's top-level constant +// built from testPaths() is already its worker's. // // E2E_-prefixed on purpose, never TRANSCRIPTS_DIR / SETTINGS_FILE: a // `--share-data` worktree's `.worktree-env` sets TRANSCRIPTS_DIR to the REAL @@ -44,8 +51,19 @@ export function testPathsFor(root: string): TestPaths { }; } +/** The data root of a worker slot: the editor directory for slot 0. */ +export function slotRoot(slot: number): string { + return slot > 0 ? join(EDITOR_ROOT, ".e2e-workers", `w${slot}`) : EDITOR_ROOT; +} + +/** This process's worker slot (0 outside a Playwright worker). */ +export function currentSlot(env: Readonly<Record<string, string | undefined>> = process.env): number { + const n = Number(env.TEST_PARALLEL_INDEX); + return Number.isInteger(n) && n > 0 ? n : 0; +} + /** This process's test data paths (read per call, so a worker's env applies). */ export function testPaths(): TestPaths { const root = process.env.E2E_DATA_ROOT?.trim(); - return testPathsFor(root ? resolve(root) : EDITOR_ROOT); + return testPathsFor(root ? resolve(root) : slotRoot(currentSlot())); } diff --git a/editor/package.json b/editor/package.json @@ -9,7 +9,7 @@ "start:test": "WORKER_TOKEN=test-worker-token TRANSCRIPTS_DIR=${E2E_DATA_ROOT:-$(pwd)}/test-transcripts EXPORT_PUBLIC_DIR=${E2E_DATA_ROOT:-$(pwd)}/test-transcripts/.export-public SETTINGS_FILE=${E2E_DATA_ROOT:-$(pwd)}/test-settings.json EDITOR_CHANGELOG_FILE=${E2E_DATA_ROOT:-$(pwd)}/test-changelog.md EXPORT_CHANGELOG_FILE=${E2E_DATA_ROOT:-$(pwd)}/test-export-changelog.md YTDLP_BIN=$(pwd)/e2e/fixtures/bin/fake-ytdlp.mjs GALLERY_DL_BIN=$(pwd)/e2e/fixtures/bin/fake-gallery-dl.mjs WHISPER_BIN=$(pwd)/e2e/fixtures/bin/fake-whisper.mjs WHISPER_MODEL=/dev/null CHOUGH_BIN=$(pwd)/e2e/fixtures/bin/fake-chough.mjs CHOUGH_MODEL=/dev/null PARAKEET_STITCH_BIN=$(pwd)/e2e/fixtures/bin/fake-parakeet-stitch.mjs PARAKEET_CLI=/dev/null PARAKEET_MODEL=/dev/null DIARIZE_BIN=$(pwd)/e2e/fixtures/bin/fake-diarize.mjs FFMPEG_BIN=$(pwd)/e2e/fixtures/bin/fake-ffmpeg.mjs FFPROBE_BIN=$(pwd)/e2e/fixtures/bin/fake-ffprobe.mjs OLLAMA_URL=http://127.0.0.1:${OLLAMA_STUB_PORT:-11435} CLAUDE_BIN=$(pwd)/e2e/fixtures/bin/fake-claude.mjs FINDMNT_BIN=$(pwd)/e2e/fixtures/bin/fake-findmnt.mjs UDISKSCTL_BIN=$(pwd)/e2e/fixtures/bin/fake-udisksctl.mjs next start --port ${PORT:-3011}", "build": "next build", "start": "UV_THREADPOOL_SIZE=${UV_THREADPOOL_SIZE:-16} next start --port ${EDITOR_PORT:-3001}", - "test": "tsx --test \"app/**/*.test.ts\"", + "test": "tsx --test \"app/**/*.test.ts\" \"e2e/*.unit.ts\"", "e2e": "node ../scripts/queue-lock.mjs --name e2e-editor --estimate 1500 --prebuild editor --ports PORT:3011,EXPORT_PORT:3010,OLLAMA_STUB_PORT:11435 -- playwright test", "e2e:ui": "playwright test --ui" }, diff --git a/editor/playwright.config.ts b/editor/playwright.config.ts @@ -1,13 +1,14 @@ import { spawnSync } from "node:child_process"; import path from "node:path"; import { defineConfig, devices } from "@playwright/test"; -import { portFor } from "yt-dlp-transcript-common/lib/ports.mjs"; -import { testPaths } from "./e2e/testPaths"; +import { SERIAL_SPEC_PATTERN } from "./e2e/serial"; +import { resolveE2EMode, resolveWorkers, slotPorts, slotServers } from "./e2e/servers"; +import { currentSlot } from "./e2e/testPaths"; // THE TEST-ONLY ENVIRONMENT, declared here (one-core Phase 4 slice 3). Every // variable only a harness reads carries the E2E_ prefix; the ones this config -// sets for the editor's test server are E2E_SERVER_ENV (passed as the -// webServer's env below), and the rest are knobs a spec or a person sets: +// sets for the editor's test server are E2E_SERVER_ENV (e2e/servers.ts, the +// env of every slot's editor), and the rest are knobs a spec or a person sets: // // E2E_TEST_ROUTES=1 opens /api/test/* (api/test/_guard.ts) and makes // the boot settle a test server's leftover jobs @@ -46,6 +47,9 @@ import { testPaths } from "./e2e/testPaths"; // `test-settings.json`, the disposable changelogs. // Read by `dev:test`/`start:test` and by the // specs' testPaths() (e2e/testPaths.ts) +// E2E_WORKERS how many workers, each with its own server set +// (e2e/servers.ts): a number, or `auto` for what +// memory allows (cap 3). Default 1 // E2E_RACK_SHOTS=1 run the /channels rack screenshot audit // E2E_FAKE_YTDLP_AUDIO_CHECK_MODE, E2E_FAKE_YTDLP_CHUNK_DELAY_MS, // E2E_FAKE_YTDLP_CORRUPT_AFTER_CHUNK, E2E_FAKE_YTDLP_CORRUPT_RUNS, @@ -94,44 +98,19 @@ import { testPaths } from "./e2e/testPaths"; // worktree by scripts/worktree.mjs and named in queue-lock's --ports list. Nor // are the queue's own E2E_QUEUE / E2E_PORT_CHECK / E2E_QUEUE_TIMEOUT (read by // scripts/queue-lock.mjs, shared machine-wide). ENVIRONMENT.md lists them all. -const E2E_SERVER_ENV = { - E2E_TEST_ROUTES: "1", - E2E_AUDIO_CHECK_INTERVAL_MS: "300", - E2E_AUDIO_CHECK_SIZE_GATE: "4096", - E2E_AUDIO_CHECK_INTERVAL_FLOOR_MS: "50", - E2E_AUDIO_CHECK_RECOVER_STEP_MS: "100", - E2E_AUDIO_CHECK_RECOVER_AFTER: "2", - E2E_BACKOFF_BASE_MS: "20000", - E2E_CLIP_WINDOW_GAP_MS: "2000", - E2E_LIVE_CHECK: "skip", - WRANGLER_BIN: path.resolve(process.cwd(), "e2e", "fixtures", "bin", "fake-wrangler.mjs"), - ARCHILYZER_BRANCH: "main", - CLOUDFLARE_API_TOKEN: "e2e-fake-token-never-sent", - EXPORT_NEXT_BIN: path.resolve(process.cwd(), "e2e", "fixtures", "bin", "fake-next.mjs"), -}; - -const PORT = portFor("PORT"); -const baseURL = `http://localhost:${PORT}`; -// Expose the assigned base URL to node-side spec code (fetches to the editor's -// test API). Keeps offset-port worktrees working even when run directly without -// the worktree wrapper. See e2e/baseUrl.ts. -process.env.PLAYWRIGHT_BASE_URL = baseURL; +// The servers' environment, ports and commands live in e2e/servers.ts — one +// definition for slot 0 (the webServer entries below) and for every other +// worker slot (globalSetup). +const E2E_MODE = resolveE2EMode(); +const STAMPED_BUILD = E2E_MODE === "start" && !process.env.CI; // START MODE BY DEFAULT (plans/e2e-speed.md, S1): the same tests took 0.32× the // time under `next start` — a polled route recompiles under `next dev`. Before // any server starts, scripts/e2e-stamp.mjs compares the build's stamp with the // tree and rebuilds when they differ (it says which, and why), so a start-mode // run cannot serve a stale build. CI — the sharded image, which runs its own -// `next build` into `.next` — keeps that build and skips the stamp. -const E2E_MODE = (() => { - const raw = (process.env.E2E_MODE ?? "").trim().toLowerCase(); - if (raw === "" || raw === "start") return "start"; - if (raw === "dev") return "dev"; - throw new Error(`E2E_MODE=${process.env.E2E_MODE} is not a mode: use start (the default) or dev`); -})(); -const STAMPED_BUILD = E2E_MODE === "start" && !process.env.CI; -// The same directory as scripts/e2e-stamp.mjs PACKAGES.editor.distDir. -const E2E_DIST_DIR = ".next/e2e"; +// `next build` into `.next` — keeps that build and skips the stamp. A run +// through queue-lock's `--prebuild` has ensured it already (E2E_BUILD_CHECKED). if (STAMPED_BUILD && !process.env.E2E_BUILD_CHECKED) { const ensured = spawnSync( process.execPath, @@ -146,32 +125,50 @@ if (STAMPED_BUILD && !process.env.E2E_BUILD_CHECKED) { } process.env.E2E_BUILD_CHECKED = "1"; } -const webServerCommand = E2E_MODE === "start" ? "pnpm start:test" : "pnpm dev:test"; -const webServerEnv: Record<string, string> = STAMPED_BUILD - ? { ...E2E_SERVER_ENV, E2E_NEXT_DIST_DIR: E2E_DIST_DIR } - : E2E_SERVER_ENV; -// The digest lane's local engine is reached over HTTP, not spawned, so it gets a -// webServer entry instead of a fake binary in e2e/fixtures/bin/. Its port is -// exported so the editor's dev:test / start:test scripts point OLLAMA_URL at the -// same place, and so an offset-port worktree does not collide. -const OLLAMA_STUB_PORT = portFor("OLLAMA_STUB_PORT"); -process.env.OLLAMA_STUB_PORT = String(OLLAMA_STUB_PORT); +// WORKERS (plans/e2e-speed.md S5): one server set per worker slot. This file +// is evaluated again in every worker with TEST_PARALLEL_INDEX set, so from here +// on the ports, the base URL and the data root are the slot's (e2e/servers.ts). +const WORKERS = resolveWorkers(); +// Pinned for the workers, which evaluate this file again: `auto` read twice +// could read different memory, and a worker's project list must be the +// runner's. +process.env.E2E_WORKERS = String(WORKERS); +const SLOT = currentSlot(); +const ports = slotPorts(SLOT); +const baseURL = `http://localhost:${ports.editor}`; +// Node-side spec code (fetches to the editor's test API, e2e/baseUrl.ts) and +// the export specs (portFor("EXPORT_PORT")) read these. +process.env.PLAYWRIGHT_BASE_URL = baseURL; +process.env.EXPORT_PORT = String(ports.export); +// The digest lane's local engine is reached over HTTP, not spawned, so it gets +// a server instead of a fake binary in e2e/fixtures/bin/. Exported so the +// editor's dev:test / start:test scripts point OLLAMA_URL at the same place. +process.env.OLLAMA_STUB_PORT = String(ports.ollama); + +// Slot 0's servers: the webServer entries Playwright starts (and reuses, out of +// CI). Slots 1… are globalSetup's. +const slot0 = slotServers(0, E2E_MODE); +const webServer = slot0.map((s) => ({ + command: s.command, + url: s.url, + timeout: s.name === "ollama" ? 30_000 : 120_000, + reuseExistingServer: !process.env.CI, + env: s.env, +})); -const EXPORT_PORT = portFor("EXPORT_PORT"); -const exportBaseURL = `http://localhost:${EXPORT_PORT}`; -// Share the editor's test-settings.json with the export server so the -// footer (and any other server-rendered settings consumers) can be -// driven from a single fixture file during E2E. -const exportSettingsFile = testPaths().settingsFile; -// Footer/branding on the export server now come from a per-site config -// (currentSite()), so point it at a fixture site for deterministic E2E. -const exportSitesDir = path.resolve( - process.cwd(), - "e2e", - "fixtures", - "sites", -); +// @serial: spec files that time wall-clock behaviour under contention, or +// write into the checkout's own build outputs (export/out, homepage/out — +// shared by every slot), run after the parallel project, on one worker +// (e2e/serial.ts). With one worker there is one project, as before. +const browser = { ...devices["Desktop Chrome"] }; +const projects = + WORKERS > 1 + ? [ + { name: "chromium", use: browser, testIgnore: SERIAL_SPEC_PATTERN, teardown: "serial" }, + { name: "serial", use: browser, testMatch: SERIAL_SPEC_PATTERN, workers: 1 }, + ] + : [{ name: "chromium", use: browser }]; export default defineConfig({ testDir: "./e2e", @@ -179,7 +176,8 @@ export default defineConfig({ // Reap fixture binaries that outlived their run — before this one starts (a // SIGKILLed run never gets to clean up after itself) and again after it ends. // Both log anything they find, because by construction they should find - // nothing. See e2e/fixtureProcs.ts. + // nothing. See e2e/fixtureProcs.ts. With more than one worker, globalSetup + // also starts slots 1…'s servers, and globalTeardown stops them. globalSetup: "./e2e/globalSetup.ts", globalTeardown: "./e2e/globalTeardown.ts", // The sharded runner sets CI=true for `reuseExistingServer: !CI` below, not @@ -198,77 +196,31 @@ export default defineConfig({ ["../scripts/e2e-timings-reporter.mjs", { outputFile: "test-results/timings.json" }], ], outputDir: "test-results/", - // Serial, one worker — deliberate, and not a performance oversight. Three - // pieces of shared mutable state are global to the whole run, so two workers - // corrupt each other's fixtures rather than merely running slower: + // ONE WORKER BY DEFAULT; E2E_WORKERS for more (e2e/servers.ts). Two workers + // over ONE server corrupt each other's fixtures rather than merely running + // slower: // - // 1. One hardcoded data root (e2e/helpers.ts:17) that 303 resetData() calls - // across 83 of the 87 spec files destroy and recreate — mostly from - // *inside* test bodies (e2e/helpers.ts:33-48), not just in beforeEach. - // 2. One shared test-settings.json (e2e/helpers.ts:18) that the export - // webServer below also reads as SETTINGS_FILE (see exportSettingsFile) — - // so resetData's rm+cp deletes a file a second live server is reading. - // 3. Four globalThis singletons inside the single Next server — job - // registry, worker pool, scheduler, auto-runner — cleared on every - // resetData/writeSettings via - // app/api/test/invalidate-cache/route.ts:24,32,38,44. + // 1. One data root that resetData() destroys and recreates — mostly from + // *inside* test bodies, not just in beforeEach. + // 2. One test-settings.json that the export server also reads as + // SETTINGS_FILE — so resetData's rm+cp deletes a file a second live + // server is reading. + // 3. The globalThis singletons inside the Next server — job registry, + // worker pool, scheduler, auto-runner — cleared on every + // resetData/writeSettings via app/api/test/invalidate-cache/route.ts. // - // (3) is the blocker that per-worker TRANSCRIPTS_DIR/SETTINGS_FILE cannot - // fix: the singletons live in the server process, so isolation needs a - // *server per worker*, not a directory per worker. That is why parallelism - // here is one container per shard (scripts/run-sharded-e2e.mjs, which gives - // each shard its own servers) rather than workers > 1 in this config. + // (3) is why per-worker directories alone cannot fix it: the singletons live + // in the server process, so each worker gets a SERVER of its own (and its own + // data root and settings file — testPaths.ts). Files stay whole per worker + // (fullyParallel: false): a spec's tests share its data in order. fullyParallel: false, - workers: 1, - webServer: [ - { - command: webServerCommand, - url: baseURL, - timeout: 120_000, - reuseExistingServer: !process.env.CI, - env: webServerEnv, - }, - { - // The export server stays `next dev` in both modes. The export is a - // STATIC export (output: "export"): a build bakes test-settings.json and - // the fixture site in at build time, so export-search.spec's settings - // rewrite would be asserted against a page that cannot see it; and the - // two spec files that use this server ran 42 s in all in release 19's - // start-mode run — less than one export build costs. - command: `pnpm --filter export run dev --port ${EXPORT_PORT}`, - url: exportBaseURL, - timeout: 120_000, - reuseExistingServer: !process.env.CI, - env: { - SETTINGS_FILE: exportSettingsFile, - SITES_DIR: exportSitesDir, - SITE_ID: "testsite", - // Its own dist dir: Next allows one `next dev` per dist dir, and the - // export suite's server may be running beside this suite (release 24, - // plans/e2e-speed.md S4 — each suite queues under its own name). - E2E_NEXT_DIST_DIR: ".next/e2e-editor", - }, - }, - { - command: `node ${path.resolve(process.cwd(), "e2e", "fixtures", "ollama-stub.mjs")}`, - // /api/tags is the same endpoint digestApps.ts probes, so playwright's - // readiness check and the app's own reachability check agree. - url: `http://127.0.0.1:${OLLAMA_STUB_PORT}/api/tags`, - timeout: 30_000, - reuseExistingServer: !process.env.CI, - env: { OLLAMA_STUB_PORT: String(OLLAMA_STUB_PORT) }, - }, - ], + workers: WORKERS, + webServer, use: { baseURL, trace: "on-first-retry", screenshot: "only-on-failure", video: "retain-on-failure", }, - projects: [ - { - name: "chromium", - use: { ...devices["Desktop Chrome"] }, - }, - ], + projects, });