Skip to content

feat: add MultiActorSession for coordinated multi-user browser testing#2

Merged
drewstone merged 1 commit intomainfrom
feat/multi-actor-session
Mar 1, 2026
Merged

feat: add MultiActorSession for coordinated multi-user browser testing#2
drewstone merged 1 commit intomainfrom
feat/multi-actor-session

Conversation

@drewstone
Copy link
Contributor

Summary

  • Adds MultiActorSession and Actor classes for coordinated multi-user browser testing
  • Each actor gets an isolated BrowserContext (separate cookies, localStorage, auth state) while sharing the same Browser instance
  • Imperative API — consumers orchestrate with standard async/await for sequential flows and Promise.all() / session.parallel() for concurrent execution
  • Cleanup-safe: partial creation failures (e.g., setup hook throws) close all already-created contexts
  • 22 unit tests covering all public API surface, error paths, and edge cases

Usage

const session = await MultiActorSession.create(browser, {
  actors: {
    admin:   { storageState: '.auth/admin.json' },
    partner: { storageState: '.auth/partner.json' },
    user1:   {},
  },
  agentConfig: { model: 'gpt-4o', vision: true },
});

// Sequential
await session.actor('admin').run({ goal: 'Create quest', startUrl: '/admin' });
await session.actor('partner').run({ goal: 'Approve quest' });

// Parallel
await session.parallel(
  ['user1', { goal: 'Start quest' }],
  ['admin', { goal: 'Monitor dashboard' }],
);

await session.close();

Test plan

  • npx tsc --noEmit — zero type errors
  • npx vitest run tests/multi-actor.test.ts — 22/22 pass
  • npx vitest run — 79/79 pass (zero regressions)
  • npx tsc — dist output includes multi-actor.{js,d.ts}

🤖 Generated with Claude Code

Enable multi-user browser tests where different roles (admin, partner,
user) interact with the same application with isolated auth state.

Each actor gets its own BrowserContext (separate cookies/localStorage)
while sharing the same Browser instance. Consumers orchestrate with
standard async/await for sequential flows and Promise.all() for parallel.

- MultiActorSession.create() — builds isolated contexts per actor
- Actor.run() — delegates to AgentRunner, accumulates results
- session.parallel() — concurrent execution with named result Map
- session.close() — idempotent cleanup with AggregateError on failures
- Partial creation failure cleanup (setup hook throws → all contexts closed)
- Config merging: shared agentConfig + per-actor overrides
- onTurn callback prefixed with actor name for unified logging
- Raw page/context/driver access for hybrid scripted+agent flows
@drewstone drewstone merged commit 3c11bcc into main Mar 1, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant