feat(cli): e2e compile turns recorded agent.act steps into test code
RFC, draft. It works end to end and is tested, but I'm opening it to agree on the shape first: the command, the block format, and what counts as safe to compile. Names, codes, and defaults are all open to change. Open questions are at the end.
e2e compile replaces a recorded agent.act() call with the screen.* and app.* lines its replay cache recording repeats, in place in the test, between two JSDoc comments.
- Compared with the replay cache, a compiled step trades self-healing for review. A replay that doesn't match hands off to the agent. A compiled line fails like any hand-written locator, and
e2e compile revertbrings the agent back. - Compared with
e2e mcp'stest_lines, which checks each line against the live screen while the agent walks the flow, compile writes from the recording alone. So it checks its own work: after writing, it runs each compiled test once and keeps only the blocks that pass.
Why
An agent.act() with no recording costs a model round trip, and a reviewer only ever sees the instruction, never what ran. The replay cache removes the model call, but a recorded step lives in .e2e/cache/ as a JSON file named by its key hash, which never shows up in the test's diff. It also misses when its key changes (another engine or engine contract, the replay policy, the app's identity, a renamed test), and then the step calls the model again.
This proposes a third state between "the agent does it" and "a person wrote it". The agent finds the path once, and compile writes that path into the test as code a reviewer reads and that runs with no model and no cache.
flowchart LR
A["agent.act('...')"] -->|e2e run records| B[(replay cache<br/>trace-1)]
B -->|e2e compile| C["/** @compiled */<br/>screen.* lines<br/>/** @end compiled */"]
C -->|app changed, test breaks| D[e2e compile revert]
D --> A
What it looks like
npx e2e compile tests/checkout.e2e.ts # record, write, run once, keep what passes
npx e2e compile tests/checkout.e2e.ts --dry-run # print the change; run and edit nothing
npx e2e compile status [--json] # every step: compiles, compiled, stale, or why it stays
npx e2e compile revert tests/checkout.e2e.ts:12 # put the agent.act() back (--dry-run to preview)
--dry-run is the only mode flag, and means the same on compile and revert, as on e2e upgrade. With several targets, --target <name> picks whose recordings compile.
examples/with-vite/tests/agentic.e2e.ts before:
test('the agent gets a greeting', { skip }, async ({ app, agent, screen }) => {
await app.open('/');
await agent.act('get the app to greet {name}', { params: { name: 'Grace' } });
await expect(screen.getByRole('status')).toHaveText('hello, Grace!');
await agent.assert('the app greets Grace by name');
});
After e2e compile (recorded with Claude Code over @e2e-dev/acp; comments trimmed):
test('the agent gets a greeting', { skip }, async ({ app, agent, screen }) => {
await app.open('/');
/**
* @compiled agent.act("get the app to greet {name}")
* @from "await agent.act('get the app to greet {name}', { params: { name: 'Grace' } });"
* @recording fd36642b39fe
* @step 9dadd2295d82.71e0d496a8c9
* @recordedAt 2026-11-10
* @compiledAt 2026-11-10
* @verifiedAt 2026-11-10
*/
await screen.getByRole("textbox", "name").fill("Grace");
await screen.getByRole("button", "greet").tap();
await expect(screen.getByText("hello, Grace!")).toBeVisible();
/** @end compiled */
await expect(screen.getByRole('status')).toHaveText('hello, Grace!');
await agent.assert('the app greets Grace by name');
});
- A step with no recording is recorded first.
compileruns its test (e2e run <file:line>), and a step whose run does not pass stays anagent.act(). - The block is a pair of JSDoc comments found through oxc's comment list, so a trailing comment or CRLF line endings don't lose it.
@fromkeeps the original statement byte for byte, andrevertputs exactly that back (fixtures and imports compile added stay). The reverted call has the same cache key, so its recording replays again. @recordingand@stepletstatusmark a blockstaleonce its step is recorded again.- Credentials and secrets are written by name (
credentials.user('admin').password,secrets.get('pin')), andunique()params as the expression the test passed. No value the ledger redacted can reach the file.
When a recording is pinned to a call
compile touches only a call a recording is pinned to. Everything else stays an agent.act(), and e2e compile status gives the reason as a code.
- The call is a literal instruction in a bare
await agent.act(...)statement of the test's own callback. A call inside a loop or a branch (nested-call) or in a helper (not-in-body) stays, because the source doesn't say how many times it runs. So does every call of a test declared in a loop (loop-declared), because one source serves several tests. - Params the source spells out are projected and digested the way the cache key is (
validateParams+templateParams;tests/unit/compile-params.test.tspins this against the runtime). A recording made with other params, under another replay policy (when the recording names its policy; older ones don't), or counted together with a helper's call is not taken (tests/integration/cli-compile-pinning.test.ts). - There must be one agent, one recording per call by
callIndex, and a step's repeats compile together or not at all. A call with hooks (onAction,onBeforeAction) or atimeoutstays (step-options).
A target with no test id is located by its role and name, text, or placeholder, and its line ends in // unverified locator. A call whose params the source doesn't spell out takes its test's only recording of that instruction. Then the check: compile runs each compiled test once on every target, with no retries, and puts back the blocks of any test that doesn't pass (verify-failed). The blocks that pass get @verifiedAt and lose their // unverified locator comments.
Some steps never compile, by design: a value read off the screen during that run (runtime-value), a project tool (project-tool), a hover or drag at a bare viewport point (point), and keyboard input to whatever had focus (focus-keyboard). Those stay with the agent. A tap at a bare viewport point, as on a canvas, compiles to screen.tapAt({ x, y }); it holds only on a viewport of the recorded size, which the checking run confirms.
Coverage on this repo's examples and demos
I ran every agent.act() in examples/ and apps/ on current main through compile, in a separate worktree. The examples ship an AI Gateway config, so for the run I swapped in my own subscriptions: Claude Code over @e2e-dev/acp, and ChatGPT through e2e/oauth/chatgpt for the dogfood suite that needs the built-in agent's project tools. The two benchmarks used their committed recordings. The output is a demo branch, not for merge: the compiled tests.
| Suite | agent.act steps | Compiled and passed | Left, and why |
|---|---|---|---|
examples/with-{vite,next,astro,angular} (web) | 8 | 8 | |
examples/with-swiftui (iOS), with-compose (Android) | 4 | 4 | |
examples/with-{kotlin-multiplatform,flutter,maui} (Android + iOS, verified on both), with-expo (iOS + Android + web, verified on all three) | 8 | 8 | |
apps/testbed tests-agent | 21 | 18 | 1 focus-keyboard (a canvas form typed through the keyboard); 1 nested-call (the test reads the step's summary); 1 not-recorded (the step ends where it began, so the cache keeps nothing) |
apps/testbed dogfood suites | 9 | 0 | 4 project-tool; 5 not-recorded (4 tests written to fail, 1 tool-only step with no action to replay) |
apps/web-benchmark tests-agent | 32 | 10 as written, 24 with one test per scenario | 4 runtime-value; 2 nested-call (expected failures inside a helper); 1 focus-keyboard; 1 verify-failed (a 431-screen scroll) |
apps/mobile-benchmark tests-agent (iOS) | 24 | 0 as written, 9 with one test per scenario | 2 runtime-value; 1 focus-keyboard; 2 project-tool; 4 not-recorded (the recording run did not pass); 6 verify-failed (below) |
| Total | 106 | 48 as written, 71 with one test per scenario |
- Every example step compiles and passes on every target the example runs. Every step left in
apps/has a code, and none isambiguous-recording. - One test per scenario. Both benchmarks declare one test per scenario in a loop, so every scenario is
loop-declaredas written. The demo branch also declares each scenario as its own test, with the same titles and instructions, so the committed recordings still match; that is what the bold numbers count. It is a demo of what the loop costs, not a change I'm proposing to the benchmarks. - What the checking run caught. A SwiftUI greeting recording that tapped "열기" ("Open"), a transient iOS prompt, went back to
agent.act(); a fresh recording compiled. On the mobile benchmark it put back six: two recordings that tapped iOS's "Not Now" and "Allow" dialogs, which a later run doesn't show; a scroll that stopped short of its row; two test ids that match several nodes on a later run (PXGGridLayout-Infoin the photo picker,Cardin Stripe's sheet); and a tap the keyboard covered. Fresh recordings of these fail the same way, so they are gaps in compile or the recorder, listed below. - Simulator state. The benchmark app asks for the microphone on launch while the permission is undetermined, and the system prompt covers the home list the scenarios open from. Mobile numbers are from a simulator with the prompt answered.
- Cross-platform ids. Android reports an
AutomationIdor resource id as<package>:id/<name>; compiled lines write the short form, which the mobile engine matches on Android and iOS alike, so the .NET MAUI blocks recorded on Android pass on iOS. - Imported names. Compiled lines use a name the file already imports, such as the mobile benchmark's
expectfrom its own fixtures module.
Open questions
- Name.
compilecan read as TypeScript compilation. Is it the right word next toe2e cacheande2e run? - Block format. JSDoc comments leave the public API unchanged. The alternative is a construct the runtime knows about (
agent.act(instruction, { compiled: { run } })), which would let a failing compiled step hand off to the agent instead of failing. - A mode with no run.
compilealways runs the compiled tests, so it needs the app, its devices, and a model for any judgment left in the test. Restricted to test-id targets, a write with no run would have compiled 15 of the 106 steps above, and no canvas tap. Is that mode worth a flag, or is--dry-runenough? - The checking run. Is one passing run on every target, with no retries, enough?
- CI.
compileexits 0 even afterverify-failed. Shouldstatusexit non-zero onstaleblocks or below a coverage floor? A run withCIset records nothing unlesscache.modeisread-write, so compile mostly belongs on a laptop today. - Recordings after compile. A compiled step never replays its recording again, except after
revert. Should compile leave the committed recordings alone, or delete them in the same change? - Date tags.
@recordedAt,@compiledAt, and@verifiedAtchange on every recompile, which is diff noise. Are they worth it next to@recording? status --json. Not a schema'd wire format yet. Should it becompile-status-1with fixtures?- Recording verified lines. If the recorder kept the verified test line for each action (what the MCP session does in
mcp/test-lines.ts), most// unverified locatorlines would be certain before the checking run. - Engine verbs. The agent's keyboard dismissal on mobile has a test line,
device.dismissKeyboard(), but it belongs to@e2e-dev/mobile's fixture, and core never names an engine's fixtures. Compile drops it, and a later tap behind the keyboard fails. Should an engine contribute compile lines for its own verbs? - Twins by test id. A recording names a target by test id without its position when the id repeats (seven photo grid cells share one), so the line is ambiguous on replay. Should the recorder keep a position whenever an id is not unique?
- Loops and helpers. Should
compileemit a separate compiled test per recording for a loop-declared test, or leave those alone?
Verified
Ran it locally: yes
The worktree run above, on current main. For example, examples/with-vite with this branch built and packed:
$ npx e2e compile tests/agentic.e2e.ts --dry-run
✓ L11 "get the app to greet {name}" → 2 action(s), 1 assertion(s) (2 unverified locator(s))
✓ L21 "press greet without typing a name" → 1 action(s), 1 assertion(s) (1 unverified locator(s))
2 step(s) would compile, 0 left to the agent; without --dry-run, the files change and a run checks the lines
$ npx e2e compile tests/agentic.e2e.ts
...
✓ L11 "get the app to greet {name}" → 2 action(s), 1 assertion(s) (2 unverified locator(s))
✓ L21 "press greet without typing a name" → 1 action(s), 1 assertion(s) (1 unverified locator(s))
Verifying 2 compiled test(s): e2e run tests/agentic.e2e.ts:7 tests/agentic.e2e.ts:18
...
✓ the agent gets a greeting passed with its compiled lines
✓ the agent finds the empty-name error passed with its compiled lines
2 step(s) compiled, 0 left to the agent
$ npx e2e run tests/agentic.e2e.ts --video on
✓ the agent gets a greeting > agent.assert "the app greets Grace by name" · 1 model call
✓ the agent finds the empty-name error > agent.assert "the app asks for a name" · 1 model call
...
Tests 2 passed (2)
No agent.act step is left in the run; only the judgments call a model. The compiled greeting test, 1.5 s into its run ():

The file it writes matches the demo branch's, dates aside. pnpm check, the unit suite (3600 tests), and the two compile integration files (13 tests: record, write, check, revert, the verify-failed path, and pinning) pass.
Secrets: on the demo branch, git grep for the testbed's and the web benchmark's credential passwords finds nothing, and the fills read the credential by name:
apps/web-benchmark/tests-agent/login-form.e2e.ts: await screen.getByTestId("password-input").fill(credentials.user("benchmark").password);
apps/testbed/tests-agent/act.e2e.ts: await screen.getByRole("textbox", "Password").fill(credentials.user("admin").password);