Files
PaperClipAI/tests/e2e/playwright.config.ts
T
Dotta 7563842165 perf(ci): cut E2E ceiling under 95s via 16 AWS shards, 8-core speedup, top serial splits, and parallel UI build (#22960)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - Live 8-core PR runs (`45668834558`, `45667106472`) showed
`e2e_shards` was the #1 critical-path bottleneck on normal PRs
(`152–171s` test step) due to four compounding causes:
> 1. `scripts/e2e-shard.mjs` still used the 4-vCPU
`EFFECTIVE_PARALLEL_SPEEDUP = 1.85` even on 8-vCPU runners running 4
Playwright workers (`~3.35x` measured speedup), under-allocating serial
shards (`5` serial shards running `96–124s` while parallel shards sat
idle after `55–78s`).
> 2. `scripts/e2e-shard-durations.json` had stale weights
(`chat-adapters-ui-providers.spec.ts` `86.8s` vs `117–165s` actual;
`acp-stop-continuation.spec.ts` `69.3s` vs `88–102s` actual).
> 3. Three serial (`1-worker`) specs pinned the floor at `75–91s`:
`agent-configuration.spec.ts` (`91.4s`), `agent-chat-sessions.spec.ts`
(`79.9s`), and `onboarding.spec.ts` (`75.3s`).
> 4. `playwright.config.ts` ran `vite build ui` (`~5.4s`) serially
before starting embedded Postgres + 512 migrations (`~21s`) even though
database bootstrap does not read `server/ui-dist`.
> - This pull request overlaps the unminified Vite UI build with
Postgres bootstrap inside `start-e2e-server.ts`, splits the top 3 serial
specs into 6 balanced specs (keeping all 3 anchor filenames and 100% of
20 tests intact), makes `e2e-shard.mjs` CPU-aware (`3.2x` on 8-vCPU /
`1.85x` on 4-vCPU), refreshes all 58 specs in
`e2e-shard-durations.json`, and scales AWS `e2e_shards` `12 -> 16` while
keeping `ubuntu-latest` hosted at `4` — bringing simulated E2E test
execution to `~90–96s` (`-60 to -75s`).

## Linked Issues or Issue Description

Refs #22804

**What existing behavior does this improve?**
E2E shard wall-clock ceiling on 8-core PR runners (`tests/e2e/`,
`scripts/e2e-shard.mjs`, `scripts/e2e-shard-durations.json`,
`.github/ci-task-matrix.json`, `.github/workflows/pr-trusted.yml`).

**Subsystem affected**
tests/e2e/ and CI — Playwright server bootstrap, serial spec sharding,
and E2E shard matrix

**Current behavior**
E2E shards take `152–171s` on 8-core runners because `vite build ui`
runs serially before Postgres boot, 3 serial specs run `75–91s` each,
`e2e-shard.mjs` assumes 4-vCPU `1.85x` parallel speedup, and AWS runs 12
shards.

**Proposed behavior**
Overlap unminified Vite UI build with embedded Postgres boot in
`tests/e2e/start-e2e-server.ts`, split the top 3 serial specs into 6
balanced specs (preserving anchor paths and all tests), use CPU-aware
parallel speedup (`3.2x` on 8-vCPU / `1.85x` on 4-vCPU) with refreshed
58-spec durations, and run 16 AWS E2E shards (`8 serial + 8 parallel`,
`59.7–76.5s` Playwright) while keeping `ubuntu-latest` hosted at `4`.

## What Changed

- **Overlapped UI build with Postgres bootstrap
(`tests/e2e/playwright.config.ts`, `tests/e2e/start-e2e-server.ts`):**
- Launches `start-e2e-server.ts` directly with `PAPERCLIP_E2E_BUILD_UI`
(`0` when `PAPERCLIP_E2E_SKIP_UI_BUILD=1`), overlapping `vite build ui
--outDir ../server/ui-dist --emptyOutDir --minify false` concurrently
inside `Promise.all([dbPromise, import("../../server/src/index.js"),
uiReady])` with `stopUiBuild()` and `dbPromise` cleanup on
signals/failure, plus `maintenance_work_mem = 128MB` / `work_mem = 32MB`
on disposable PG.
- **Split top 3 serial E2E specs (100% of 20 tests preserved, all 3
anchor filenames & `maps/` links intact, all 3 new siblings registered
in BOTH `playwright.config.ts` and `scripts/e2e-shard.mjs`
`SERIAL_SPECS`):**
- `agent-configuration.spec.ts` (3 tests) +
`agent-configuration-revisions.spec.ts` (5 tests) +
`agent-configuration.shared.ts`
- `agent-chat-sessions.spec.ts` (3 tests) +
`agent-chat-sessions-navigation.spec.ts` (3 tests)
- `onboarding.spec.ts` (3 tests) + `onboarding-resume.spec.ts` (3 tests)
- **CPU-aware speedup, refreshed 58-spec manifest, & 16 AWS E2E shards
(`scripts/e2e-shard.mjs`, `scripts/e2e-shard-durations.json`,
`.github/ci-task-matrix.json`, `.github/workflows/pr-trusted.yml`,
`.github/scripts/tests/ci-plan.test.mjs`,
`scripts/__tests__/e2e-shard.test.mjs`):**
- Exported `EFFECTIVE_PARALLEL_SPEEDUP_4W = 3.2` and
`resolveEffectiveParallelSpeedup(cpus)` matching `playwright.config.ts`
worker scaling.
- Refreshed all 58/58 spec weights from live 8-core runs `45668834558` &
`45667106472`.
- Scaled AWS `e2e_shards` `12 -> 16` while keeping `ubuntu-latest`
hosted at `4`.

## Verification

- `node --test scripts/__tests__/e2e-shard.test.mjs
.github/scripts/tests/ci-plan.test.mjs
scripts/check-test-budget.test.mjs
scripts/__tests__/merge-queue-checks-workflow.test.mjs` — **45/45 PASS**
- `npx playwright test --config tests/e2e/playwright.config.ts --list`
on all 6 split specs — **20 tests in 6 files**
- `tsc --strict --noEmit` across all 9 edited `tests/e2e/*.ts` files —
**0 errors**
- `node scripts/check-test-budget.mjs --base origin/master` and `node
scripts/check-maps.mjs` — **PASS**
- `ruby -ryaml -e 'YAML.load_file(".github/workflows/pr-trusted.yml")'`
— **YAML OK**

## Risks

- Low risk: all 3 original serial spec anchor filenames remain intact,
`PAPERCLIP_E2E_SKIP_UI_BUILD=1` is preserved, signal/failure handlers
clean up both the Vite child and embedded PG, `ubuntu-latest` stays at 4
hosted shards, and full CI runs all E2E shards live before merge.

## Model Used

- Gemini 4 Neon (High) via Antigravity agent swarm (`e2e-opt`,
`verifier`, `ci-pipeline`).

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
2026-11-25 13:40:52 -06:00

210 lines
8.9 KiB
TypeScript

import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { defineConfig } from "@playwright/test";
// Use a dedicated port so e2e tests always start their own server in local_trusted mode,
// even when the dev server is running on :3100 in authenticated mode.
const PORT = Number(process.env.PAPERCLIP_E2E_PORT ?? 3199);
const BASE_URL = `http://127.0.0.1:${PORT}`;
const PAPERCLIP_HOME = fs.mkdtempSync(path.join(os.tmpdir(), "paperclip-e2e-home-"));
const PAPERCLIP_INSTANCE_ID = "playwright-e2e";
const PAPERCLIP_CONFIG = path.join(PAPERCLIP_HOME, "instances", PAPERCLIP_INSTANCE_ID, "config.json");
const PAPERCLIP_AGENT_JWT_SECRET = process.env.PAPERCLIP_AGENT_JWT_SECRET ?? "playwright-e2e-agent-jwt-secret";
const PAPERCLIP_DECISION_SIGNING_SECRET =
process.env.PAPERCLIP_DECISION_SIGNING_SECRET ?? "playwright-e2e-decision-signing-secret";
const PAPERCLIP_TOOL_ACTION_SIGNING_SECRET =
process.env.PAPERCLIP_TOOL_ACTION_SIGNING_SECRET ?? "playwright-e2e-tool-action-signing-secret";
const PLAYWRIGHT_CHANNEL = process.env.PAPERCLIP_PLAYWRIGHT_CHANNEL;
process.env.PAPERCLIP_HOME = PAPERCLIP_HOME;
process.env.PAPERCLIP_CONFIG = PAPERCLIP_CONFIG;
// Worker processes reload this config; retain the main process's server path
// for specs that seed historical database state in the throwaway instance.
process.env.PAPERCLIP_E2E_SERVER_CONFIG ??= PAPERCLIP_CONFIG;
// Specs that mint agent JWTs in-process (via createLocalAgentJwt) must derive
// the same per-instance signing key as the webServer, or verification fails
// with a 401 instead of authenticating as the agent.
process.env.PAPERCLIP_INSTANCE_ID = PAPERCLIP_INSTANCE_ID;
process.env.PAPERCLIP_AGENT_JWT_SECRET = PAPERCLIP_AGENT_JWT_SECRET;
process.env.PAPERCLIP_DECISION_SIGNING_SECRET = PAPERCLIP_DECISION_SIGNING_SECRET;
process.env.PAPERCLIP_TOOL_ACTION_SIGNING_SECRET = PAPERCLIP_TOOL_ACTION_SIGNING_SECRET;
const REPO_ROOT = path.resolve(import.meta.dirname, "../..");
const UI_DIST_INDEX = path.join(REPO_ROOT, "server", "ui-dist", "index.html");
const SKIP_UI_BUILD = ["1", "true"].includes(
(process.env.PAPERCLIP_E2E_SKIP_UI_BUILD ?? "").trim().toLowerCase(),
);
if (SKIP_UI_BUILD && !fs.existsSync(UI_DIST_INDEX)) {
throw new Error(
`PAPERCLIP_E2E_SKIP_UI_BUILD is enabled, but prebuilt UI assets are missing at ${UI_DIST_INDEX}. ` +
"Build @paperclipai/ui into server/ui-dist first or unset PAPERCLIP_E2E_SKIP_UI_BUILD.",
);
}
// Specs that mutate instance-wide state on the shared throwaway server
// (server-read experimental flags or server-persisted workspace preferences)
// or assert strict real-time latency / focus restoration sensitive to
// multi-worker Chromium CPU contention. Keep in sync with `SERIAL_SPECS` in
// `scripts/e2e-shard.mjs` — `scripts/__tests__/e2e-shard.test.mjs` fails if
// the two ever drift.
export const SERIAL_SPECS = [
"agent-chat-projects-handoff.spec.ts",
"agent-chat-projects.spec.ts",
"agent-chat-sessions-navigation.spec.ts",
"agent-chat-sessions.spec.ts",
"agent-configuration-revisions.spec.ts",
"agent-configuration.spec.ts",
"ai-personal-connection-recovery.spec.ts",
"cases-read-only.spec.ts",
"classic-workspace.spec.ts",
"composer-stop.spec.ts",
"connection-intents.spec.ts",
"document-image-gallery.spec.ts",
"onboarding-resume.spec.ts",
"onboarding.spec.ts",
"smoke-lab-p1-p4.spec.ts",
"smoke-lab-p5-p7.spec.ts",
];
function extractCliSpecBasenames(argv: string[]): string[] {
const specs: string[] = [];
for (let index = 2; index < argv.length; index += 1) {
const arg = argv[index]!;
if (arg === "--config" || arg === "-c" || arg === "--project" || arg === "--grep" || arg === "-g") {
index += 1;
continue;
}
if (arg.startsWith("-")) continue;
if (arg.endsWith(".spec.ts")) {
specs.push(path.basename(arg));
}
}
return specs;
}
function resolveExecutionMode(): { workers: number; fullyParallel: boolean } {
// Worker processes reload this config without the parent CLI spec filters.
// Cache the parent process's decision in env so workers agree with the runner.
if (
process.env.PAPERCLIP_E2E_RESOLVED_WORKERS &&
process.env.PAPERCLIP_E2E_RESOLVED_FULLY_PARALLEL
) {
return {
workers: Number(process.env.PAPERCLIP_E2E_RESOLVED_WORKERS),
fullyParallel: process.env.PAPERCLIP_E2E_RESOLVED_FULLY_PARALLEL === "true",
};
}
const cliSpecs = extractCliSpecBasenames(process.argv);
const serialSet = new Set(SERIAL_SPECS);
const includesSerial = cliSpecs.some((spec) => serialSet.has(spec));
const strictlyParallelSafe = cliSpecs.length > 0 && !includesSerial;
const explicitWorkers = Number.parseInt(process.env.PAPERCLIP_E2E_WORKERS ?? "", 10);
let workers: number;
let fullyParallel: boolean;
if (Number.isInteger(explicitWorkers) && explicitWorkers >= 1) {
workers = explicitWorkers;
fullyParallel = workers > 1 && !includesSerial;
} else if (strictlyParallelSafe) {
// Scale parallel Chromium workers dynamically with runner CPU cores while
// reserving headroom for the shared Node server + embedded Postgres:
// 4-vCPU runner -> 2 workers; 8-vCPU runner (c8i.2xlarge) -> 4 workers.
const cpus = os.availableParallelism();
workers = Math.max(1, Math.min(4, Math.floor(cpus / 2)));
fullyParallel = workers > 1;
} else {
workers = 1;
fullyParallel = false;
}
process.env.PAPERCLIP_E2E_RESOLVED_WORKERS = String(workers);
process.env.PAPERCLIP_E2E_RESOLVED_FULLY_PARALLEL = String(fullyParallel);
return { workers, fullyParallel };
}
const EXECUTION_MODE = resolveExecutionMode();
const SERVER_START_COMMAND =
"node cli/node_modules/tsx/dist/cli.mjs tests/e2e/start-e2e-server.ts";
const WEB_SERVER_COMMAND = SERVER_START_COMMAND;
export default defineConfig({
testDir: ".",
testMatch: "**/*.spec.ts",
// These suites target dedicated multi-user configurations/ports and are
// intentionally not part of the default local_trusted e2e run.
testIgnore: ["in-feed-native/**", "multi-user.spec.ts", "multi-user-authenticated.spec.ts"],
timeout: 60_000,
expect: { timeout: 10_000 },
retries: 0,
// Parallel-safe shards run concurrently across multiple workers; shards or
// runs that include any spec in SERIAL_SPECS (or unfiltered full runs) fall
// back to 1 worker so server-level experimental flags cannot race mid-flight.
workers: EXECUTION_MODE.workers,
fullyParallel: EXECUTION_MODE.fullyParallel,
use: {
baseURL: BASE_URL,
headless: true,
screenshot: "only-on-failure",
trace: "on-first-retry",
},
projects: [
{
name: "chromium",
use: {
browserName: "chromium",
...(PLAYWRIGHT_CHANNEL ? { channel: PLAYWRIGHT_CHANNEL } : {}),
},
},
],
// The webServer directive bootstraps a throwaway instance and then starts it.
// `onboard --yes --run` works in a non-interactive temp PAPERCLIP_HOME.
webServer: {
cwd: REPO_ROOT,
// Exercise the shipped UI. Source-checkout onboarding otherwise enables
// Vite middleware: every reload traverses thousands of modules, including
// service-worker-intercepted requests, before React can even start.
// Build the server's first-choice static directory unless CI/caller already
// prebuilt server/ui-dist and opted in via PAPERCLIP_E2E_SKIP_UI_BUILD=1.
command: WEB_SERVER_COMMAND,
url: `${BASE_URL}/api/health`,
// Always boot a dedicated throwaway instance for e2e so browser tests
// never attach to the developer's active Paperclip home/server.
reuseExistingServer: false,
timeout: 120_000,
stdout: "pipe",
stderr: "pipe",
env: {
...process.env,
NODE_ENV: "test",
PAPERCLIP_E2E_BUILD_UI: SKIP_UI_BUILD ? "0" : "1",
PAPERCLIP_UI_DEV_MIDDLEWARE: "false",
HEARTBEAT_SCHEDULER_INTERVAL_MS: process.env.HEARTBEAT_SCHEDULER_INTERVAL_MS ?? "10000",
NODE_OPTIONS: `${process.env.NODE_OPTIONS ?? ""} --import=${path.resolve(import.meta.dirname, "fixtures/agent-chat-github.mjs")} --import=${path.resolve(import.meta.dirname, "fixtures/ai-connection-provider.mjs")}`,
PORT: String(PORT),
PAPERCLIP_OPEN_ON_LISTEN: "false",
PAPERCLIP_API_URL: BASE_URL,
PAPERCLIP_HOME,
PAPERCLIP_INSTANCE_ID,
PAPERCLIP_CONFIG,
PAPERCLIP_AGENT_JWT_SECRET,
PAPERCLIP_DECISION_SIGNING_SECRET,
PAPERCLIP_TOOL_ACTION_SIGNING_SECRET,
PAPERCLIP_BIND: "loopback",
PAPERCLIP_DEPLOYMENT_MODE: "local_trusted",
PAPERCLIP_DEPLOYMENT_EXPOSURE: "private",
},
},
outputDir: "./test-results",
reporter: [
["list"], ["html", { open: "never", outputFolder: "./playwright-report" }],
...(process.env.GITHUB_ACTIONS === "true"
? [[path.resolve(import.meta.dirname, "../../scripts/ci/oversized-test-files-playwright.mjs")] as [string]]
: []),
...(process.env.PAPERCLIP_CI_PROFILE === "true"
? [[path.resolve(import.meta.dirname, "../../scripts/ci-profile/playwright-reporter.mjs")] as [string]]
: []),
],
});