app-e2e-tests
Use when writing, changing, reviewing, or debugging Playwright e2e tests in packages/app/e2e (regression keepers and user stories). Covers the mocked opencode server harness and the Bun static server, per-test isolation, page-load and route cost, the suite-wide service-worker block, races with first mount, hover, measurement, clock, dialogs and shortcuts, projects, shards and worker scheduling, rehearsing Windows timing locally, and diagnosing a CI flake from its artifacts. Not for component tests (stories mounted on packages/stories) or the strobe benchmarks in packages/app/perf.
SKILL.md 原文预览
App e2e tests
Read packages/app/e2e/AGENTS.md and the Tests section of packages/app/AGENTS.md first. They define what to test, which locators to use, and how to assert. packages/app/README.md (E2E Testing) documents run modes and env vars. This skill covers what makes these tests slow or flaky in CI, which runs the suite as two shards per OS on 4-vCPU runners (.github/workflows/check-test.yml:217-240). Most races below were found on Windows.
All paths below are relative to packages/app unless they start with packages/, services/ or .github/.
What a test runs against
- No opencode backend. Each shard leg runs
bun --cwd packages/app test:e2e:built --shard=<n>/2(check-test.yml:287-292). It builds once and starts one Bun static server,e2e/utils/serve.ts, on127.0.0.1:${PLAYWRIGHT_PORT ?? 3000}. All 5 workers share it (playwright.config.ts:23-27). serve.tskeeps vite preview's SPA fallback rules. Do not move built e2e back to vite preview. On case-insensitive file systems it synchronously reads the wholedist/_assetsdirectory (about 3,100 files) for every asset request, so every worker's page loads wait in line.- The API is an in-memory mock per page, running in the test worker.
mockOpenCodeServer(e2e/utils/mock-server.ts:202): - answers
page.route("/api/")with an Effect HttpApi handler; - fakes
/api/eventSSE with an init-scriptfetchoverride; - serves PTY sockets through
routeWebSocket. - Unmocked routes fail the test with a 501 and
Unmocked API request(mock-server.ts:403-411). Add the route tomock-server.tsonce instead of routing around it in a spec. - Build pages with the helpers:
mockWorkspace,openSession,openDraft,openWorktreeDraft,mockRemoteServer,openSettings(e2e/utils/workspace.ts);setupTimeline(e2e/utils/timeline.ts:209) for streamed timelines,mockServers(mock-server.ts:495) for several origins;seed(e2e/utils/app.ts:61) for storage,holdRoute(app.ts:207) to hold requests until you release them.- Deliver events with the mock's
push, which buffers until the app connects, or withinstallSseTransport(e2e/utils/sse-transport.ts:60), whosesendresolves on delivery. Afterpage.reload(), awaittransport.waitForConnection()before sending (e2e/regression/timeline-stream.spec.ts:1700-1702). - Windows-only failures are races, not Windows code paths. Mock directories are
C:/OpenCode/<name>on every OS (workspace.ts:33), and nothing touches the disk. Lazy chunks, stylesheets and responses finish out of order more often on the Windows runners.
Isolation
- No shared state between tests. Each test gets a fresh context, mock handler and init scripts. Outside
e2e/service-worker, which runs under its own config and shares builds through a worker fixture (e2e/service-worker/cache.spec.ts:21,:74), app e2e has nobeforeAll, serial mode,test.extendor worker fixtures. Keep it that way so-gandPLAYWRIGHT_FULLY_PARALLEL=1keep working. - Handlers mutate the objects you pass. Creating a session pushes into
sessions(mock-server.ts:839). Renaming writessession.title(:1340), and VCS init writesproject.vcs(:1019). - Call
session()/project()inside the test. mockWorkspaceandopenSessioncopy what you pass (workspace.ts:36-48).mockOpenCodeServerandmockServersuse your objects as they are. Module-level fixtures likemulti-server.spec.ts:10-19are therefore shared by every test in the file.- Timeline builders keep state per test attempt (
timeline.ts:165-198). Call stateful builders such asassistantMessageorpartUpdatedinside the test. Only pure ones such astoolPartbelong at module scope. - Seed before the first
goto.seedwrites storage once per tab behind asessionStoragemarker, so reloads keep what the app stored (app.ts:59-90). It cannot reset state mid-test.
Keep it fast
- Navigate once. Every
gotoorreloadis a cold load of the production bundle: about 150 requests per session open, about 125 of them static files. Each test has a new context, and anypage.routedisables the HTTP cache. Reach later states through the UI or through pushed events. Reload only when surviving a reload is the contract. - Service workers are already blocked suite-wide (
serviceWorkers: "block",playwright.config.ts:66-67). Do not add a per-file block; the 11 ine2e/regressionare redundant. - Production registers
/sw.json load (src/entry.tsx:54-55) and precaches about 1,600 files (globPatterns: ["**/*"],vite.pwa.ts:34).e2e/service-worker/covers it under its own config. The main config ignores that directory (playwright.config.ts:33-36), and CI runs it after shard 2 (check-test.yml:294-298). - Opt back in with
test.use({ serviceWorkers: "allow" })only when the worker is the contract. It never controls the first load (clientsClaim: false,vite.pwa.ts:26-28). After a reload it can control the page, and page routes may then miss its requests. - Every built-mode page load logs Playwright's block warning. Console collectors must ignore it, as
captureConsoleWarningsdoes (e2e/utils/command-palette.ts:15-26). - **Match new routes with a RegExp or a query-aware glob, not a function.
评论
