Skip to content

test(e2e): run the suite offline, against a throwaway Postgres and local emulators of every outside service - #328

Merged
viclafouch merged 7 commits into
mainfrom
320-keep-local-e2e-runs-off-the-ci-test-database
Nov 30, 2026
Merged

viclafouch merged 7 commits into
mainfrom
320-keep-local-e2e-runs-off-the-ci-test-database

Conversation

@viclafouch

@viclafouch viclafouch commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

Summary

Each e2e run now owns its outside world, started by Playwright before the app and gone with the run:

flowchart LR
    PW[Playwright] -->|1. starts| OUT["Outside services<br/>(e2e/emulators)"]
    PW -->|2. builds, starts| APP[App server]
    OUT --- PG[(Postgres 17<br/>embedded, empty)]
    OUT --- EM["MSW emulators, in memory<br/>Bunny · Stripe · Algolia · Resend · Anthropic"]
    APP --> PG
    APP --> EM
    Browser --> APP
    Browser --> EM
    Guard{{"network guard: fails any non-loopback request"}}
    Guard -.-> APP
    Guard -.-> PW
    Guard -.-> Browser
Loading
 e2e/
+├── emulators/
+│   ├── index.ts          # Postgres, then one emulator per outside service
+│   ├── database.ts       # embedded-postgres, migrated, throwaway
+│   ├── bunny/            # pull zones (HS256 tokens from Bunny's docs), Stream API, Storage, 3 s video fixture
+│   ├── stripe/           # typed with the Stripe SDK, refuses any other Stripe-Version
+│   ├── algolia/          # search, filters, replicas, recommend, insights, typed with the SDK
+│   ├── resend.ts
+│   └── anthropic.ts
+├── network-guard.ts      # MSW setupServer in every Node process of a run
-├── fake-anthropic.ts
 .env.e2e                  # committed: placeholder keys only
  • Drift guard: emulator responses are typed with each installed SDK (satisfies Stripe.Subscription, Algolia's SearchResponse…), and Bunny's with the app's own response schemas, moved to src/constants/bunny-api.ts. An unknown call is refused by name.
  • The app reads Bunny pull zones as full origins (VITE_BUNNY_ORIGIN, VITE_BUNNY_IMAGES_ORIGIN) and takes optional origins for each outside API, defaulting to the real hosts.
  • The e2e workflow needs no secret and groups runs per branch: two branches run at once, a push on main never cancels another.
  • The Algolia index settings get one home, src/constants/algolia.ts, read by scripts/setup-algolia-indices.ts and the emulator.

Closes #320
Closes #292

Evidence

  • Before: CI e2e on main (874fd37): 305 passed in 10.2 min, Studio 40 s, seed 35 s, checkout 33 s, one shared Neon branch, one run at a time.
    After: local, offline, build included: pnpm run test:e2e → 304 passed in 2.7 min, Studio 3.8 s, checkout ~3 s. [network guard] and [emulator] errors in the run and server logs: 0. (304: the remote "Bunny Storage holds every file" setup check is gone, the files ship with the fixture.)
  • pnpm run check, pnpm run bundle-size: green.

Merge Danger

Door: two-way

Revertable in one commit. The Neon test branch and the Bunny, Algolia and Stripe e2e resources stay untouched until deleted by hand after the merge.

Blast Radius: deployment

VITE_BUNNY_HOSTNAME and VITE_BUNNY_IMAGES_HOSTNAME become VITE_BUNNY_ORIGIN and VITE_BUNNY_IMAGES_ORIGIN, with https://. Vercel needs them before the merge, or the build fails env validation. The preview of this PR fails the same way until then.

…cal emulators of every outside service

Each e2e run, local or CI, starts its own Postgres 17 (embedded-postgres) and
MSW emulators of Bunny, Stripe, Algolia, Resend and Anthropic, holding their
state in memory for the run. A network guard fails any request that leaves
the machine, in the app server, the Playwright processes and the browser.
The library video is a 3 second fixture. .env.e2e is committed with
placeholder keys, so the e2e workflow needs no secret, and runs of different
branches no longer wait for each other.

The app reads its Bunny pull zones as full origins and takes optional
origins for each outside API, defaulting to the real hosts.

Closes #320
Closes #292
@vercel

vercel Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
petit-meme Ready Ready Preview Nov 29, 2026 11:30pm UTC

Request Review

@viclafouch viclafouch linked an issue Nov 29, 2026 that may be closed by this pull request
@viclafouch viclafouch added test Tests only enhancement New feature or request labels Nov 29, 2026
@viclafouch viclafouch self-assigned this Nov 29, 2026
@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

📦 Startup JS · ✅ No heavier

Brotli · 33 routes · against main at 874fd37 · workflow run

Route Route JS Budget Startup JS vs main
✅ /admin/categories 116.2 kB 122 kB · 5.8 kB left 407.4 kB ⚪ −0.1 kB
✅ /admin/downloader 83.6 kB 89 kB · 5.4 kB left 374.8 kB ⚪ −0.1 kB

What moved

Chunk vs main Loaded by
algolia-insights ⚪ +0.1 kB /reels, /, /dmca and 17 more
app-hooks ⚪ −0.1 kB every route

Caution

Far from the goal. 🟩 is the goal, each 🟥 one more goal’s worth.

Now Goal Distance
Startup JS of /memes/$memeId/studio, the heaviest route 516.5 kB 150 kB 🟩🟥🟥🟥 3.4×
Shell (every route) 291.2 kB 150 kB 🟩🟥 1.9×
Route JS of /memes/$memeId/studio 225.3 kB 50 kB 🟩🟥🟥🟥🟥 4.5×
📋 Every route
Route Route JS Budget Startup JS vs main
✅ Shell (every route) 291.2 kB 296 kB · 4.8 kB left — —
✅ /memes/$memeId/studio 225.3 kB 228 kB · 2.7 kB left 516.5 kB ·
✅ /memes/$memeId 205.9 kB 209 kB · 3.1 kB left 497.1 kB ·
✅ /admin/library/$memeId 197.1 kB 203 kB · 5.9 kB left 488.3 kB ·
✅ /memes/ai-search 175.6 kB 178 kB · 2.4 kB left 466.8 kB ·
✅ /settings 174.5 kB 177 kB · 2.5 kB left 465.7 kB ·
✅ /submit 165.1 kB 168 kB · 2.9 kB left 456.3 kB ·
✅ /password/create-new 163.2 kB 166 kB · 2.8 kB left 454.4 kB ·
✅ /password/reset 161.5 kB 164 kB · 2.5 kB left 452.7 kB ·
✅ /memes/bookmarks 156.7 kB 160 kB · 3.3 kB left 447.9 kB ·
✅ /memes/category/$slug 155.9 kB 159 kB · 3.1 kB left 447.1 kB ·
✅ / 155.2 kB 158 kB · 2.8 kB left 446.4 kB ·
✅ /verify-email 150.2 kB 153 kB · 2.8 kB left 441.4 kB ·
✅ /app 138.7 kB 140 kB · 1.3 kB left 429.9 kB ·
✅ /pricing 137.3 kB 140 kB · 2.7 kB left 428.5 kB ·
✅ /mentions-legales 129.5 kB 133 kB · 3.5 kB left 420.7 kB ·
✅ /terms-of-use 129.5 kB 133 kB · 3.5 kB left 420.7 kB ·
✅ /privacy 129.5 kB 133 kB · 3.5 kB left 420.7 kB ·
✅ /dmca 129.5 kB 133 kB · 3.5 kB left 420.7 kB ·
✅ /faq 124.4 kB 127 kB · 2.6 kB left 415.6 kB ·
✅ /checkout/success 124.0 kB 127 kB · 3.0 kB left 415.2 kB ·
✅ /admin/library 117.9 kB 124 kB · 6.1 kB left 409.1 kB ·
✅ /admin/categories 116.2 kB 122 kB · 5.8 kB left 407.4 kB ⚪ −0.1 kB
✅ /admin/users/$userId 106.6 kB 112 kB · 5.4 kB left 397.8 kB ·
✅ /admin/users 96.0 kB 102 kB · 6.0 kB left 387.2 kB ·
✅ /reels 90.7 kB 96 kB · 5.3 kB left 381.9 kB ·
✅ /admin/proposals 85.7 kB 91 kB · 5.3 kB left 376.9 kB ·
✅ /admin/activity/$ip 84.0 kB 90 kB · 6.0 kB left 375.2 kB ·
✅ /admin/downloader 83.6 kB 89 kB · 5.4 kB left 374.8 kB ⚪ −0.1 kB
✅ /admin/activity 83.3 kB 89 kB · 5.7 kB left 374.5 kB ·
✅ /admin 81.4 kB 87 kB · 5.6 kB left 372.6 kB ·
✅ /admin/ai-search 74.5 kB 80 kB · 5.5 kB left 365.7 kB ·
✅ /embed/$memeId 69.8 kB 75 kB · 5.2 kB left 361.0 kB ·
✅ /admin/services 59.6 kB 65 kB · 5.4 kB left 350.8 kB ·
🤖 Agent brief

What this measures. The Brotli size of each JS file the server-rendered page of a route modulepreloads, read from the TanStack Start manifest of pnpm run build:e2e. The shell is what the root route preloads on every page. Route JS is what a route adds on top, each file counted once. Startup JS is both, and every comparison with main runs on it: Rolldown moves code between the shell and the routes from one build to the next, and only the startup JS of a page tells what its visitor downloads. Sizes in the data are bytes.

Rules. Budgets live in bundle-budget.json as a one-way ratchet: the size when last updated, plus 5 kB. pnpm run bundle-size --update only lowers them, and --allow-growth raises them, flagged in red against main. Never raise one to turn the check green. Chunk names drop the Rolldown hash: meme-card stands for meme-card-<hash>.js. Two chunks with the same name add up, and a chunk loaded by every route reads every route. A chunk that grows while no route loading it gets heavier shows ⚪, with isRegression: false: Rolldown renamed or merged it, and only red chunks explain a heavier route. A chunk Rolldown renamed reads old → new, with renamedFrom. First-view CSS is gated apart, by e2e/first-view.spec.ts against firstViewCss.

Reproduce

pnpm run build:e2e
gh run download 46307394879 --name bundle-size --dir /tmp/main-bundle-size
git show origin/main:bundle-budget.json > /tmp/main-budget.json
pnpm run bundle-size --base /tmp/main-bundle-size/report.json --base-budget /tmp/main-budget.json
pnpm run build:analyze

Data

{
  "verdict": "pass",
  "base": {
    "commit": "874fd37",
    "runId": "46307394879"
  },
  "violations": [],
  "raisedBudgets": [],
  "routeChanges": [
    {
      "name": "/admin/downloader",
      "beforeBytes": 374926,
      "afterBytes": 374813
    },
    {
      "name": "/admin/categories",
      "beforeBytes": 407560,
      "afterBytes": 407448
    }
  ],
  "chunkChanges": [
    {
      "chunk": "algolia-insights",
      "deltaBytes": 125,
      "loadedBy": [
        "/reels",
        "/",
        "/dmca",
        "/mentions-legales",
        "/privacy",
        "/terms-of-use",
        "/verify-email",
        "/memes/$memeId",
        "/app",
        "/checkout/success",
        "/memes/ai-search",
        "/password/create-new",
        "/password/reset",
        "/memes/$memeId/studio",
        "/memes/bookmarks",
        "/faq",
        "/pricing",
        "/settings",
        "/submit",
        "/memes/category/$slug"
      ],
      "isRegression": false
    },
    {
      "chunk": "app-hooks",
      "deltaBytes": -107,
      "loadedBy": [
        "every route"
      ],
      "isRegression": false
    }
  ]
}

…leave the machine

WebKit reads a video through blob: URLs, whose empty hostname the guard took
for a request to the outside, and aborted.
…ck before hydration sent it away

A submit before hydration posts the form natively, which drops the token from
the address. The faster suite meets that window more often.
…f the page

Once the app's service worker controls a WebKit page, the page's requests go
through it and skip Playwright's routing: they lost the per-test x-real-ip, so
every WebKit export counted against one shared "unknown" IP and hit the
download rate limit, and the browser network guard could not see them.
No scenario relies on the service worker.
…t's routing

The per-test x-real-ip only rides on routed calls. When a call skips the
routing, as WebKit's did through the service worker, every scenario shares one
IP and the rate limits fail tests far from the cause. The fixture now names
such calls at the end of the scenario. With service workers allowed, 11 of the
12 WebKit Meme files scenarios go red on it.
The e2e video now has a sound, and a phone browser may start it muted, as
Safari on an iPhone does. The scenario checks that the tap leaves the sound
alone, whichever way the browser started it.
In CI, WebKit plays video through GStreamer in a container with no audio
output: with a sound track, playback sometimes stalled before its first frame,
so the player never counted as started and kept its controls hidden. Ten
repeats of the WebKit player scenarios failed 3 times out of 161 with the
sound and never without it. The sound export is built from silence, the way
production builds it for a video without sound.
@viclafouch
viclafouch merged commit b074aaa into main Nov 30, 2026
8 checks passed
@viclafouch
viclafouch deleted the 320-keep-local-e2e-runs-off-the-ci-test-database branch November 30, 2026 08:18

This branch was successfully deployed

1 active deployment
Preview — 04134fdd Deployed Nov 29, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request test Tests only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keep local e2e runs off the CI test database Give e2e its own Stripe sandbox

1 participant