Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0104f66
fix(desktop): give a located container the text its descendants show
kdy1 Nov 27, 2026
314aa97
fix(expect): poll again on a read the screen changed under, and time …
kdy1 Nov 27, 2026
2f79837
fix(desktop): tap the row or button a tapped text sits in
kdy1 Nov 27, 2026
ff514e6
fix(desktop): let an agent step follow a window it opens while one is…
kdy1 Nov 27, 2026
8e7f123
fix(agent): say in the type tool that a slider takes its number there
kdy1 Nov 27, 2026
0f5c96d
fix(desktop): open an app in the foreground only once it has a key wi…
kdy1 Nov 27, 2026
28fd58e
test(desktop): read a located list's text without its fold line
kdy1 Nov 27, 2026
838fdcd
feat(core): name the agent step on every operation it makes
kdy1 Nov 27, 2026
de5e65d
fix(desktop): follow an agent's new window within its step, replayed …
kdy1 Nov 27, 2026
97ffa63
fix(desktop): leave hidden nodes out of a container's text, and keep …
kdy1 Nov 27, 2026
80faca9
fix(expect): give the engine's reason when every read failed until th…
kdy1 Nov 27, 2026
41dcd83
fix(desktop): fail the key-window wait on a late cancel or an app tha…
kdy1 Nov 27, 2026
0bcb203
fix(desktop): open a row's menu from text in a cell that takes its ow…
kdy1 Nov 27, 2026
a3b7cc8
refactor(desktop): drop follow's empty-list branch, which no read rea…
kdy1 Nov 28, 2026
6e4c181
docs(desktop): say when keyWindow fails the open
kdy1 Nov 28, 2026
644625b
fix(desktop): measure a test's point from the active window after an …
kdy1 Nov 29, 2026
3f56a9a
fix(core): keep the engine's reason in reads that use only the node
kdy1 Nov 29, 2026
5c5ce6e
docs(core): name every step that stamps agentStep
kdy1 Nov 29, 2026
bc9aed3
docs(desktop): move container text, text taps, and agent following in…
kdy1 Nov 29, 2026
9122160
fix(desktop): read the text under a heading that has none of its own …
kdy1 Nov 29, 2026
860a15b
fix(desktop): follow a window the agent step opened once it takes focus
kdy1 Nov 29, 2026
b74a698
fix(desktop): open a row's menu from a secondary tap on a cell with n…
kdy1 Nov 29, 2026
d16acab
docs(desktop): put pointIn's comment back on pointIn
kdy1 Nov 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/agent-type-slider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@e2e-dev/core': patch
---

The agent's `type` tool now says that a slider or a spin button (stepper) takes its new number through it, so a model types `18` into a slider instead of clicking and pressing keys on it and giving up. It steps the control with arrow keys only when the value it shows then is not that number.
8 changes: 8 additions & 0 deletions .changeset/engine-agent-step.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@e2e-dev/core': patch
'e2e': patch
'@e2e-dev/web': patch
'@e2e-dev/mobile': patch
---

An engine operation now carries `agentStep`, an id of the agent step it belongs to (`agent.act`, `agent.assert` on a custom executor, or an `e2e mcp` session), on every operation of the step, replayed from the cache as well as live, where `origin` is `test`. An engine may scope state to one agent step with it; the desktop engine follows a window an agent step opened only within that step.
6 changes: 6 additions & 0 deletions .changeset/expect-stale-read.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'e2e': patch
'@e2e-dev/core': patch
---

