Skip to content

Commit bb31ad1

Browse files
kdy1claudeokwasniewski
authored
fix(mcp): draft a test line for every step a desktop session takes (ENG-1533) (e2e-inc#2355)
* fix(desktop): let a scroll area scroll itself only with a scroll bar for the axis SwiftUI gives every scroll area the AXScroll*ByPage actions, also one whose content fits or that scrolls only along the other axis. `scroll` counted the page action for the direction as "scrolls itself", so a swipe down on a horizontal carousel inside a vertical page sent AXScrollDownByPage to the carousel, moved nothing, and answered success. `scrolls_itself` now uses the rule the snapshot offers `Scroll` with: a scroll bar for the axis, or, for any role but a scroll area, the page action. A scroll area without that bar hands the swipe to the scroll area above it, and with none is refused as "nothing here scrolls". Review: michal-e2e on e2e-inc#2322 at e7a74d4 (must fix). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(desktop): read focus before a key as a stall, and check frontmost last The focus reads before a key went through `Element::element()`, which drops a stall: an app slow to answer AXFocusedUIElement or AXFocusedWindow got "the field lost keyboard focus", a refusal the engine does not retry, where every other stalled read is a retryable APP_UNRESPONSIVE. `element_attribute` keeps the stall, and `type`, `press`, and `key_window` read focus through it. Past the first typed key, an unanswered read still only shortens the wait for the next key. A headed `type` also re-read the field's focus after its AXFrontmost check for the first key. That read waits on the app, and another app that came forward meanwhile would take the key. The frontmost check is now the last read before the first physical key, as it is for `press`. Review: michal-e2e on e2e-inc#2322 at e7a74d4 (optional). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(desktop): refuse scrollTo on a gone element as a stale ref `read_frame` and the parent reads in `placement` read AX_INVALID_ELEMENT as no frame and no parent, so a gone element was `Placement::Shown` and `scrollTo` answered success before any scroll. Before the reveal rewrite, AXScrollToVisible refused a gone element as stale. `read_frame` and `placement` now pass AX_INVALID_ELEMENT up as they pass a stall, and `reveal` maps it to the retryable STALE_REF. `frame()` still reads any failure as no frame. Review: michal-e2e on e2e-inc#2322 at e7a74d4 (optional). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(desktop): do not confirm a secure fill by a field that went away A secure fill checks AXNumberOfCharacters after the write. A field that a change handler replaced answers AX_INVALID_ELEMENT there, which read as "counts none", so the fill succeeded unchecked. `secure_count` now treats a gone field like a stall: no proof the field counts none, so the fill ends unconfirmed unless the count shows the whole text, as a plain field's fill does. Review: michal-e2e on e2e-inc#2322 at e7a74d4 (optional). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(desktop): retry a stepper whose value read stalls A fill on a stepper whose AXValue cannot be written reads the value to see that it shows a number. A read the app did not answer in time fell through to "the value of this stepper cannot be set", a non-retryable ACTION_NOT_SUPPORTED. It is now the retryable APP_UNRESPONSIVE (and a gone element a stale ref), as every other stalled read is. Review: michal-e2e on e2e-inc#2322 at e7a74d4 (follow-up). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(desktop): name no value in a stepper's failure messages The stepper's failures printed the fill text and the parsed target, and the engine copies the driver's message into the step's error. The secret ledger matches a secret in every spelling a serializer gives it, but not re-parsed as a number, so a secret `0042` filled into a stepper would print as `42`. The five messages (out of range, stopped short, wraps, already showed, steps past) now say "the value" and "where it started" instead of numbers. Review: michal-e2e on e2e-inc#2322 at e7a74d4 (for the maintainer). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(desktop): name a list row for select as the snapshot names it `row_texts` stopped at a text child and read only that child's own label, while the snapshot walks into it and names the row from every text below. A row holding "Invoice" and an untitled heading over "Paid" was "Invoice Paid" to a locator but "Invoice" to `select`. `gather_texts` now walks the way the snapshot gathers a name from content: every level, a text's children before the text itself, and no scroll bar's parts. It takes the tree reads as closures, so a unit test pins the order on a fake tree. Review: michal-e2e on e2e-inc#2322 at e7a74d4 (optional). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(desktop): stop waiting on a row the list replaced as it scrolled it in After `AXScrollToVisible`, `reveal` polled until the element read as shown. Since the gone-element fix, `placement` answers a replaced element with `AX_INVALID_ELEMENT`, which never reads as shown, so a tap, check, or scrollIntoView on a row the list replaces as it scrolls in waited out the poll and then failed as "still off screen". It now ends the poll at once with `STALE_REF`, delivered like any failure after that scroll, as `after_scroll` counts it. Found by michal-e2e's review of e2e-inc#2353. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(desktop): step a stepper from the number its first read showed `set_value` mapped a stalled first `AXValue` read to a retryable stall, then read `AXValue` again for the number to step from, a read that turned a stall into no number. `step_to` then returned without a step, and the fill failed unconfirmed as "stopped short of the value" with nothing pressed. The first read's number is now where stepping starts. The read is split into `shown_number`, so a unit test feeds it a stall and a gone element. Found by michal-e2e's review of e2e-inc#2353. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(desktop): read a stall as one in raise, focus, and the window list The stall fix covered the five focus reads e2e-inc#2322's review named. Four more places still read a stall as an answer: `raise` read a stalled `AXFrontmost` or `AXFocusedWindow` as "could not be brought forward"; `focus` read a stalled `AXFocusedUIElement` as no focus; `holds_focus` read a stalled sheet `AXParent` as another window, so a key for a field in a sheet got a non-retryable "not the app's key window"; and `windows::list` listed every window as unfocused. Each now fails with the retryable `APP_UNRESPONSIVE`, before anything is sent where the read comes first. `stalled` is the one mapping they share, and a unit test feeds it `AX_CANNOT_COMPLETE`. Found by michal-e2e's review of e2e-inc#2353. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(desktop): refuse a swipe with nothing to scroll as not actionable A node swipe where nothing scrolls along the axis failed with `ACTION_NOT_SUPPORTED`, which the engine reads as `UNSUPPORTED_CAPABILITY` and an agent step reports as `POLICY_DENIED`. A window swipe with nothing to scroll already fails as `NOT_ACTIONABLE`; the node swipe now does too (`ACTION_FAILED`), with the same "nothing here scrolls" message. Raised by michal-e2e's review of e2e-inc#2353. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(desktop): check that no stepper failure names a value The doc comment on `step_to` promises its failures name no value, since a secret filled into a stepper could come back re-parsed (`0042` as `42`), where the ledger would not redact it. Only the "steps past" message was checked. The test now drives every failure `step_to` gives: a wrap, a step past and back, a step past that cannot go back, a probe that left the value changed, and one out of time. It asserts no ASCII digit appears in any of them. Asked for by michal-e2e's review of e2e-inc#2353. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ci(desktop): install rustup from a pinned, checksum-verified rustup-init Both `native` jobs ran `curl https://sh.rustup.rs | sh` when the image had no rustup, and the release job builds the driver npm ships right after it. The new `.github/actions/rust-toolchain` composite action downloads rustup-init 1.29.3 for the runner's architecture from static.rust-lang.org and checks it against the SHA-256 recorded in the action before it runs it. It then installs the toolchain rust-toolchain.toml pins and puts that toolchain's cargo first on PATH, the step spec's job already had; the release job now runs it too, which build-native.ts did implicitly through rustup before. rust-toolchain.toml stays the toolchain pin. Answers the follow-up from the e2e-inc#2325 review (okwasniewski): the release job's rustup install was an unpinned curl | sh. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ci(desktop): load the x64 addon under Rosetta before it ships The x64 driver was built and its architecture read with lipo, but no job loaded it, so a build that fails to dlopen or to answer would reach Intel users unnoticed. The new `.github/actions/load-x64-addon` composite action installs Rosetta when `arch -x86_64` cannot run, downloads the official darwin-x64 Node of the version setup-node installed, checks the tarball against that release's SHASUMS256.txt, and has it require the x64 addon under `arch -x86_64` and call status(). It fails on a Node that is not x64, a load failure, or a status() without a boolean `accessibility`. Spec's `native` job runs it after the arm64 load. The release job's `native` job now loads both builds, the arm64 one natively and the x64 one this way, before it uploads them. The engine's loader test stays arm64 only: vitest's native dependencies are installed for arm64. Answers the follow-up from the e2e-inc#2325 review (okwasniewski): the x64 addon is built but never loaded by any job. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ci(desktop): pick rustup-init by OS and architecture together The rustup step chose its binary by `uname -m` alone, so a Linux x86_64 job using the action would download the macOS build, pass the checksum, and fail with an exec format error. It now matches `Darwin arm64` and `Darwin x86_64`, and anything else gets the message it already printed: no pinned rustup-init for that OS and architecture. Raised by michal-e2e's review of e2e-inc#2354. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ci(desktop): retry the rustup-init and x64 Node downloads The native job runs on every pull request and `spec gate` needs it, so a single 5xx or reset from static.rust-lang.org or nodejs.org failed every pull request and merge-queue entry until a rerun. Each download now retries 3 times, as `mcp-publisher` already does. Raised by michal-e2e's review of e2e-inc#2354. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(mcp): print a test line for every point tool The point tools (tap_at, hover_at, drag_at, type_at, press_at, select_at) printed no test line, so test_lines left their steps out of the draft without saying so: a tab tapped and a field edited at a point were missing from a desktop draft. Each point tool now plans its line the way the step resolves its target, through the step's own hit test on the newest screen. Where the engine takes the bare point, a tap prints screen.tapAt({ x, y }) in the viewport's CSS pixels; elsewhere the tool acts on the listed control under the point by id and prints that control's locator line (tap, hover, fill, press, selectOption, dragTo). A hover or a drag at bare points, and a typed key on a point where nothing is listed, print "No test line:" and why, and the draft keeps the step as a comment. A point tool called before the first screenshot does nothing and records nothing. Answers okwasniewski's e2e mcp pass on e2e-inc#2323 (2026-11-26T17:54). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(mcp): write the line of an earlier screen's id for the node it acted on An action on a node id from an earlier observation ran, then answered "No test line: not on the newest screen". The step resolves the id as an agent step does (feed.resolve): an id the newest observation no longer lists is found again by what its node read as, when exactly one node on the newest screen reads the same, and the action runs on that node. The test line looked the id up on the newest screen only. Keeping the action is the decision here, not refusing it before it acts: it is the agent's own resolution, the node it acts on is on the newest screen, a secret fill still runs the full authorization on that node, and an engine that numbers every screen afresh (SwiftUI) would otherwise fail every second call of a batch. The line now keeps the screens before the newest one, as the step does, and finds the same node; two nodes that read alike give no line, as the action fails then. The MCP reference said ids were valid only against the newest observation; it now says how an earlier id resolves. Answers okwasniewski's e2e mcp pass on e2e-inc#2323 (2026-11-26T17:54). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(core): let a fixture operation say how a test line writes its call `e2e mcp`'s test_lines wrote desktop.useWindow({ id: '36086', ... }): the window id run_code passed, which no window has on the next launch, so the drafted line never replays. A fixture operation may now declare testLine (FixtureOperation, in @e2e-dev/core/engine): for an argument that holds only while the app runs, the arguments as a test writes them to find the same thing again, or a note the line carries on why the arguments may not hold. The fixture recorder keeps it by the recorded method, and run_code's recorder asks it before it writes a line, with every string in the arguments through the secret ledger. Core still names no engine: the desktop engine declares it for useWindow, which now drafts as desktop.useWindow((await desktop.windows()).find((window) => window.title === "Inbox")), the form the testbed's own tests use; an untitled window or a bare id keeps its arguments with a comment that the id holds only while the window is open. Answers okwasniewski's e2e mcp pass on e2e-inc#2323 (2026-11-26T17:54). The only change in packages/desktop is the useWindow declaration and its unit test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(mcp): give attached run_code the engine's fixtures run_code in a session attached to a held test (open_session { attach }) had no engine fixture: `desktop is not defined`, even when the test names it, while a standalone session's code has it. On macOS 27 the attached agent then could not pick the real window back with desktop.useWindow() once a system dialog took the screen. Core's new createEngineFixtures builds the engine's own fixtures over a session, each on first touch, as a test's are, recording into the step recorder and budget it is given. The held test's tools give run_code those fixtures over the held test's session, beside the app they already built, with the attachment's own step recorder: the calls stay out of the test's report, and a --step hold never stops one of them, which recording into the test's recorder would. What a fixture changes lives in the engine session, so the test sees it after it resumes. Answers okwasniewski's e2e mcp pass on e2e-inc#2323 (2026-11-26T18:09). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(desktop): draft a useWindow line that fails when no window has the title The drafted `useWindow` line found the window by title, and on replay with no window of that title `find` returned `undefined`, which `useWindow` takes as "go back to the focused window": the test then read and asserted on another window with no error. The line now ends with `?? "titled Inbox"`, an id `useWindow` refuses with "the app has no window titled Inbox". It drafts by title only when the title is a non-empty string; a window object with none, as plain JavaScript can pass, keeps the id and its note. Found by michal-e2e's review of e2e-inc#2355. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(desktop): raise the core and e2e peer floor to the release with testLine `@e2e-dev/desktop` now declares `FixtureOperation.testLine`, which `@e2e-dev/core` 0.25.0 does not have; on it the window line is drafted with the id again, without a word. Both peers now read `>=0.25.1 <1`, as the web and mobile engines already do. Found by michal-e2e's review of e2e-inc#2355. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(mcp): keep one set of engine fixtures for an attachment's run_code `run_code` asks for its attempt on every call, and the held test's attachment built new engine fixtures each time. State a fixture keeps did not carry from one call to the next: a web route added in one call lived on that call's `browser`, so `unroute` in the next removed nothing and the route was still there when the test resumed. The attachment now builds the attempt once, on the first call, as a standalone session keeps its own, and each call enters its own phase of the attachment's one budget, cancelled with that call. The new test sets a property on the fixture in one call and reads it in the next; on the per-call fixtures it reads nothing. Found by michal-e2e's review of e2e-inc#2355. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(core): carry a node's test id on ExecutorNode The listing an executor reads shows a node's test id (`testid="..."`), but `ExecutorNode` had no field for it, so code working from the tree could not tell apart two controls only their test ids separate. `projectTree` now copies `testId` onto the node. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(mcp): find an earlier screen's id for its line by the action's own rule The line for an id only an earlier screen listed re-found the node with its own `twinsOf`, which compares role, name, text, and placeholder and ignores the test id, while the action re-finds it with `describeTarget` and `relocateDescriptor`, which go by role, name, test id, placeholder, and input purpose. Two "Delete" buttons with different test ids, renumbered: the tap landed on the right one and the line said "not on the newest screen". Two nameless rows whose text swapped: the line named the row the action did not touch. The line now calls the same two functions on the listed nodes. Found by michal-e2e's review of e2e-inc#2355. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(mcp): tell the agent an older node id works when one node reads like it `open_session` still said node ids are valid only for the newest observation, while the docs and the skill say an older id is found again when exactly one node on the newest screen reads like its node. Its text now says the same, and the reference names the fields the action goes by: role, name, test id, placeholder, and the text of a node with neither a name nor a test id. Raised by michal-e2e's review of e2e-inc#2355. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(mcp): replay a drafted check line beside the tap_at lines The point-tool change replaced the `check` step with a `tap_at` on the checkbox and left the `check` entry as dead data, so no drafted `.check()` line was replayed. The checkbox is checked with `check` again, then tapped twice at its point with `tap_at`, off and on, and every line replays in the run. Raised by michal-e2e's review of e2e-inc#2355. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Oskar Kwaśniewski <oskar@okwasniewski.com>
1 parent 8525d2e commit bb31ad1

26 files changed

Lines changed: 705 additions & 83 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'e2e': patch
3+
---
4+
5+
`e2e mcp`: `run_code` in a session attached to a held test (`open_session {attach}`) now has the engine's fixture (`desktop`, `browser`, `device`) over the held test's app, as a standalone session's code has. Before, it failed with `desktop is not defined`, so an attached agent could not switch the window the test reads. The calls are the session's: they stay out of the held test's report and steps.

‎.changeset/mcp-earlier-id-lines.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'e2e': patch
3+
'@e2e-dev/core': patch
4+
---
5+
6+
`e2e mcp`: an action on a node id that only an earlier observation listed now prints its test line. The action already found the node again on the newest screen by what it read as, when exactly one node there reads the same, as an agent step does, but the line looked for the id on the newest screen only and printed `No test line: not on the newest screen`. The line now finds that node by the rule the action uses, which goes by role, name, test id, placeholder, and input purpose, so two controls told apart by test id are told apart in the line too. An `ExecutorNode` from `e2e/agent` now carries the node's `testId`, as the listing shows it.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'e2e': patch
3+
'@e2e-dev/core': patch
4+
'@e2e-dev/desktop': patch
5+
---
6+
7+
`e2e mcp`: a `run_code` call of an engine fixture whose argument holds only while the app runs is written in `test_lines` the way the engine says a test finds the same thing again. `desktop.useWindow(window)` is written as `desktop.useWindow((await desktop.windows()).find((window) => window.title === "Inbox") ?? "titled Inbox")` rather than with the window's id, which no longer exists on the next launch; with no window of that title, `useWindow` fails instead of going back to the focused window. An engine declares this with the new `testLine` field of a fixture operation, in `@e2e-dev/core/engine`.

‎.changeset/mcp-point-tool-lines.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'e2e': patch
3+
---
4+
5+
`e2e mcp`: the point tools (`tap_at`, `hover_at`, `drag_at`, `type_at`, `press_at`, `select_at`) now print a test line, and `test_lines` keeps it. A point tool that acts on the listed control under its point prints that control's locator line. A bare tap prints `screen.tapAt({ x, y })` in the viewport's pixels. When no line can repeat the action, the result says `No test line:` and why, and the draft keeps the step as a comment. Before, the point tools printed nothing and the draft left their steps out.

‎docs/desktop.mdx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,12 @@ The `desktop` fixture lists the app's windows (`desktop.windows()`), picks
140140
the one `screen` reads (`desktop.useWindow(window)`), presses a key into the
141141
app's window for an app with no control that takes keyboard focus
142142
(`desktop.press('ControlOrMeta+2')`), and quits the app
143-
(`desktop.closeApp()`).
143+
(`desktop.closeApp()`). A window's id holds only while the window is open,
144+
so a test picks a window by its title:
145+
`desktop.useWindow((await desktop.windows()).find((window) => window.title === 'Controls'))`.
146+
`e2e mcp` writes its test lines that way too, ending with `?? "titled Controls"`:
147+
with no such window, `useWindow` then fails with "the app has no window titled
148+
Controls", where `undefined` would go back to the focused window.
144149

145150
## What differs from the web
146151

‎docs/reference/engine.mdx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2582,8 +2582,14 @@ recorded steps. Each operation takes:
25822582
| `label` | `(...args) => string` | none |
25832583
| `timeout` | milliseconds, a function of the arguments, or `false` when the method owns its deadline | `actionTimeout` |
25842584
| `verifies` | `boolean` | `true` for assertions |
2585+
| `testLine` | `(...args) => { args } \| { note } \| undefined` | the arguments as given |
25852586

25862587
- Nested maps describe namespaces.
2588+
- `testLine` is for an argument that holds only while the app runs, such as
2589+
a window id. `e2e mcp` writes a `run_code` call of the method in its test
2590+
lines with `args` in place of the arguments, code that finds the same
2591+
thing on the next run, or keeps the arguments and adds `note` as a
2592+
comment. Strings in the arguments it gets are already redacted.
25872593
- Recording decorates the object in place, so create a fresh surface in each
25882594
factory invocation.
25892595
- The runner opens the step before calling a declared method, so attachments
@@ -2600,8 +2606,13 @@ export interface FixtureOperation<Args extends unknown[] = unknown[]> {
26002606
readonly timeout?: number | false | ((...args: Args) => number | undefined);
26012607
/** Assertions verify by default; waits may opt in as well. */
26022608
readonly verifies?: boolean;
2609+
/** How a test line `e2e mcp` writes for this call spells it, for an argument that holds only while the app runs. */
2610+
readonly testLine?: (...args: Args) => FixtureTestLine | undefined;
26032611
}
26042612

2613+
/** What `FixtureOperation.testLine` writes in place of the arguments as given. */
2614+
export type FixtureTestLine = { readonly args: string } | { readonly note: string };
2615+
26052616
/** Only declared async methods are recorded. Sync accessors pass through unchanged. */
26062617
export type FixtureOperations<T extends object> = {
26072618
readonly [Key in keyof T]?: T[Key] extends (...args: infer Args) => Promise<unknown>

‎docs/reference/mcp.mdx‎

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ changed on screen.
223223

224224
| Input | Does |
225225
| --- | --- |
226-
| A node id | From the newest observation. |
226+
| A node id | From the newest observation. An id only an earlier observation listed is found again on the newest one by what its node read as (role, name, test id, placeholder, and the text of a node with neither a name nor a test id), when exactly one node there reads the same; otherwise the action fails with `LOCATOR_NOT_FOUND`. |
227227
| The value, key, `checked` state, direction, drop target, project-relative or `sample:` `files`, URL, `width` and `height`, or secret name | What the verb needs. |
228228
| `modifiers` (optional) | On `tap`, `double_tap`, and `right_click`, when the engine declares `tapModifiers`: a list of `Shift`, `Control`, `Alt`, `Meta`, `ControlOrMeta`, held for the click. |
229229

@@ -272,7 +272,7 @@ call {tool: "run_code", args: {code: "const rows = screen.getByRole('listitem');
272272

273273
| Input | Does |
274274
| --- | --- |
275-
| `code` | The body of an async function. `screen`, `app`, `expect`, `credentials`, `secrets`, `services`, `console`, and the engine's fixture (`browser`, `device`, `desktop`, or `electron`) are in scope. A session attached to a held test doesn't have an engine fixture. |
275+
| `code` | The body of an async function. `screen`, `app`, `expect`, `credentials`, `secrets`, `services`, `console`, and the engine's fixture (`browser`, `device`, `desktop`, or `electron`) are in scope, in a session attached to a held test too. |
276276
| `timeout` | Optional. How long each action or matcher on `screen` waits by default, in ms, 1 through 120000. Without it: `5000`, or the config's timeout when shorter. |
277277

278278
```txt
@@ -311,6 +311,13 @@ Test lines: 2, 1 read not listed.
311311
drafted with the function's text and a comment: declare the variables it
312312
uses in the test. What the function itself calls is not drafted again. A
313313
passing `expect(value)` leaves no line.
314+
- A call whose argument holds only while the app runs is drafted the way
315+
its engine says a test finds the same thing again. `desktop.useWindow(window)`
316+
is drafted as
317+
`desktop.useWindow((await desktop.windows()).find((window) => window.title === "Inbox") ?? "titled Inbox")`,
318+
which fails when no window has that title rather than reading the focused
319+
one; for an untitled window, or a window id passed as a string, the line keeps
320+
the id and says in a comment that it holds only while the window is open.
314321
- Each action or matcher on `screen` waits `timeout` by default. A `timeout`
315322
in a line's own options replaces it. Without `timeout`, each waits 5000 ms,
316323
or the config's [`actionTimeout`](/reference/config#actiontimeout) or
@@ -358,7 +365,8 @@ Test line: await screen.getByRole("button", "Sign in").tap();
358365
```
359366

360367
- The locator comes from the target as the newest observation listed it,
361-
before the action runs. Role and name, label, placeholder, text, and test
368+
before the action runs. An id an earlier observation listed is the node
369+
the action acts on there (see [Actions](#actions)). Role and name, label, placeholder, text, and test
362370
id are tried in that order, and the first that matches the target and
363371
nothing else on the live screen wins, as [`locate`](#locate) would report it.
364372
- A locator that also matches twins is narrowed: to nodes that render
@@ -388,13 +396,19 @@ Test line: await screen.getByRole("button", "Sign in").tap();
388396
| `drag`, `upload` | `dragTo(locator)`, `setInputFiles(files)` |
389397
| `scroll_to` a node | `scrollIntoView()` |
390398
| `navigate`, `back` | `app.open(url)`, with a URL on the app's origin as its path; `app.back()` |
399+
| `tap_at` where the engine takes a bare point | `screen.tapAt({ x, y })` in the viewport's CSS pixels, with a comment that a point holds only while the layout does |
400+
| `tap_at`, `hover_at`, `type_at`, `press_at`, `select_at` on the listed control under the point | The control's line, as for `tap`, `hover`, `type`, `press`, and `select` by id |
401+
| `drag_at` between two listed controls | `dragTo(locator)` |
391402

392403
No line: `type` or `press` with no target, `press` with `times` over 1,
393404
`scroll`, `scroll_to` a text, `dismiss_keyboard`, `resize_viewport` (set the
394405
size with the engine's built-in fixture, `browser.setViewport` on web), `switch_tab`
395406
and `close_tab` (`browser.tabs()[tab - 1].activate()` and `.close()` on
396-
web), and a `type` the
397-
node took through the keyboard. The [point tools](#point-tools) print nothing.
407+
web), a `type` or `type_at` the
408+
node took through the keyboard, `hover_at` and `drag_at` at bare points
409+
(no `screen` call repeats them), and `type_at` and `press_at` on a point
410+
where nothing is listed. A [point tool](#point-tools) called before the
411+
first screenshot does nothing and prints nothing.
398412

399413
#### `screenshot`
400414

@@ -641,7 +655,11 @@ exits.
641655

642656
Sessions enforce what tests enforce:
643657

644-
- Node ids are valid only against the newest observation.
658+
- Node ids are resolved against the newest observation. An id that only an
659+
earlier observation listed is found again by what its node read as, when
660+
exactly one node on the newest screen reads the same, as an agent step
661+
finds it; otherwise the action fails with `LOCATOR_NOT_FOUND`. A secret
662+
fill then checks the node it found, as for any fill.
645663
- The single actions fill a secret only through `type_secret`.
646664
[`run_code`](#run_code) fills one as a test does.
647665
- Once the config has loaded, its secret values are redacted from every text
@@ -680,6 +698,10 @@ attachment right away. Any recording still running saves in the background.
680698
The runner logs the saved path or the error. The MCP server logs the same
681699
result if it's still connected.
682700

701+
[`run_code`](#run_code) gets the engine's fixture over the held test's app,
702+
as a normal session's code does, so `desktop.useWindow()` there changes the
703+
window the test reads after it resumes.
704+
683705
The report and trace record the test's own steps. App logs and screen
684706
updates from an attached call can appear in the trace if they arrive after
685707
the call ends.

‎packages/core/src/agent/executor.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ export interface ExecutorNode {
129129
readonly inputPurpose?: SemanticNode['inputPurpose'];
130130
readonly states?: SemanticNode['states'];
131131
readonly attributes?: Readonly<Record<string, string>>;
132+
/** The app's test id for the node, as the listing shows it (`testid="..."`). */
133+
readonly testId?: string;
132134
readonly rect?: SemanticNode['rect'];
133135
readonly framePath?: readonly string[];
134136
readonly children?: readonly ExecutorNode[];

‎packages/core/src/agent/observation.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ export function projectTree(node: RedactedNode, appOrigin?: string): ExecutorNod
448448
...(node.inputPurpose === undefined ? {} : { inputPurpose: node.inputPurpose }),
449449
...(node.states === undefined ? {} : { states: node.states }),
450450
...(attributes === undefined ? {} : { attributes }),
451+
...(node.testId === undefined ? {} : { testId: node.testId }),
451452
...(node.rect === undefined ? {} : { rect: node.rect }),
452453
...(node.framePath === undefined ? {} : { framePath: node.framePath }),
453454
...(node.children === undefined ? {} : { children: node.children.map((child) => projectTree(child, appOrigin)) }),

‎packages/core/src/engine/index.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,20 @@ export interface FixtureOperation<Args extends unknown[] = unknown[]> {
224224
readonly timeout?: number | false | ((...args: Args) => number | undefined);
225225
/** Assertions verify by default; waits may opt in as well. */
226226
readonly verifies?: boolean;
227+
/**
228+
* How a test line `e2e mcp` writes for this call spells it, for an argument
229+
* that holds only while the app runs, such as a window id: `args`, the
230+
* arguments as a test writes them to find the same thing on the next run,
231+
* or `note`, why the arguments as given may not hold, which the line
232+
* carries as a comment. Undefined writes the arguments as given. Strings
233+
* in the arguments it receives are already redacted.
234+
*/
235+
readonly testLine?: (...args: Args) => FixtureTestLine | undefined;
227236
}
228237

238+
/** What `FixtureOperation.testLine` writes in place of the arguments as given. */
239+
export type FixtureTestLine = { readonly args: string } | { readonly note: string };
240+
229241
/** Only declared async methods are recorded. Sync accessors pass through unchanged. */
230242
export type FixtureOperations<T extends object> = {
231243
readonly [Key in keyof T]?: T[Key] extends (...args: infer Args) => Promise<unknown>

0 commit comments

Comments
 (0)