Repository navigation
Conversation
A test or describe names its peers, each with an optional target, session, agent, and agentContext; innermost wins as a whole. Setup tests and serial groups cannot declare them. Collection checks the names and fields, an unknown target or agent, a peer target the run does not select, a peer session no setup saves, and a peer session on a target that cannot restore one. Selection runs the setup that saves a peer's session on the peer's target, under --shard, filters, and --last-failed too. The scheduler holds a test until that setup finishes on any target and skips it when the setup fails or its target cannot start. e2e list shows each pair's peers, and test filters get peerSetupFiles, which the decision filter reads like setupFile. A run of a test with peers is refused before anything starts until the runtime that opens their apps lands.
A peer gets an engine instance of its own: a child worker loads the config again in graph mode, boots the peer's engine once, reuses it across attempts, and disposes it with the worker. The peer's app opens right after the test's, before the deadline, with its saved session and video, and closes on every path; its artifacts go to peers/<name>/, and a failure keeps evidence from every user. peers.<name> gives app, screen, agent, platform, and the engine's own fixtures, typed from the test's peers option; an undeclared name fails at the touch. Each peer runs as its own agent with its own context and executor memory, and every user of an attempt shares one secret ledger, so a secret one user typed never reaches another user's screen read. A run given a config value, and an engine shared through a package, are refused with an error that says how to fix them. Peers on another target stay refused until they can be opened. The testbed gets a message board and a two-user test.
Every step, file, and app log line a peer's app produced now carries the peer's name, and attempt.peers keeps each peer's environment and its screen at the failure. A run with no peers writes exactly what it did before. - Each user's app log, navigations, and screen changes stay with that user's steps, and each user's agent quotes only its own earlier steps. - The replay cache keys a peer's steps on its name too, confirms a recording only by a check of the same user, and the strict stale check never blames a peer's step on another user's recording. The test's own user's keys are unchanged. - toHaveScreenshot keeps a peer's baselines in peers/<name>/. - The terminal, --step prompts, Markdown, the trace page, --debug, --ai-trace, and the HTML report name the peer; the HTML report plays each user's video on its own timeline. - Peer names "." and "..", and two that differ only in case, are refused, since each peer's files go in a folder named after it.
A test's peer can now run on any other selected target that is not a phone: on that target's own engine and options, against its app, with a login saved on that target. A peer on a phone target is refused before anything starts, since it would need a device of its own that the run does not reserve yet. - A second user on an engine object another user in the worker already runs on is refused at launch, on the same target or another. An engine made inside a package is that one object in every load of the config. - attempt.peers.<name>.target says where each peer ran, and the trace page names a peer's target when it is not the test's own.
A peer runs inside the worker that runs its test, so on its target it needs a slot no worker of that target holds: on a phone target, a device of its own. The runner now asks each target's prepare for its own workers' slots plus one per peer the run's tests bring to it, and tells each worker which slots its tests' peers take. - EnginePrepareInfo.peerSlots says how many of slots are for peers; a peer's engine gets one of them as its workerSlot, with what that target's prepare handed its own workers. - Where an engine serves fewer slots than needed, worker counts are lowered, the short target's own first, with a notice. A target that cannot serve one worker and its peers fails the run before any test. - A peer the run reserved no slot for is refused; it never falls back to another user's device. The refusal of peers on phone targets is gone. - The mobile benchmark gets a two-iPhone scenario, locator steps only, that runs where the run names two simulators, as CI does.
…s why - e2e mcp's open_session refuses a test with peers: a session drives one app. - A peer on a target served by an engine server is a collection error; the harness now tells an engine server's handle from an engine in the process (isServedEngine). - @e2e-dev/web refuses, in prepare and before it leases anything, a peer on a target with a browser provider or a browser attached over CDP. - @e2e-dev/mobile refuses, in prepare and before it leases anything, a peer on a target with a device provider. A local pool serves peers.
- docs/authentication.mdx: a "Two users in one test" section. - docs/reference/test.mdx: the peers option, the peers fixture, and their types and errors. - docs/reference/engine.mdx: EnginePrepareInfo.peerSlots and what workerSlot means for a peer. - docs/reference/reporters.mdx: the user on step progress. - docs/mobile.mdx: two users on two devices, and tool calls per user. - skills/e2e: the peers option, synced into the plugin. - A changeset for e2e, @e2e-dev/web, @e2e-dev/mobile, @e2e-dev/html-reporter, and @e2e-dev/decision.
… run's time limit
…er its prepare serves
…h past config.workers
… calls in the AI trace
…get and agent its test runs on
…public step types
- Skip a test whose peer's target app exited, and report the exit, even when that target runs no test of its own (main's app-exit handling). - Redact a peer's name, agent, and target in the AI trace (main's trace redaction). - Score a test whose peer's setup file changed as touched in the decision filter (main's relevance scores). - Show the screen of the user whose step failed in the terminal, JUnit, and the HTML report. - Refuse a serial group inside a group with peers. - e2e mcp refuses a test with a peer on another target with SESSION_TEST_UNSUPPORTED, as documented. - Stop reserving the fixture name peers: a suite's own peers fixture keeps working, and only a test that declares peers through it, or on a target whose engine contributes one, is refused. - Count each user's app log against its own limit, keep the test's own step inside a peer's step as the test's own, give the vision hint the agent's own steps only, and name the right test when a peer's engine fails to load. - Leave empty color codes off the test user's step lines. - Docs: the slot contract as the code keeps it, every peers case in the error reference, the shared secrets in SECURITY.md, peerSetupFiles, and the mobile benchmark's two-user test in a CI step of its own.
|
This overlaps #1716 (@MarcosCamara01, actors in one test), which already has maintainer review points: actors via Automated triage by Claude Code on behalf of the maintainers. |
|
Linked #1716 and posted the comparison there. |
kdy1
left a comment
There was a problem hiding this comment.
Thanks for asking for API agreement before the line-by-line review. I'm requesting changes to the API shape. The direction is right, and I'd keep most of the decisions: extra users beside the test's own app, screen, and agent, one engine instance per user, one secret ledger per attempt, and every step, file, and log line marked with its user. What I'd change is how a test names its extra users, how their fixtures get typed, how a peer's engine instance gets built, and how peers count against capacity.
Below are the problems I found at 720f56b1, then the API I'd like instead, with a type sketch I compiled against current main.
Problems with the current API
1. Peer fixtures are mostly unknown
PeerFixtures is Omit<TestFixtures, 'peers'> plus [fixture: string]: unknown. I built the PR and typechecked a probe file with the repo's own compiler settings (strict, exactOptionalPropertyTypes, noUncheckedIndexedAccess):
| Probe | Result at 720f56b1 |
|---|---|
peers.ava.browser in a test from @e2e-dev/web, where the test's own browser is typed |
unknown, so it needs a cast |
peers.ava.aap.open('/') (a typo) |
'peers.ava.aap' is of type 'unknown', not "does not exist" |
Peers declared on a describe, then peers.ava.app.open('/') in a test |
TS18048: 'peers.ava' is possibly 'undefined' |
{ ava: { session: 'ava', sesion: 'x' } } |
Rejected, which is good |
A peer on the test's own target is the common case. That peer runs the same engine as the test, so it should get the same engine fixture types without a cast. The docs page already tells users to write peers.ava.device as Device.
2. peers is a new core fixture name that is only partly reserved
To keep a suite's own peers fixture working, the PR special-cases the name in FixtureDefinitions and Extended, and adds a runtime COLLECTION_ERROR for a test that declares peers through a chain that defines its own. Every later change to fixture typing has to carry that exception. If the test author names each extra user, there is no fixed name to reserve.
3. A peer's engine comes from loading the config again
loadPeerExecutor builds each peer's engine by loading the config file again, along with the project files it imports. So:
- The config's top-level code runs again for each peer target in each worker.
- An engine created inside a package is one shared object across loads, so it fails with
INVALID_CONFIG(message). - A run with no config file (a config value, or tests registered in memory) fails with
UNSUPPORTED_CAPABILITY. - A peer on a target served by an engine server fails with
COLLECTION_ERROR.
The engine is the thing that knows how to make a second independent instance of itself. The harness should ask it, not re-import user code to get one.
4. Engines get peers whether they support them or not
EngineInitInfo.workerSlot can now go past config.workers. A peer's instance also lives in the same worker process as the test's own, so any state an engine keeps at module level is shared between the two. @e2e-dev/web and @e2e-dev/mobile handle this, but a third-party engine that has never heard of peers gets extra slots and a second instance with no way to say no. Today this is opt-out. I think it should be opt-in where it matters (see the proposal).
5. Peer slots sit on top of workers, for the whole run
Per docs/mobile.mdx, the run sets peer devices aside for every worker on the target, for the whole run. One test with a peer leaves the target fewer workers for every other test, and the mobile benchmark's CI works around it by running --tag peers separately. With a browser or device provider this would also multiply leases past the workers value the user chose. When the devices don't fit, the run stops with ENGINE_FAILURE before any test runs, so one multi-user test can block the whole suite.
6. A smaller one: an undeclared peer is INVALID_CONFIG
Reading peers.bob for a peer the test did not declare throws INVALID_CONFIG at runtime (fixtures.ts). That is a mistake in the test body, not in the config. With the proposal below it becomes a type error.
Proposed API: actors
Each extra user is a top-level fixture with a name the test author picks. The test's own app, screen, and agent stay as they are, so a single-user test and its report do not change.
Usage
// Two browsers on one web target. `guest` has the same engine fixtures as the test.
import { test } from '@e2e-dev/web';
import { expect } from 'e2e';
test("a guest sees the admin's post", { session: 'admin', actors: { guest: {} } }, async ({ app, screen, guest }) => {
await app.open('/chat');
await guest.app.open('/chat');
await screen.getByLabel('Message').fill('Release 2.0 is out');
await screen.getByRole('button', 'Send').tap();
await expect(guest.screen.getByText('Release 2.0 is out')).toBeVisible();
await expect(guest.browser).toHaveURL('/chat'); // typed as Browser, no cast
});// A web user and an iPhone user. actor<S>() types an actor on another target.
import { test } from '@e2e-dev/web';
import { actor, expect } from 'e2e';
import type { Device } from '@e2e-dev/mobile';
test('a web order reaches the courier app', {
platforms: ['web'],
session: 'shopper',
actors: { courier: actor<{ device: Device }>({ target: 'iphone', session: 'courier', agent: 'courier' }) },
}, async ({ app, agent, courier }) => {
await app.open('/cart');
await agent.act('check out with the saved card');
await courier.app.open();
await courier.agent.act('accept the newest delivery request');
await courier.device.openLink('courier://orders'); // typed as Device
});// Actors shared by a group of tests and their hooks, like an extend() chain.
import { test as base, expect } from '@e2e-dev/web';
const test = base.actors({ mod: { agent: 'moderator', agentContext: 'You moderate #general.' } });
test.describe('moderation', { session: 'member', actors: { mod: { session: 'moderator' } } }, () => {
test.beforeEach(async ({ app, mod }) => {
await app.open('/c/general');
await mod.app.open('/c/general');
});
test('the moderator removes spam', async ({ mod, screen }) => {
await mod.agent.act('delete the message "BUY NOW"');
await expect(screen.getByText('BUY NOW')).toBeHidden();
});
});Types
export interface ActorOptions {
/** Target the actor runs on, by name. Default: the target the test runs on. */
target?: string;
/** Session a setup test saved on the actor's target, restored before the body. */
session?: string;
/** Configured agent (`agents.<name>`) for this actor's agent steps. One name, never a list. */
agent?: string;
/** Context for this actor's agent steps only. Not inherited from the test's `agentContext`. */
agentContext?: string;
/** Capabilities the actor's target must have, else the pair is skipped at selection. */
requires?: readonly Capability[];
}
declare const actorSurface: unique symbol;
/** An actor declaration that also carries its engine's fixture types. Compile time only. */
export interface ActorDeclaration<Surface extends object = {}> extends ActorOptions {
readonly [actorSurface]?: Surface;
}
/** Types an actor. At runtime it returns its argument. A `target` is kept in the type. */
export function actor<S extends object = {}>(options: ActorOptions & { target: string }): ActorDeclaration<S> & { readonly target: string };
export function actor<S extends object = {}>(options?: Omit<ActorOptions, 'target'>): ActorDeclaration<S>;
export type ActorDeclarations = Readonly<Record<string, ActorOptions>>;
export interface ActorFixtures {
readonly name: string;
readonly target: string;
readonly platform: string;
readonly app: App;
readonly screen: Screen;
readonly agent: Agent;
}
/** Same target: the test's engine fixtures. Explicit target: only what actor<S>() declares. */
type ActorSurface<D, Surface> =
D extends ActorDeclaration<infer S> ? (D extends { readonly target: string } ? S : Surface & S) : Surface;
export type Actor<D, Surface = {}> = Omit<ActorFixtures, keyof ActorSurface<D, Surface>> & ActorSurface<D, Surface>;
export type ActorsOf<A, Surface = {}> = { readonly [K in keyof A]: Actor<A[K], Surface> };
type ReservedName = 'agent' | 'app' | 'screen' | 'platform' | 'session';
/** An actor name that is already a fixture of this test is a type error. */
export type CheckedActors<A, Fixtures> = A & { readonly [K in keyof A & (keyof Fixtures | ReservedName)]: never };
// TestOptions does not change. Only the actors overload takes `actors`.
export interface DescribeOptions extends Omit<TestOptions, 'only' | 'fail'> {
serial?: boolean;
/** Defaults for actors the tests inside declare. Cannot add an actor or change its target. */
actors?: Readonly<Record<string, Omit<ActorOptions, 'target'>>>;
}
export interface TestAPI<Fixtures = TestFixtures, Surface extends object = {}> {
(title: string, fn: TestFn<Fixtures>): TestCase;
(title: string, options: TestOptions, fn: TestFn<Fixtures>): TestCase;
// Last on purpose: TypeScript reports the last overload's error, so a bad
// `actors` value gets a message about `actors`, not about TestOptions.
<const A extends ActorDeclarations>(
title: string,
options: TestOptions & { actors: ActorDeclarations & CheckedActors<A, Fixtures> },
fn: TestFn<Fixtures & ActorsOf<A, Surface>>,
): TestCase;
actors<const A extends ActorDeclarations>(actors: CheckedActors<A, Fixtures>): TestAPI<Fixtures & ActorsOf<A, Surface>, Surface>;
/** The type-only form also records engine fixtures, so a same-target actor gets them. */
extend<Extra>(): TestAPI<Fixtures & Extra, Surface & Extra>;
extend<Extra>(fixtures: FixtureDefinitions<Fixtures, Extra>): TestAPI<Fixtures & Extra, Surface>;
// ...the rest unchanged
}@e2e-dev/web and @e2e-dev/mobile already export test as base.extend<{ browser: Browser; app: WebApp }>() and base.extend<{ device: Device }>(), so they fill Surface with no change on their side.
Type check
I compiled this sketch against main at 5c7e18f9 with TypeScript 7.0.2 and the repo's compiler settings, using the built Browser, WebApp, and Device types:
| Case | Result |
|---|---|
Same-target guest.browser: Browser, guest.app: WebApp |
Compiles |
actor<{ device: Device }>({ target: 'iphone' }) gives courier.device: Device |
Compiles |
courier.browser on that iPhone actor |
Type error |
Two simulators, device and bob.device |
Compiles |
test.actors() with describe defaults and beforeEach reading mod |
Compiles |
An undeclared actor bob in the body |
Type error |
sesion typo, alone or next to session |
Type error: 'sesion' does not exist in type 'ActorOptions'. Did you mean to write 'session'? |
An actor named app or browser |
Type error |
Re-declaring an actor that test.actors() already added |
Type error |
agent: ['a', 'b'] on an actor |
Type error |
target in describe-level actors |
Type error |
{ target: 'iphone' } without actor<S>() gets no web browser |
Type error on phone.browser |
A shared const opts: TestOptions = { timeout: 60_000 }, as suites write today |
Compiles |
Actors in a shared as const object |
Compiles, names kept |
A first draft of this sketch had three traps, and the version above avoids them:
- If
TestOptionsitself gets anactors?field, a call the actors overload rejects falls through to the plain(title, options: TestOptions, fn)overload and compiles. An actor namedappthen disappears from the types without an error. KeepTestOptionsas it is. - If
actor()has only one signature, its return type does not record thattargetwas set. A cross-target actor then inherits the test's web fixtures, andcourier.browsertype-checks on an iPhone. - Without
ActorDeclarations &in the overload'sactorstype, a typo next to a valid field ({ session, sesion }) is not caught.
Proposed engine contract and capacity
export interface Engine {
/**
* A new engine built from the same options that shares none of this one's
* state. The harness calls it for a second instance of the same handle in
* one process. In-process only, never sent over the wire. A clone gets
* init and dispose, never prepare or finish, and reads what prepare
* provisioned from EngineInitInfo.env. Without it, a process can drive
* only one instance per handle.
*/
clone?(): EngineHandle;
}
export interface EngineAttemptContext {
/** The actor this instance serves in the attempt, for display only. Absent for the test's own user. */
readonly actor?: string;
}web()andmobile()implementcloneas() => web(options)and() => mobile(options).- An actor on another target needs nothing new. Each target's handle still drives one instance per process.
- An actor on the same target with an in-process
defineEngineengine needsclone. Without it, the run fails before any test withUNSUPPORTED_CAPABILITY, naming the test, the target, and the engine. This is the opt-in: the harness cannot know whether an engine's closure state can be entered twice, andloopbackTransportserves the same handle on every connection. - An engine behind
connectEngine(spawn, socket, engine server) needs no opt-in. The harness opens one more connection, which servers already handle forworkers > 1. Its manifest'sworkerscaps it. - No config reload, so no
INVALID_CONFIGfor engines made inside packages, and runs with no config file work. workersbecomes the budget of live app instances: each worker's own plus the actors it holds. A test with two users uses two. This keeps hosted leases and CPU within what the user set.- The scheduler reserves a file's whole demand per target before dispatch, all or nothing, so a worker never waits mid-file for a slot another worker holds. A file whose demand is larger than
workersruns alone, so--workers 1still works. Suites with no actors schedule exactly as today. - A test that needs more instances than its target can serve fails alone with a new
CAPACITY_EXCEEDED(configuration, exit 2), and the rest of the run continues. That replaces the run-wideENGINE_FAILURE. slotsandworkerSlotkeep their current meaning.peerSlotsgoes away.
Report changes
The same data as now under a different name: actor instead of user on steps, artifacts, app log lines, and errors, plus attempt.actors with each actor's target, slot, and environment, and result.actors with the declared actors. A replay recording of an actor step adds actor: "<name>@<targetId>" to its key. The keys of the test's own steps do not change, so existing recordings stay valid, the same as the current PR.
Costs of this direction
- An actor's name is a fixture name, so it shares the namespace with the suite's own fixtures. The types and the collector both catch a clash, and it can only happen in new code.
- A third-party in-process engine needs
clonebefore two users can share its target. Cross-target and protocol engines need nothing. - Reserving per file means a file with one two-user test holds two instances for the whole file. Multi-user tests belong in their own files.
- The type sketch has more moving parts than
Record<string, PeerFixtures>. I think the typed fixtures are worth it, but it's a real cost. - I compiled only the types. The scheduler and
cloneparts are not prototyped.
Requested changes
- Replace the
peersoption and fixture withactors: top-level, author-named fixtures typed as above, withactor<S>()for cross-target actors andtest.actors()for shared ones. - Add
Engine.clone?()and build same-target instances with it, instead of reloading the config. Support engine servers through one extra connection. - Count actors in
workers, reserve per file, and fail one test withCAPACITY_EXCEEDEDwhen it does not fit. DroppeerSlotsand the newworkerSlotmeaning. - Make an undeclared actor a type error, and drop the runtime
INVALID_CONFIGfor it. - Rebase onto
mainfirst. After #1737 these types live in@e2e-dev/core(packages/core/src/types.ts,packages/core/src/engine/index.ts), andgit merge-treeshows 15 conflicting files. The public API change then needs an@e2e-dev/corechangeset too.
Once the API is settled, splitting the PR into runner, reporters, and engines, as you suggested in the description, sounds good to me.
|
Thanks for the careful review, and for compiling the types against main. I agree with all of it and will rework the PR that way: A few questions before I start:
|
|
@TanmayOG, sorry, I wrote my review without reading #1716 first. Marcos's proposal and the maintainer triage there cover the same API, and the triage already asked to settle one shape in #1716. Let's settle the API in #1716. Please hold the rework I asked for in my review until we agree there. I'll post my proposal in #1716, revised against the points raised there, and answer your three questions in the same place. |
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,screenandagentas they are today.A peer can run on another target, so one test can drive a browser and an iPhone:
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.--ai-trace. Its files go inpeers/<name>/.peerscan be set on adescribe, so a collaborative suite doesn't repeat it.web({ connect })or on a device provider is refused withUNSUPPORTED_CAPABILITYbefore anything is leased.Open questions
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.workers. Should a run-wide cap count them?Issue
Related to #1716
Verified
Ran it locally: yes
❯ 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.tests/two-users.e2e.tson two iOS simulators: passed, with one video per user.Checklist
pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.peerskeeps working.docs/**/*.mdxpage for the behavior, andskills/e2e/if the skill describes it..d.tsreviewed,tests/types/sdk-types.tsupdated; wire change edits the schema and both fixtures.e2e/engine): changesets fore2e,@e2e-dev/web, and@e2e-dev/mobile.