An `expect` poll, `locator.waitFor`, and the other polling reads no longer fail with `node became stale` when the engine found the screen changing under every read until the deadline, as a SwiftUI app that re-creates its elements on each state change can make it. They sample again, and a timeout is the assertion's own `ASSERTION_FAILED` (or `waitFor`'s `LOCATOR_NOT_FOUND`), whose `observed` line gives the engine's own reason the last reads failed, such as a locked screen, and carries that error as its cause. Such a read never lets a negated assertion or `waitFor({ state: 'detached' })` pass.
22 changes: 22 additions & 0 deletions docs/reference/desktop.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@ expect(await main.isActive()).toBe(true);
stays open to ask about unsaved changes. Closing a window that already
closed does nothing.
- When the active window closes, `screen` reads the focused window again.
- With a window made active, an agent step that opens a window which takes
focus (Preferences, from a button it pressed) reads and acts there for the
rest of that step, replayed from the cache too, while that window is open.
The test's own steps, its coordinate taps included, stay on the active
window, and the next agent step starts from it again.
- The Siri dialog macOS 27 can put over an app is read only when a test makes
it active.
- Windows on another macOS Space stay readable.
Expand All @@ -417,6 +422,10 @@ background, like document-based apps, need `--headed` or
sent.
- A box that already shows the state `check` or `uncheck` asks for is left
alone.
- A tap or `secondaryTap` on static text or an image goes to the row or
button it sits in, as a click on text does on the web: up to three levels
up, never past a list, a scroll area, another control, or the window. Text
with no such row or button around it is refused with `ACTION_FAILED`.
- A tap, secondary tap, `check`, or `uncheck` on a hidden node scrolls it
into view first, or is refused. A failure after that scroll fails with
`ACTION_FAILED` as an action that may have taken effect, and is never
Expand All @@ -437,6 +446,9 @@ real pointer. Keys and typing then use the real keyboard.
there.
- Once a double-click's first click goes, the second follows at once,
whatever the first opened.
- In the foreground, `app.open()` also waits up to 2 seconds for the app to
have a key window, so the first keys of a `pressSequentially` right after
it reach the app.
- Two desktop targets run at the same time. With `physicalInput: true` they
would share the pointer and keyboard, so set `workers: 1`.

Expand Down Expand Up @@ -513,6 +525,11 @@ A read is one snapshot of the active window. Sheets and open context,
pop-up, and toolbar menus are included, so `getByRole('menuitem', 'Copy')`
finds a menu's items. Window chrome (Close, Minimize, Zoom) is left out.

- `textContent()`, `toHaveText`, and `toContainText` on a list, a tree, a
group, or a row read the text its rows and labels show, and the names of
the controls in it (a button's name is its text, even an icon's label), one
line each, leaving out what is hidden. A text field's value is not part of
it, as on the web.
- An element accessibility lists under two parents is read once, where it is
first found. A SwiftUI toolbar `Menu` lists its open menu under the button
and beside it, so its items match once.
Expand Down Expand Up @@ -545,6 +562,7 @@ Roles use the names the web uses: `textbox`, `checkbox`, `combobox`,
| Text field | `textbox` |
| Radio button | `radio` |
| Disclosure control, menu button | `button` |
| Tab of a SwiftUI `TabView` or an AppKit tab view | `tab`, in a `tablist`, so `getByRole('tab', 'Advanced').tap()` switches to it |
| Sheet, popover | `dialog` |
| Outline | `tree` |
| Stepper (incrementor) | `spinbutton` |
Expand Down Expand Up @@ -605,6 +623,10 @@ its own, such as a `.e2e` suffix.
containers, or the Keychain.
- A session saves the defaults domain only. A test that uses it starts from
a cleared app with those defaults.
- An installed app keeps its data between runs. A document app such as
TextEdit keeps the unsaved documents of a run that was killed, so a new
document's title (`Untitled 3`) can change from run to run: don't match a
window by that title.

