feat(e2e): pin agent.act steps in a steps file or inline

Closed
KD
14d ago
+2758-96

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 --pin writes each confirmed agent.act() step that is not pinned yet to <test>.steps.json (new wire format steps-1, packages/e2e/schema/steps-v1.schema.json). --pin all records 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 with cache: '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 is REPLAY_STALE, and the message names the field.
  • agent.act(goal, { steps: [] }) works like toMatchInlineSnapshot. 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 empty steps: [] 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-each runs 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 required for one run, fails an agent.act() step with no pin with REPLAY_STALE instead of running the agent, so CI runs only reviewed steps (gronxb's comment).
    • A run with --pin records instead. Under required, an empty steps: [] records only under --pin.
    • A call opts out with pin: false (not with steps), and --pin skips it. An executor with cache: 'off' fails unless the call opts out.
    • Judgments are out of scope. Sessions (e2e mcp, openHost) never require pins. pins is not in the config digest, so setting it keeps the replay cache.
  • The report's step.cache gains pinned: '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:

QuestionDefault here
Where pins live<test>.steps.json next to the test
Pins vs replay cacheA separate tier. The cache is unchanged and not replaced
Renamed testNo stable id. A rename unpins the step
Inline opt-inPer 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 requiredREPLAY_STALE, like an empty steps: [] in CI, not a new error code
Inline contentActions only. The rest goes in the steps file
Hand-written inline actions with no steps-file entryReplay 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' executorUNSUPPORTED_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.ts runs the real web engine:
    • --pin with 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=1 while the executor throws if called. An empty list fails in CI.
  • The inline test spawns dist/cli/bin.js because Vitest in-process runs report compiled line numbers.
  • Fresh-context review by GPT-6.1 Sol found three problems, all fixed here:
    • steps in an openHost session 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 114ff035 and 6daac431. The fixes include confirming a pin with the cache's failure-time cutoff, keeping pins out of onEvent payloads, and tightening the steps-1 schema to match the reader.
  • pins: 'required': pinned-steps.test.ts covers a failed step that makes no model call, pin: false running live, --pin under required, the pin replaying after, and a cache: 'off' executor. Unit tests cover the plan for an empty steps: [], the config and flag, and pin validation. pnpm check, pnpm test, and pnpm test:testbed pass.
  • A fresh-context GPT-6.1 Sol review of pins: 'required' found one problem, fixed here: under required, a local run still recorded an empty steps: [] with the model.
  • Not run against a real model.

šŸ¤– Generated with Claude Code