feat(runner): more users in one test, with peers

Draft
TA
8d ago
+5693-369

What and why

I'd like to agree on the API before anyone reviews the code line by line.

A test can declare more users. Each peer gets an app of its own, with its own saved session, target and agent. The test's own user keeps app, screen and agent as they are today.

test('a message the admin posts reaches a signed-out user', { session: 'admin', peers: { guest: {} } }, async ({ app, screen, peers }) => {
  await app.open('/messages');
  await screen.getByLabel('Message').fill('Standup moved to 10:30');
  await screen.getByRole('button', 'Post').tap();

  await peers.guest.app.open('/messages');
  await expect(peers.guest.screen.getByRole('list', 'Messages')).toContainText('admin: Standup moved to 10:30');
});

A peer can run on another target, so one test can drive a browser and an iPhone:

test('web user with an iPhone peer', { peers: { phone: { target: 'ios-simulator' } } }, async ({ app, peers }) => {
  await app.open('/');
  await peers.phone.screen.getByRole('textbox', 'Name field').fill('Grace Hopper');
});
  • Each peer runs on an engine instance of its own. The engine contract only gains EnginePrepareInfo.peerSlots. It works on mobile too, where a peer takes a simulator or emulator of its own. The cost is a browser process or a device per peer.
  • A peer's steps, files, app logs, video and replay recordings carry its name in the terminal, Markdown, the HTML report and --ai-trace. Its files go in peers/<name>/.
  • Each peer's agent sees only its own app and its own steps.
  • The whole test shares one secret ledger, because one user's secret can show up on another user's screen. SECURITY.md changes with it.
  • A peer's recordings are keyed by its name. Tests without peers keep their keys, so existing recordings stay valid.
  • peers can be set on a describe, so a collaborative suite doesn't repeat it.
  • A peer on a browser provider, on web({ connect }) or on a device provider is refused with UNSUPPORTED_CAPABILITY before anything is leased.

Open questions

  1. Name and shape. peers adds users next to the test's own user. The other shape is a set of named users that replaces the top-level app, screen and agent. With peers, adding a second user to a test doesn't change the lines that are already there.
  2. An engine instance per peer, or a browser context per peer inside one engine. A context is lighter on web, but the engine would have to know which user each operation is for, and it doesn't cover phones. The two could live together later.
  3. Should engines opt in? Today any engine that launches its own browser or device works.
  4. Peers take slots on top of workers. Should a run-wide cap count them?
  5. Size. It's 125 files, much of it tests and docs. Once the API is settled I can split it into runner, reporters and engines.

Issue

Related to #1716

Verified

Ran it locally: yes

  • testbed, a Chromium user with a Firefox peer: passed. A failing peer step prints ❯ at guest · http://127.0.0.1:4271/messages, and the HTML report shows a separate "at failure · guest" panel with the guest's screen.
  • mobile-benchmark, tests/two-users.e2e.ts on two iOS simulators: passed, with one video per user.
  • A web user with an iPhone peer, and an iPhone user with a web peer: both passed.
  • 125 of the 126 new tests fail on main and pass here. The other one is a guard that passes on both.
  • Android: not run yet. A peer there uses the same device pool as on iOS.

Checklist

  • Changeset added (pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.
  • Breaking change: none. A suite's own fixture named peers keeps working.
  • Docs updated in the same PR: the docs/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it.
  • Contract change: emitted .d.ts reviewed, tests/types/sdk-types.ts updated; wire change edits the schema and both fixtures.
  • Engine contract change (e2e/engine): changesets for e2e, @e2e-dev/web, and @e2e-dev/mobile.