| Throws | When |
| --- | --- |
Expand Down
10 changes: 10 additions & 0 deletions docs/reference/engine.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ export interface OperationContext {
readonly runId: string;
readonly attemptId: string;
readonly origin: 'test' | 'agent';
/**
* The agent step this operation belongs to, an id unique within the
* attempt, on every operation of a step the harness dispatches to an
* executor: `agent.act`, `agent.assert` on a custom executor, and the live
* session of `e2e mcp`, replayed from the cache as well as live. Absent on
* a test's own operations and on a judgment (`waitFor`, `extract`, and the
* built-in agent's `agent.assert`). An engine may scope state to one agent
* step with it, since `origin` is `test` while a step replays.
*/
readonly agentStep?: string;
}
```

Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/agent/primitives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,13 @@ export function grammarTools(
// tap_at gave it focus, and how a key reaches a screen with no node to aim at.
const focused = verbs.has('typeText');
if (verbs.has('type') || focused) {
// A model that read only "input node" tried clicks and arrow keys on a slider and gave up; a value control takes its number here.
const valueControls =
' A slider or spin button (stepper) takes its new number the same way: type e.g. "18" into it with target rather than dragging it or stepping it with keys; step it with arrow keys only if the value it shows then is not that number.';
tools['type'] = screenTool({
description: focused
? 'Type a plain-text value into one input node, or into whatever has focus when target is omitted. With target the value replaces the node\'s value. After tap_at on a field the screen does not list, call type with NO target (not the document or a container id): the value is inserted at the caret of the focused field; set replace to clear it first. Several fields can be typed in one turn.'
: 'Type a plain-text value into one input node, replacing its current value. Several fields can be typed in one turn.',
? `Type a plain-text value into one input node, or into whatever has focus when target is omitted. With target the value replaces the node's value.${valueControls} After tap_at on a field the screen does not list, call type with NO target (not the document or a container id): the value is inserted at the caret of the focused field; set replace to clear it first. Several fields can be typed in one turn.`
: `Type a plain-text value into one input node, replacing its current value.${valueControls} Several fields can be typed in one turn.`,
inputSchema: z.object({
target: verbs.has('type') && focused ? target.optional() : verbs.has('type') ? target : z.undefined().optional(),
value: z.string(),
Expand Down
12 changes: 10 additions & 2 deletions packages/core/src/agent/step-accounting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export interface StepAccountingOptions {
readonly callSignal?: () => AbortSignal;
}

/** The last `agentStep` handed out in this process. */
let nextStepId = 0;

export class StepAccounting {
readonly api: string;
readonly timeoutMs: number;
Expand Down Expand Up @@ -75,6 +78,8 @@ export class StepAccounting {
private modelId: string | undefined;
/** Whether the step is replaying a recorded trace: its actions are then a test's, not the model's. */
private inReplay = false;
/** This step's `agentStep`, on every operation it makes. */
private readonly stepId = String((nextStepId += 1));

constructor(
private readonly runtime: AgentContext,
Expand Down Expand Up @@ -213,9 +218,12 @@ export class StepAccounting {
);
}

/** Every operation inside a replayed span is the test's, navigation included; outside it, the agent's. */
/**
* Every operation inside a replayed span is the test's, navigation
* included; outside it, the agent's. Both carry the step's `agentStep`.
*/
private stamped(operation: OperationContext): OperationContext {
return this.inReplay ? { ...operation, origin: 'test' } : operation;
return { ...operation, agentStep: this.stepId, ...(this.inReplay ? { origin: 'test' as const } : {}) };
}

/** Marks the span in which the step's actions come from a recorded trace rather than the model. */
Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/engine/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ export interface OperationContext {
* transition to end first.
*/
readonly origin: 'test' | 'agent';
/**
* The agent step this operation belongs to, an id unique within the
* attempt, on every operation of a step the harness dispatches to an
* executor: `agent.act`, `agent.assert` on a custom executor, and the live
* session of `e2e mcp`, replayed from the cache as well as live. Absent on
* a test's own operations and on a judgment (`waitFor`, `extract`, and the
* built-in agent's `agent.assert`). An engine may scope state to one agent
* step with it, since `origin` is `test` while a step replays.
*/
readonly agentStep?: string;
}

export type TextPattern =
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/engine/protocol/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ function encodeOperation(link: Link, operation: OperationContext): WireOperation
runId: operation.runId,
attemptId: operation.attemptId,
origin: operation.origin,
...(operation.agentStep === undefined ? {} : { agentStep: operation.agentStep }),
};
}

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/engine/protocol/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export interface WireOperation {
readonly runId: string;
readonly attemptId: string;
readonly origin: 'test' | 'agent';
readonly agentStep?: string;
}

/** `EngineCleanupContext` on the wire. */
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/engine/protocol/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ class EngineServer {
runId: wire.runId,
attemptId: wire.attemptId,
origin: wire.origin,
...(typeof wire.agentStep === 'string' ? { agentStep: wire.agentStep } : {}),
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/locator/element-screenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function captureMatch(
let kept: string | undefined;
let missing = `locator did not become visible with a box to capture: ${shown}`;
const boxOf = async (reads: ReadWindow): Promise<Box | undefined> => {
const { node } = await engine.tryRead(expression, reads);
const node = await engine.readNode(expression, reads);
return isNodeVisible(node) ? node.rect : undefined;
};
const viewportOf = async (reads: ReadWindow): Promise<ViewportSize> =>
Expand Down
87 changes: 74 additions & 13 deletions packages/core/src/locator/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,16 +439,34 @@ if (sampled && reads.cutOff(cause)) throw await notFound(cause);
* Reads one node for polling surfaces; returns null while zero matches.
* A poll that waits for absence passes `missingFrame: 'empty'`: nothing
* under a frame that is not in the document is attached, so the sample is
* zero matches rather than a wait for the frame. A ref that went stale
* before it was read is `stale`, one match with no node: a poll for
* absence samples again instead of reading the node as gone.
* zero matches rather than a wait for the frame. A read the engine found
* stale until the window's deadline (an app that re-created its elements
* under every read), or a ref superseded before it was read, is no node
* with `stale` set (one match for the superseded ref, none for a resolve
* that never answered) and the engine's failure as `cause`: the poll
* samples again, and its timeout is its own failure, never a gone node,
* whose reason is that cause's (`staleReason`).
*/
async tryRead(
expression: LocatorExpression,
reads: ReadWindow,
missingFrame: MissingFrame = 'wait',
): Promise<{ node: SemanticNode | null; count: number; stale: boolean }> {
return this.readOne(expression, reads, missingFrame);
): Promise<StaleableRead> {
try {
return await this.readOne(expression, reads, missingFrame);
} catch (cause) {
if (isStaleRead(cause)) return { node: null, count: 0, stale: true, cause: staleCause(cause) };
throw cause;
}
}

/**
* The one current match, for a caller that reads only the node: a read the
* engine found stale until the window's deadline throws its error, unlike
* `tryRead`, so the caller's poll keeps it as the cause of its timeout.
*/
async readNode(expression: LocatorExpression, reads: ReadWindow, missingFrame: MissingFrame = 'wait'): Promise<SemanticNode | null> {
return (await this.readOne(expression, reads, missingFrame)).node;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}

/**
Expand All @@ -463,22 +481,23 @@ if (sampled && reads.cutOff(cause)) throw await notFound(cause);
async readViewport(
expression: LocatorExpression,
reads: ReadWindow,
): Promise<{ node: SemanticNode | null; count: number; stale: boolean; intersection?: ViewportIntersection }> {
): Promise<StaleableRead & { intersection?: ViewportIntersection }> {
if (!this.session.measuresViewport) {
throw new ConfigurationError(
'UNSUPPORTED_CAPABILITY',
'toBeInViewport is not available on this target: its engine does not implement viewportIntersection',
);
}
const { node, count, stale } = await this.readOne(expression, reads, 'empty');
if (node === null) return { node, count, stale };
const read = await this.tryRead(expression, reads, 'empty');
const { node, count, stale } = read;
if (stale || node === null) return read;
try {
const intersection = await reads.read((timeoutMs) =>
this.session.viewportIntersection(node.ref, this.readOperation(timeoutMs)),
);
return { node, count, stale, intersection };
} catch (cause) {
if (asEngineError(cause)?.code === 'NODE_STALE') return { node, count, stale: true };
if (asEngineError(cause)?.code === 'NODE_STALE') return { node, count, stale: true, cause };
throw translateLocatorError(cause, expression);
}
}
Expand All @@ -502,15 +521,15 @@ if (sampled && reads.cutOff(cause)) throw await notFound(cause);
expression: LocatorExpression,
reads: ReadWindow,
missingFrame: MissingFrame,
): Promise<{ node: SemanticNode | null; count: number; stale: boolean }> {
const ref = await this.singleOf(await this.resolveOnce(expression, reads, missingFrame), expression);
): Promise<StaleableRead> {
const ref = await this.singleOf(await this.resolveOnce(expression, reads, missingFrame), expression);
if (ref === null) return { node: null, count: 0, stale: false };
try {
const node = await reads.read((timeoutMs) => this.session.read(ref, this.readOperation(timeoutMs)));
return { node, count: 1, stale: false };
} catch (cause) {
if (asEngineError(cause)?.code === 'NODE_STALE') {
return { node: null, count: 1, stale: true };
return { node: null, count: 1, stale: true, cause };
}
throw translateLocatorError(cause, expression);
}
Expand Down Expand Up @@ -686,7 +705,7 @@ const ref = await this.singleOf(await this.resolveOnce(expression, reads, missin
evaluate: async (reads) => {
// A box read at the deadline could never be tapped: skip the read so the wait ends as LOCATOR_NOT_FOUND.
if (deadline.expired()) return false;
const { node } = await this.tryRead(expression, reads);
const node = await this.readNode(expression, reads);
if (!isNodeVisible(node) || node.rect === undefined) return false;
origin = node.origin ?? node.rect;
return true;
Expand Down Expand Up @@ -909,6 +928,48 @@ function lateAction(kind: string, target: string): TestError {
return new TestError('ACTION_FAILED', `operation timed out before the ${kind} was sent: ${target}`);
}

/** One read of a polling surface: the node, how many matched, and, for a read the screen changed under, the engine's failure. */
export interface StaleableRead {
readonly node: SemanticNode | null;
readonly count: number;
readonly stale: boolean;
/** The engine's `NODE_STALE` that made the read `stale`: why it could not read (`staleReason`). */
readonly cause?: unknown;
}

/**
* The engine's own `NODE_STALE` in a stale read's failure, bare or under the
* locator failure a resolve translated it into; else the failure itself.
*/
export function staleCause(cause: unknown): unknown {
if (asEngineError(cause)?.code === 'NODE_STALE') return cause;
const inner = isE2EError(cause) ? cause.cause : undefined;
return asEngineError(inner)?.code === 'NODE_STALE' ? inner : cause;
}

/**
* Why a stale read could not read, from the engine's own `NODE_STALE`: "the
* Mac's screen is locked", or an app that re-created its elements. Undefined
* when the failure is no such error.
*/
export function staleReason(cause: unknown): string | undefined {
const engineError = asEngineError(staleCause(cause));
return engineError?.code === 'NODE_STALE' ? engineError.message : undefined;
}

/**
* Whether a failure is a read the engine found stale: a retryable
* `NODE_STALE`, bare or as the locator failure it was translated into once a
* resolve retried it until its deadline. A poll samples again on one.
*/
export function isStaleRead(cause: unknown): boolean {
const stale = (value: unknown): boolean => {
const engineError = asEngineError(value);
return engineError?.code === 'NODE_STALE' && engineError.retryable;
};
return stale(cause) || (isE2EError(cause) && cause.code === 'LOCATOR_NOT_FOUND' && stale(cause.cause));
}

/** Translates an engine error into the runner-owned public taxonomy. */
export function translateLocatorError(cause: unknown, expression?: LocatorExpression): E2EError {
const suffix = expression === undefined ? '' : `: ${describeExpression(expression)}`;
Expand Down
Loading
Loading