feat(runner): more users in one test, with peers
Draft
TA
8d ago+5693+5693+0123456789012345678901234567890123456789-369-369-012345678901234567890123456789
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 inpeers/<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.
peerscan be set on adescribe, so a collaborative suite doesn't repeat it.- A peer on a browser provider, on
web({ connect })or on a device provider is refused withUNSUPPORTED_CAPABILITYbefore anything is leased.
Open questions
- Name and shape.
peersadds users next to the test's own user. The other shape is a set of named users that replaces the top-levelapp,screenandagent. Withpeers, adding a second user to a test doesn't change the lines that are already there. - 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.
- Should engines opt in? Today any engine that launches its own browser or device works.
- Peers take slots on top of
workers. Should a run-wide cap count them? - 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.tson 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
peerskeeps working. - Docs updated in the same PR: the
docs/**/*.mdxpage for the behavior, andskills/e2e/if the skill describes it. - Contract change: emitted
.d.tsreviewed,tests/types/sdk-types.tsupdated; wire change edits the schema and both fixtures. - Engine contract change (
e2e/engine): changesets fore2e,@e2e-dev/web, and@e2e-dev/mobile.