Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
95 changes: 65 additions & 30 deletions packages/provider-limrun/src/ios-interactor-text-entry.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, test, vi } from 'vitest';
import { afterEach, expect, test, vi } from 'vitest';
import { createLimrunIosInteractor, type LimrunIosSession } from './ios.ts';
import type { IosTreeNode } from './snapshot.ts';

Expand All @@ -16,6 +16,10 @@ function emailField(editing: boolean): IosTreeNode {
};
}

afterEach(() => {
vi.restoreAllMocks();
});

function sessionWithTrees(trees: IosTreeNode[]) {
const calls: string[] = [];
let reads = 0;
Expand All @@ -35,6 +39,9 @@ function sessionWithTrees(trees: IosTreeNode[]) {
typeText: vi.fn(async () => {
calls.push('typeText');
}),
setElementValue: vi.fn(async () => {
calls.push('setElementValue');
}),
};
const session = {
platform: 'ios',
Expand Down Expand Up @@ -64,7 +71,7 @@ test('a delayed type sends one focused-blind key press per character', async ()
]);
});

test('fill waits for text-entry focus to arrive and only then sends keys', async () => {
test('fill waits for text-entry focus to arrive and only then sets the value', async () => {
const { interactor, client, calls } = sessionWithTrees([
emailField(false),
emailField(false),
Expand All @@ -73,40 +80,30 @@ test('fill waits for text-entry focus to arrive and only then sends keys', async

const result = await interactor.fill(200, 170, 'qa@example.com');

expect(calls).toEqual([
'elementTree',
'tap',
'elementTree',
'elementTree',
'pressKey:a+command',
'typeText',
]);
expect(calls).toEqual(['elementTree', 'tap', 'elementTree', 'elementTree', 'setElementValue']);
expect(result).toEqual({ textEntryReadiness: 'focused-element' });
expect(client.typeText).toHaveBeenCalledWith('qa@example.com', false, { requireFocus: false });
});

test('fill selects the field value first, so entry replaces it', async () => {
const { interactor, calls } = sessionWithTrees([emailField(false), emailField(true)]);

await interactor.fill(200, 170, 'replacement');

expect(calls.indexOf('pressKey:a+command')).toBeLessThan(calls.indexOf('typeText'));
expect(client.setElementValue.mock.calls).toEqual([['qa@example.com']]);
expect(client.pressKey).not.toHaveBeenCalled();
expect(client.typeText).not.toHaveBeenCalled();
});

test('the clear request empties the focused field instead of typing nothing', async () => {
const { interactor, client, calls } = sessionWithTrees([emailField(false), emailField(true)]);
test.each([
['你好', undefined],
['qa@例子.com', undefined],
['👋', undefined],
['replacement', undefined],
['', undefined],
['你好a', 1],
['', 1],
])('fill writes %s once with delay %s', async (text, delayMs) => {
const { interactor, client } = sessionWithTrees([emailField(false), emailField(true)]);

const result = await interactor.fill(200, 170, '');
const result = await interactor.fill(200, 170, text, delayMs);

expect(calls).toEqual([
'elementTree',
'tap',
'elementTree',
'pressKey:a+command',
'pressKey:delete',
]);
expect(client.typeText).not.toHaveBeenCalled();
expect(result).toEqual({ textEntryReadiness: 'focused-element' });
expect(client.setElementValue.mock.calls).toEqual([[text]]);
expect(client.pressKey).not.toHaveBeenCalled();
expect(client.typeText).not.toHaveBeenCalled();
});

test('a session that cannot answer the focus read fails before the device is touched', async () => {
Expand All @@ -121,5 +118,43 @@ test('a session that cannot answer the focus read fails before the device is tou
);
expect(calls).toEqual(['elementTree']);
expect(client.tap).not.toHaveBeenCalled();
expect(client.setElementValue).not.toHaveBeenCalled();
expect(client.pressKey).not.toHaveBeenCalled();
expect(client.typeText).not.toHaveBeenCalled();
});

test('fill writes no value when text-entry focus never arrives', async () => {
const { interactor, client } = sessionWithTrees([emailField(false)]);
// The focus budget is wall-clock time. Step the clock by that budget on every
// read so the first miss expires it, and the refusal is not a three-second wait.
let now = 0;
vi.spyOn(Date, 'now').mockImplementation(() => {
const current = now;
now += 3_000;
return current;
});

await expect(interactor.fill(200, 170, '你好')).rejects.toMatchObject({
code: 'COMMAND_FAILED',
details: { reason: 'text_entry_focus_not_observed' },
});
expect(client.tap).toHaveBeenCalledTimes(1);
expect(client.setElementValue).not.toHaveBeenCalled();
expect(client.pressKey).not.toHaveBeenCalled();
expect(client.typeText).not.toHaveBeenCalled();
});

test('a rejected value write fails the fill with that failure', async () => {
const { interactor, client } = sessionWithTrees([emailField(false), emailField(true)]);
const failure = new Error('element value refused');
client.setElementValue.mockRejectedValueOnce(failure);

await expect(interactor.fill(200, 170, '你好')).rejects.toMatchObject({
code: 'COMMAND_FAILED',
details: { reason: 'text_entry_value_write_failed', dispatched: 'unknown' },
cause: failure,
});
expect(client.setElementValue.mock.calls).toEqual([['你好']]);
expect(client.pressKey).not.toHaveBeenCalled();
expect(client.typeText).not.toHaveBeenCalled();
});
24 changes: 16 additions & 8 deletions packages/provider-limrun/src/ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class LimrunIosInteractor implements Interactor {
await this.enterText(text, delayMs);
}

async fill(x: number, y: number, text: string, delayMs?: number): Promise<FillBackendResult> {
async fill(x: number, y: number, text: string, _delayMs?: number): Promise<FillBackendResult> {
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
// Loaded on the fill path to keep this provider's declared import-time closure budget.
const { awaitLimrunTextEntryFocus, readLimrunUnambiguousTapTargets, readLimrunTextEntryFocus } =
await import('./text-entry-focus.ts');
Expand All @@ -295,14 +295,22 @@ class LimrunIosInteractor implements Interactor {
x,
y,
});
// Select first: iOS replaces a selection on the next key, so `fill` replaces and
// an empty fill clears.
await this.session.client.pressKey('a', ['command']);
if (text.length === 0) {
await this.session.client.pressKey('delete');
return { textEntryReadiness };
// Omitting the selector lets the server resolve focus.
try {
await this.session.client.setElementValue(text);
} catch (error) {
if (error instanceof AppError) throw error;
throw new AppError(
'COMMAND_FAILED',
'Limrun could not write the focused field value.',
{
reason: 'text_entry_value_write_failed',
dispatched: 'unknown',
hint: 'Inspect and assert the field or resulting screen before continuing. If the value needs correction, retry fill with the full desired value. To append with key events, focus the field with press, then use type.',
},
error,
);
}
await this.enterText(text, delayMs);
return { textEntryReadiness };
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/schema/cli-help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Selectors:
Text entry:
fill replaces; type appends to an already-focused field: fill 'id="field-email"' "qa@example.com"; type "Handle with care" --delay-ms 80
fill <target> "" clears the field (replace with nothing); the empty argument must be present -- fill <target> alone is a missing argument.
Plain fill/type first; if an iOS debounced/search-as-you-type field drops characters, retry with --delay-ms before clipboard paste.
For dropped iOS text, retry with --delay-ms before clipboard paste. Limrun iOS: fill ignores --delay-ms; type supports delayed key events.
Element presses behind the keyboard are refused with tap_keyboard_occludes_target. keyboard dismiss taps its own dismiss key when one exists, else UNSUPPORTED_OPERATION. Android: try dismiss before back. iOS: when both fail, do not tap a static text/heading hoping it is safe; prefer type "\\n" to submit.
iOS paste-prompt limits and Android IME/handwriting capture quirks: help debugging.

Expand Down
10 changes: 6 additions & 4 deletions website/docs/docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,8 @@ agent-device alert dismiss
agent-device click @e1
agent-device click @e1 --button secondary # macOS secondary click / context menu
agent-device focus @e2
agent-device fill @e2 "text" # Clear then type
agent-device fill @e2 "search" --delay-ms 100
agent-device fill @e2 "text" # Replace the field value
agent-device fill @e2 "search" --delay-ms 100 # No delay on Limrun iOS fill
printf %s "$PASSWORD" | agent-device fill @e2 --text-stdin # Text from stdin, kept out of argv
agent-device type "text" # Type into focused field without clearing
agent-device type "query" --delay-ms 100
Expand Down Expand Up @@ -487,14 +487,16 @@ A `click` or `press` whose target the daemon resolves to a point (`@ref` or sele

### Text entry

- `fill` clears then types. `type` appends to the focused field and accepts text only: use `fill @ref "text"` to target a field, or `press @ref` then `type "text"`.
- Use plain `fill` or `type` first. Add `--delay-ms` only when a debounced or search-as-you-type field misses characters, or the app must receive each incremental update; delayed typing enters characters one at a time instead of using a clipboard-style fallback.
- `fill` replaces the field value. `type` appends to the focused field and accepts text only: use `fill @ref "text"` to target a field, or `press @ref` then `type "text"`.
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
- Use plain `fill` or `type` first. Add `--delay-ms` only when a debounced or search-as-you-type field misses characters, or the app must receive each incremental update; delayed typing enters characters one at a time instead of using a clipboard-style fallback. On Limrun iOS, `--delay-ms` has no effect on `fill`; use `press` to focus the field and `type --delay-ms` for intentional key-event input.
- `fill --text-stdin` reads the text from stdin so a secret never appears in process arguments. Pipe it with `printf %s`. It reads at most 64 KiB, removes one trailing newline, and refuses a terminal, empty input, invalid UTF-8, or an extra text argument. Output shows the value as `${VAR}` with `--record-as <VAR>` and as `[REDACTED]` otherwise, including in error messages and details, and in the `requested`, `before`, and `after` read-back of an unconfirmed fill, which can hold a reformatted form of the value. With `--settle`, the diff line text and tail labels are replaced whole, so text around the value in the field is not shown either; refs and counts stay. While script recording is armed, pass `--record-as <VAR>` or `--no-record`; passing neither is an error. Batch steps don't accept it.
- The privacy controls for typed input (`--text-stdin` and `--record-as`) keep the literal out of agent-device's own responses, diagnostics, and recorded scripts. They do not rewrite what the platform records: on iOS, XCTest writes its own diagnostic logs and its `.xcresult` bundle, and typed text can appear in both, on a simulator or a physical device. Treat those as sensitive, and use test-only credentials when they may be kept or shared. See [Security and trust](/docs/security-trust).
- Android text entry is owned by `agent-device`. Don't fall back to raw `adb`, clipboard, or paste; if non-ASCII is unsupported on the current backend, report the gap. Android `fill` verifies the text and fails instead of retrying when the IME captures input.

Text-entry errors and what to do:

- `text_entry_focus_not_observed` (Limrun iOS `fill`): the tap did not establish focus on the target, so no value was written. Run `snapshot -i` and choose the input again.
- `text_entry_value_write_failed` (Limrun iOS `fill`): the write outcome is unknown. Inspect and assert the field or resulting screen before continuing. Retry `fill` with the full value only if it needs correction. See [Limrun iOS text entry](/docs/limrun).
- `TEXT_INPUT_NOT_FOCUSED` (`type`): focus a visible text input and retry. If accessibility does not expose the input, focus it by coordinates.
- `NO_TEXT_INPUT_AT_POINT` (iOS `fill` under a degraded XCTest channel — coordinate, ref, selector, and replay fills all aim at a point): the runner identified no text input under that point and refused before dispatching anything (`error.details.reason` is `no_text_input_at_point`, `dispatched: no`), so no field changed. A ref or selector fill aims at the centre of the rect it resolved to, so an outer container or a non-input node can land outside the real field: run `snapshot -i`, pick the input node itself, and aim inside its rect.
- `TEXT_INPUT_PROBE_UNAVAILABLE` (iOS `fill` under a degraded XCTest channel — coordinate, ref, selector, and replay fills all aim at a point): the runner's input lookup could not answer, so it refused before dispatching anything (`error.details.reason` is `text_input_probe_unavailable`, `dispatched: no`). This does not mean the point has no input. Retry the fill, or run `snapshot -i` once its capture reads back. A ref or selector fill aims at the centre of its resolved rect.
Expand Down
2 changes: 1 addition & 1 deletion website/docs/docs/limrun.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ On an iPhone, Limrun reports a native tab bar as one empty group. `snapshot` the

On iOS, `settings` supports `appearance`, `permission`, `location`, and `clear-app-state`, with the same arguments as a local simulator. `clear-app-state` resets the app's data container through Limrun's soft reset. That reset relaunches the app once before agent-device stops it, so the app may run once after its data is cleared. `reset-keychain`, `wifi`, `airplane`, `mobile-data`, `faceid`, `touchid`, and `text-size` are unsupported, and you cannot read back any iOS setting. On Android, `settings mobile-data on|off` runs over the ADB tunnel like on a local device.

On iOS, `fill` taps the target, waits for that field to take text-entry focus, and only then types. Apps that never report a globally focused element, such as Flutter forms, still fill and report `textEntryReadiness: "focused-element"`. If the tap does not focus a field, `fill` fails with `text_entry_focus_not_observed` instead of typing into an unknown field. Use `type` to send text to whichever field already has focus.
On iOS, `fill` taps the target, waits for that field to take text-entry focus, and replaces the focused field's value in one write. The write is the complete text, including an empty string that clears the field and characters that have no hardware key. It does not send key events, so key-event handlers may not run. Some apps, including Flutter forms, do not expose a globally focused element to Limrun. In those apps, `fill` can fail with `text_entry_value_write_failed` after focus is observed. The write outcome is unknown. Inspect and assert the field or resulting screen before continuing. If the value needs correction, retry `fill` with the full desired value. To append with key events, use `press` to focus the field, then `type`. If the tap does not focus a field, `fill` fails with `text_entry_focus_not_observed` and writes nothing. `type` sends key events to whichever field already has focus. `--delay-ms` on `type` enters one character at a time; `--delay-ms` has no effect on `fill`.

To drive Limrun only through MCP, see [Use a provider only through MCP](/docs/device-clouds#use-a-provider-only-through-mcp). For Limrun, `artifacts` lists the network capture file only when you connect with `--provider-network-logs`; otherwise there are no provider artifacts to fetch.

Expand Down
Loading