feat(e2e): pin agent.act steps in a steps file or inline
An alternative to #1673, following the direction in this comment: the trace-1 recording stays the source of truth, and it is pinned beside the test where a reviewer can read it. Nothing is compiled to screen.* code.
What changes
e2e run --pinwrites each confirmedagent.act()step that is not pinned yet to<test>.steps.json(new wire formatsteps-1,packages/e2e/schema/steps-v1.schema.json).--pin allrecords every selected step again. CI refuses--pin(INVALID_CONFIG).- A pinned step replays its recording or fails with
REPLAY_STALE. It never hands off to the agent and makes no model call, even withcache: 'off'and on a retry. - The key is split in two:
- Lookup: title path, target, agent, instruction, params, callIndex.
- Validity:
recordedWith(engine, SPI, replay policy, app identity, agent context digest). Any difference isREPLAY_STALE, and the message names the field.
agent.act(goal, { steps: [] })works liketoMatchInlineSnapshot. The next local run writes the actions into the call through an oxc AST edit. The rest of the recording (start and end path, anchors,recordedWith) goes to the steps file as"inline": true. In CI an emptysteps: []fails.- A step pins only on the replay cache's rule: the test passed and a later check passed. A step that calls a project tool, types a value read off the screen, or has nothing a replay could check is not pinned; the run prints the reason.
- A call that runs with different action lists (a loop, a shared helper) is not written inline, and the run says why.
- A step whose
--repeat-eachruns recorded different flows is not written either. The steps file is written before the inline actions, so a failed write never leaves actions with nothing to check. pins: 'required'in the config, or--pins requiredfor one run, fails anagent.act()step with no pin withREPLAY_STALEinstead of running the agent, so CI runs only reviewed steps (gronxb's comment).- A run with
--pinrecords instead. Underrequired, an emptysteps: []records only under--pin. - A call opts out with
pin: false(not withsteps), and--pinskips it. An executor withcache: 'off'fails unless the call opts out. - Judgments are out of scope. Sessions (
e2e mcp,openHost) never require pins.pinsis not in the config digest, so setting it keeps the replay cache.
- A run with
- The report's
step.cachegainspinned: 'sidecar' | 'inline'(report-1 schema and both fixtures).
await agent.act('get the app to greet {name}', {
params: { name: 'Grace' },
steps: [
{ name: 'type', target: { role: 'textbox', name: 'name' }, value: 'Grace' },
{ name: 'tap', target: { role: 'button', name: 'greet' } },
],
});
flowchart LR
A[agent.act] --> B{pin for this step?}
B -- no --> C[replay cache / live agent, as today]
B -- yes --> D{recordedWith matches?}
D -- no --> S[REPLAY_STALE]
D -- yes --> E[replay actions + end check]
E -- fails --> S
E -- passes --> F[step passes, 0 model calls]
Code: packages/e2e/src/cache/pins.ts (format, read, merge), packages/e2e/src/cache/pin-context.ts (plan per step, confirmation), packages/e2e/src/cache/inline-steps.ts (AST rewrite), packages/e2e/src/run/pin-writes.ts (one write at the end of the run, in the main process), packages/e2e/src/agent/step-cache.ts (replayPinned). Docs: new docs/pinned-steps.mdx, plus the CLI, agent, and errors references and skills/e2e.
Decisions to review
These were not in the comment, so I picked defaults:
| Question | Default here |
|---|---|
| Where pins live | <test>.steps.json next to the test |
| Pins vs replay cache | A separate tier. The cache is unchanged and not replaced |
| Renamed test | No stable id. A rename unpins the step |
| Inline opt-in | Per call (steps: []) only. No file or config switch |
pins: 'required' default | 'optional'. A CI-only setting is pins: process.env.CI ? 'required' : 'optional' |
Unpinned step under required | REPLAY_STALE, like an empty steps: [] in CI, not a new error code |
| Inline content | Actions only. The rest goes in the steps file |
| Hand-written inline actions with no steps-file entry | Replay with no start-path or end check, like hand-written locator lines |
steps with no test file (openHost, in-memory tests) or a cache: 'off' executor | UNSUPPORTED_CAPABILITY |
Verified
Ran it locally: yes. No model key, so a scripted executor stood in for the model.
Scratch project: the fixture app's counter page, @e2e-dev/web, and an executor that taps Increment twice and throws when E2E_FORBID_EXECUTOR=1. Built CLI (dist/cli/bin.js), output filtered to the result lines:
$ e2e run --pin # record and pin
e2e: tests/flows.e2e.steps.json: 1 step pinned
Test Files 1 passed (1)
Tests 1 passed (1)
[exit 0]
tests/flows.e2e.steps.json actions: [{"name":"tap","summary":"tap button \"Increment\"","target":{"role":"button","name":"Increment"}},{"name":"tap","summary":"tap button \"Increment\"","target":{"role":"button","name":"Increment"}}]
$ E2E_FORBID_EXECUTOR=1 e2e run # replay; the executor throws if called
Test Files 1 passed (1)
Tests 1 passed (1)
[exit 0]
$ CI=1 e2e run --pin # --pin in CI
ERROR configuration error INVALID_CONFIG (config)
[exit 2]
$ E2E_FORBID_EXECUTOR=1 e2e run # recordedWith changed
REPLAY_STALE: this step is pinned in tests/flows.e2e.steps.json, and its recording does not replay: the engine contract (999 -> 1) changed after it was pinned; a pinned step never hands off to the agent, so re-record it with e2e run tests/flows.e2e.ts --pin all
Test Files 1 failed | 0 passed (1)
Tests 1 failed | 0 passed (1)
[exit 2]
$ E2E_FORBID_EXECUTOR=1 CI=1 e2e run # empty steps: [] in CI
REPLAY_STALE: this step is pinned by its steps option, and its recording does not replay: its steps option is empty, and this run records nothing (CI, or a session outside e2e run); a pinned step never hands off to the agent, so re-record it with e2e run tests/flows.e2e.ts --pin all outside CI, and commit the change
Test Files 1 failed | 0 passed (1)
Tests 1 failed | 0 passed (1)
[exit 2]
$ e2e run # empty steps: [] locally
e2e: tests/flows.e2e.ts: 1 call pinned inline
e2e: tests/flows.e2e.steps.json: 1 step pinned
Test Files 1 passed (1)
Tests 1 passed (1)
[exit 0]
tests/flows.e2e.ts after:
import { test, expect } from 'e2e';
test('increments the counter', async ({ app, agent, screen }) => {
await app.open();
await agent.act('increment the counter twice', { steps: [
{ name: 'tap', target: { role: 'button', name: 'Increment' } },
{ name: 'tap', target: { role: 'button', name: 'Increment' } },
] });
await expect(screen.getByRole('status', { name: 'Counter' })).toHaveText('2');
});
$ E2E_FORBID_EXECUTOR=1 CI=1 e2e run # inline replay in CI
Test Files 1 passed (1)
Tests 1 passed (1)
[exit 0]
pins: 'required', same scratch project (b252aee0), result lines only:
$ CI=1 E2E_FORBID_EXECUTOR=1 e2e run --pins required # no pin
REPLAY_STALE: this step is not pinned, and this run requires pins (pins: 'required'), so it does not run the agent; pin it with e2e run tests/flows.e2e.ts --pin outside CI and commit the change, or opt the call out with { pin: false }
[exit 2]
$ e2e run --pin --pins required # pin it
e2e: tests/flows.e2e.steps.json: 1 step pinned
[exit 0]
$ CI=1 E2E_FORBID_EXECUTOR=1 e2e run --pins required # pinned
[exit 0]
$ CI=1 e2e run # test renamed, default pins: runs live
[exit 0]
$ CI=1 E2E_FORBID_EXECUTOR=1 e2e run # test renamed, config pins: 'required'
REPLAY_STALE: this step is not pinned, and this run requires pins ...
[exit 2]
$ CI=1 e2e run --pins optional # flag over the config
[exit 0]
$ CI=1 e2e run # pin: false under pins: 'required'
[exit 0]
$ e2e run --pin all # pin: false call: nothing written
[exit 0]
$ e2e run --pins strict
error: option '--pins <mode>' argument 'strict' is invalid. expected optional or required, got "strict"
[exit 2]
$ E2E_FORBID_EXECUTOR=1 e2e run --pins required # steps: [] locally
REPLAY_STALE: this step is not pinned, and this run requires pins (pins: 'required'), so it does not run the agent; pin it with e2e run tests/flows.e2e.ts --pin, or opt the call out with { pin: false }
[exit 2]
$ e2e run --pin --pins required # steps: [] under --pin
e2e: tests/flows.e2e.ts: 1 call pinned inline
[exit 0]
$ CI=1 E2E_FORBID_EXECUTOR=1 e2e run --pins required # inline replay
[exit 0]
INVALID_CONFIG above reads: --pin writes steps files and test files, and a run in CI writes neither (CI is set); pin in a local run and commit the change.
packages/e2e/tests/integration/pinned-steps.test.tsruns the real web engine:--pinwith the cache off writes the steps file.- The next run replays with 0 model calls.
- Changing the engine SPI version fails with
REPLAY_STALE. - Inline, through the built CLI: recording writes the actions into the test file. The replay passes locally and with
CI=1while the executor throws if called. An empty list fails in CI.
- The inline test spawns
dist/cli/bin.jsbecause Vitest in-process runs report compiled line numbers. - Fresh-context review by GPT-6.1 Sol found three problems, all fixed here:
stepsin anopenHostsession ran the executor live; it now fails closed (open-session.test.ts).- A registered secret in a test title could reach the steps file; the title, target, and agent labels in the pin id are now redacted.
- The steps schema accepted actions the reader rejects; each action name now lists its required and allowed fields.
- cubic's two review rounds (19 findings) are fixed in
114ff035and6daac431. The fixes include confirming a pin with the cache's failure-time cutoff, keeping pins out ofonEventpayloads, and tightening thesteps-1schema to match the reader. pins: 'required':pinned-steps.test.tscovers a failed step that makes no model call,pin: falserunning live,--pinunderrequired, the pin replaying after, and acache: 'off'executor. Unit tests cover the plan for an emptysteps: [], the config and flag, andpinvalidation.pnpm check,pnpm test, andpnpm test:testbedpass.- A fresh-context GPT-6.1 Sol review of
pins: 'required'found one problem, fixed here: underrequired, a local run still recorded an emptysteps: []with the model. - Not run against a real model.
š¤ Generated with Claude Code