fix(mcp): draft a test line for every step a desktop session takes (ENG-1533)

Merged
KD
2d ago
+705-83

What

e2e mcp's test lines replay what the session did, on every engine:

  • The point tools (tap_at, hover_at, type_at, press_at, select_at, drag_at) print a test line: screen.tapAt({ x, y }) where the engine taps a bare point, else the locator line of the control under the point. A step no line can repeat says so (No test line: ...) and stays in the draft as a comment, where it used to be dropped silently.
  • desktop.useWindow(window) is drafted by title, desktop.useWindow((await desktop.windows()).find((window) => window.title === "Inbox") ?? "titled Inbox"), not by a window id that is dead on the next launch. With no window of that title on replay, it fails with "the app has no window titled Inbox" rather than reading the focused one.
  • An action on a node id from an earlier observation writes the line of the node it acted on, found by the rule the action uses.
  • run_code in a session attached to a held test (open_session { attach }) has the engine's fixture (desktop, browser, device), one set for the whole attachment, as a standalone session's does.

Engines get one new optional field for this: FixtureOperation.testLine in @e2e-dev/core/engine. ExecutorNode from e2e/agent gains testId, as the listing already shows it. @e2e-dev/desktop's peer floor on @e2e-dev/core and e2e rises to >=0.25.1, the release with testLine.

Why

okwasniewski's e2e mcp pass on #2323 found each of these on a desktop app: a draft missing a tab tap and a field edit, a useWindow line that fails on replay, and an attached agent that could not switch back to the app's window (desktop is not defined).

How it works

  1. FixtureOperation.testLine (packages/core/src/engine/index.ts:234) lets an engine say how a recorded fixture call is spelled in a test line: { args } in place of the arguments, or { note } kept as a comment. fixture-recording.ts:7 passes it to the recorder, and windowLine (packages/desktop/src/desktop.ts:71) drafts useWindow by a non-empty title, ending with ?? "titled <title>", an id useWindow refuses, since undefined would go back to the focused window.
  2. SessionTestLines (packages/e2e/src/session-tools/test-lines.ts:191) works out a point tool's target the way the action does and writes pointCode (:818) or the control's own line. catalog.ts records the point tools' lines.
  3. An id only an earlier observation listed is re-found on the newest screen by refound (test-lines.ts:338), which calls the action's own describeTarget and relocateDescriptor: role, name, test id, placeholder, and input purpose, the text only for a node with neither a name nor a test id. That needs the test id on each listed node, so projectTree copies it onto ExecutorNode (packages/core/src/agent/executor.ts:133). open_session's text and the reference say the same.
  4. createEngineFixtures (packages/core/src/run/fixtures.ts) builds an engine's fixtures over a session. buildCodeAttempt (packages/e2e/src/run/worker/held-test-tools.ts:419) gives the attached run_code fixtures over the held test's session with the attachment's own step recorder, so the calls stay out of the test's report and a --step hold never stops them. It builds them on the first call and keeps them for the attachment, so what a fixture holds (a web route) carries to the next call; each call enters its own phase of the attachment's one budget, cancelled with that call.
  5. docs/reference/mcp.mdx, docs/reference/engine.mdx, docs/desktop.mdx, and skills/e2e/references/mcp.md describe the lines and the field.

Acting on an earlier observation's id is kept rather than refused: SwiftUI renumbers a window on every change, so refusing would fail every second call in a batch. A secret fill still runs its checks on the node it found.

Issue

Review items from okwasniewski's e2e mcp pass on #2323.

Verified

Ran it locally: yes

  • Unit tests for each line shape, and integration tests: the drafted lines, .check() and screen.tapAt among them, replay in a real web run (mcp-test-lines.test.ts), and attached run_code calls stay out of the held test's report (mcp-step-attachment.test.ts).
  • The fixes after review, each with a test that fails on the code before it: two "Delete" buttons told apart only by test id, renumbered and swapped, draft the one the tap touched; two nameless rows whose text swapped draft the row the action acted on; a property set on an attached fixture in one call is there in the next; and a drafted useWindow line run with no "Inbox" window gives "titled Inbox".
  • Live, desktop testbed through e2e mcp, background mode: tap_at printed getByRole("button", "Enable later").tap(); useWindow drafted the title line in a standalone and an attached session; the attached run_code switched to the Controls window and the resumed test read it and passed.
  • scroll where nothing scrolls answers scroll down #n2 failed: … nothing here scrolls down, not "may have reached the app" (checked live, no code change).

Checklist

  • Changeset added (pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only. Patches for e2e, @e2e-dev/core, and @e2e-dev/desktop.
  • Breaking change: title carries !, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md).
  • Docs updated in the same PR: the docs/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it. docs/reference/mcp.mdx, docs/reference/engine.mdx, docs/desktop.mdx, and skills/e2e/references/mcp.md.
  • Contract change: emitted .d.ts reviewed, tests/types/sdk-types.ts updated; wire change edits the schema and both fixtures. FixtureOperation.testLine and ExecutorNode.testId are new optional fields; nothing else in the emitted .d.ts changes, and sdk-types.ts needed no assertion for them.
  • Engine contract change (e2e/engine): changesets for e2e, @e2e-dev/web, and @e2e-dev/mobile. The field is optional and only @e2e-dev/desktop sets it, so the web and mobile engines need no changeset.

šŸ¤– Generated with Claude Code