Skip to content

Latest commit

 

History

History
80 lines (65 loc) · 7.17 KB

README.md

File metadata and controls

80 lines (65 loc) · 7.17 KB

Lab

@executor-js/lab is the harness every test and journey runs on. It starts the products, drives their surfaces, owns time and the network for the run, and makes what the product shows comparable from one run to the next. Tests and journeys import it; they never start a product themselves.

What it gives a test

  • An in-process host per product (Host in lab/src/contracts/host.ts). Each test gets its own host, data directory, port 0 and database. A host offers typed HTTP API clients (host.api(SomeApi)), MCP, its clock, its normaliser and its background jobs. apps/local/server/test/sign-in-link-expiry.test.ts is a short example.
  • One clock, owned by the test (lab/src/contracts/clock.ts). host.clock.advance moves time; host.clock.fork runs work that waits on the clock. When the product reads time the clock cannot reach, the test is blocked on a missing product seam: report it.
  • The normaliser (lab/src/implementation/normalise.ts): ids become <id:N> in order of first appearance, times become relative to the start or <time>, and paths of the run become placeholders. Snapshots and journey recordings are normalised automatically.
  • The egress guard (lab/src/implementation/egress.ts): a test may reach loopback and the stand-ins it registered with egress.standIn(origin, handler); anything else fails the test and names the address. Under bun run test, test:hosted, journeys and surface every process also runs in a loopback-only network namespace (scripts/no-network.ts); defaults that would reach the internet are turned off in lab/src/contracts/offline.ts.
  • Tripwires (lab/src/implementation/tripwires.ts): timers and Date in test code throw; the product's own Date and randomUUID calls are reported with their call site.

Journey drivers

Journeys get these through the harness in journeys/src/implementation/harness.ts, never directly (see journeys). Each speaks only part of its surface: the agent lists and calls MCP tools, for example. When a change shows on a part no driver speaks, see proving a change.

Driver Surface File
Browser: Chromium through Playwright, with a pinned viewport, locale, fonts and motion the dashboards lab/src/implementation/browser.ts
CLI: the checkout's real executor entry point, in a home of its own cli lab/src/implementation/cli.ts, lab/src/implementation/cli-mcp.ts
Agent: the MCP SDK client over HTTP, as an agent connects mcp lab/src/implementation/agent.ts
OAuth MCP client: registers, signs in with PKCE, then connects mcp and the dashboards lab/src/implementation/oauth-agent.ts
HTTP API: requests with the server's key or an organization's token the three APIs lab/src/implementation/api.ts

The products journeys start: startLocal (lab/src/implementation/local.ts), startSelfHost (lab/src/implementation/self-host.ts, one container per journey from an image built once per run) and startCloud (lab/src/implementation/cloud.ts, from a template built once and reused).

Stand-ins

A stand-in plays a service outside the product, so a test can reach it with no network. Each is opt-in: a journey declares it or a test registers it, and nothing starts that was not asked for.

Stands in for How a journey or test asks File
A third-party OAuth provider that also sends webhooks, or an MCP server that needs sign-in provider: "github" or "mcp"; providerTokens: "issued-only" refuses revoked tokens lab/src/implementation/stand-ins.ts, lab/src/implementation/emulate-server.ts
The public app catalog catalog: "stand-in" (Local) lab/src/implementation/catalog-feed.ts
The npm registry self-host builds apps from npmRegistry: "stand-in" (self-host) lab/src/implementation/npm-registry.ts, lab/src/implementation/npm-registry-server.ts
Cloud's own outside services: sign-in providers, mail, billing and the rest always, inside the Cloud the lab starts; the list is cloudStandIns in lab/src/contracts/cloud.ts lab/src/implementation/cloud.ts
Any other HTTP origin, in an in-process test egress.standIn(origin, handler) lab/src/implementation/egress.ts

On self-host a stand-in runs as a container beside the instance (startBeside in lab/src/implementation/self-host.ts), and only its exact origin is let through.

Adding a stand-in

  1. Reuse first: the emulated providers behind standIn, or the fixed-answer server in lab/src/implementation/fixed-server.ts, before writing a new server.
  2. Point the product at it with a setting the product already reads for operators. Never add a test-only hook to product code, and never loosen a product rule: an allow-everything switch is not acceptable where an exact origin would do.
  3. Make it opt-in from the journey declaration or the test, so no other run changes.
  4. Make it as strict as the real service: it refuses what the real one refuses. State that as an invariant in policy/src/invariants.ts, with its test and a break (oauth-stand-in-refuses-what-a-provider-refuses is one).
  5. Record every exchange into the run's evidence (http.json or stand-ins.json).
  6. Fetch nothing at run time. What it serves comes from the checkout, or from an image pulled beforehand with bun run images:pull.

Lab's own tests

bun run test lab runs them. They follow the test policy like every other test.