Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
4dcc351
fix(ios): keyboard dismiss never presses the return key
thymikee Nov 17, 2026
8314201
fix(mcp): drop the keyboard search keyword its description now carries
thymikee Nov 17, 2026
a0931e2
refactor(runner): share the keyboard fixture field layout
thymikee Nov 17, 2026
fe84759
fix(ios): convert iOS return-key-only dismiss routes to keyboard enter
thymikee Nov 17, 2026
1831b06
fix(ios): read the dismiss lookup's keyboard keys from one snapshot
thymikee Nov 17, 2026
5027d82
fix(ios): keyboard dismiss fails closed when it cannot tell the retur…
thymikee Nov 17, 2026
1382109
fix(ios): keep dismiss controls near the keyboard and tap only inside…
thymikee Nov 17, 2026
1950b8e
fix(ios): drop the stale dismissControl overload
thymikee Nov 17, 2026
442045d
test(runner): give the iPad dismiss fixture an iPad keyboard frame
thymikee Nov 17, 2026
caf095a
fix(ios): tap the dismiss control by identity and anchor key rows on …
thymikee Nov 17, 2026
4e6fca1
fix(ios): decide dismiss from one app snapshot and try each eligible …
thymikee Nov 17, 2026
0ef27cb
fix(ios): tap only a hittable dismiss control and treat a missing ide…
thymikee Nov 17, 2026
a16c5ae
fix(ios): count only near-keyboard controls when telling a dismiss co…
thymikee Nov 17, 2026
82b24c6
fix(ios): look each dismiss control up inside its own container, exac…
thymikee Nov 17, 2026
12c81e1
refactor(ios): judge dismiss controls by where they sit and name an u…
thymikee Nov 17, 2026
8f0bbf7
test(runner): cover the dismiss cause in the error payload encoder co…
thymikee Nov 17, 2026
4c0b069
fix(ios): treat an app snapshot without a keyboard as an unreadable tree
thymikee Nov 17, 2026
1462f25
fix(ios): blame an unreadable tree only when the fallback held no dis…
thymikee Nov 17, 2026
5a1b7c0
fix(perf): keep the keyboard step id so its baseline history survives
thymikee Nov 17, 2026
5417b02
docs(keyboard): say which dismiss controls still work without a reada…
thymikee Nov 17, 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
2 changes: 1 addition & 1 deletion .github/workflows/perf-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ jobs:
env:
UDID: ${{ steps.ios-simulator.outputs.simulator-udid }}
run: |
# The keyboard must stay expanded for keyboard dismiss to find its Done key.
# The keyboard must stay expanded for the form step to find the return key labelled Done.
xcrun simctl spawn "$UDID" defaults write com.apple.keyboard.preferences AutomaticMinimizationEnabled -bool false
pnpm clean:daemon
node bin/agent-device.mjs prepare ios-runner --platform ios --udid "$UDID" --timeout "$AGENT_DEVICE_IOS_PREPARE_TIMEOUT_MS"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,23 @@ - (void)stopAlertActivationBusy {
self.alertActivationBusyBackstop = nil;
}

// Places a keyboard fixture's field below `above`, and the label that answers what its controls did
// below the field.
static void AgentDeviceAddKeyboardFieldWithAnswer(UIView *view, UITextField *field, UILabel *answer, UIView *above) {
field.translatesAutoresizingMaskIntoConstraints = NO;
answer.translatesAutoresizingMaskIntoConstraints = NO;
[view addSubview:field];
[view addSubview:answer];
[NSLayoutConstraint activateConstraints:@[
[field.centerXAnchor constraintEqualToAnchor:view.centerXAnchor],
[field.topAnchor constraintEqualToAnchor:above.bottomAnchor constant:24],
[field.widthAnchor constraintEqualToConstant:240],
[field.heightAnchor constraintEqualToConstant:44],
[answer.centerXAnchor constraintEqualToAnchor:view.centerXAnchor],
[answer.topAnchor constraintEqualToAnchor:field.bottomAnchor constant:12],
]];
}

// The keyboard counterpart of the busy alert: the field starts the same never-ending UIView animation
// when it takes focus, so XCTest sees work in flight for as long as the keyboard is up. Its Done
// accessory and its return key record whether they landed while the app was still busy. The backstop
Expand Down Expand Up @@ -928,25 +945,106 @@ - (void)viewDidLoad {
[field addTarget:self
action:@selector(keyboardBusyReturnPressed)
forControlEvents:UIControlEventEditingDidEndOnExit];
field.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:field];
UILabel *answer = [[UILabel alloc] init];
answer.text = @"Unanswered";
answer.accessibilityIdentifier = @"agent-device-keyboard-busy-answer";
answer.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:answer];
[NSLayoutConstraint activateConstraints:@[
[field.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor],
[field.topAnchor constraintEqualToAnchor:label.bottomAnchor constant:24],
[field.widthAnchor constraintEqualToConstant:240],
[field.heightAnchor constraintEqualToConstant:44],
[answer.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor],
[answer.topAnchor constraintEqualToAnchor:field.bottomAnchor constant:12],
]];
AgentDeviceAddKeyboardFieldWithAnswer(self.view, field, answer, label);
self.keyboardBusyField = field;
self.keyboardBusyAnswer = answer;
}

// A field whose return key reads "Done" and submits, which `keyboard dismiss` must never press. The
// optional `accessory` argument adds a Done toolbar above the keys, the one control it may press.
NSArray<NSString *> *launchArguments = NSProcessInfo.processInfo.arguments;
NSUInteger doneReturnFlag = [launchArguments indexOfObject:@"--agent-device-keyboard-done-return"];
if (doneReturnFlag != NSNotFound) {
NSString *accessoryShape = doneReturnFlag + 1 < launchArguments.count ? launchArguments[doneReturnFlag + 1] : @"";
BOOL plainAccessory = [accessoryShape isEqualToString:@"plain-accessory"];
BOOL withAccessory = plainAccessory || [accessoryShape isEqualToString:@"accessory"];
UITextField *field = [[UITextField alloc] init];
field.accessibilityIdentifier = @"agent-device-keyboard-done-return-input";
field.placeholder = @"Return key is Done";
field.borderStyle = UITextBorderStyleRoundedRect;
field.returnKeyType = UIReturnKeyDone;
UILabel *answer = [[UILabel alloc] init];
answer.text = @"Unanswered";
answer.accessibilityIdentifier = @"agent-device-keyboard-done-return-answer";
__weak UITextField *weakField = field;
__weak UILabel *weakAnswer = answer;
[field addAction:[UIAction actionWithHandler:^(__kindof UIAction *action) {
weakAnswer.text = @"Submitted";
[weakField resignFirstResponder];
}]
forControlEvents:UIControlEventEditingDidEndOnExit];
if (plainAccessory) {
// An accessory that is no toolbar: a plain view holding a button, as a custom or React Native
// input accessory is.
UIView *accessory = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
accessory.backgroundColor = UIColor.systemGray5Color;
UIButton *accessoryDone = [UIButton buttonWithType:UIButtonTypeSystem];
[accessoryDone setTitle:@"Done" forState:UIControlStateNormal];
accessoryDone.frame = CGRectMake(240, 0, 70, 44);
[accessoryDone addAction:[UIAction actionWithHandler:^(__kindof UIAction *action) {
weakAnswer.text = @"Accessory";
[weakField resignFirstResponder];
}]
forControlEvents:UIControlEventTouchUpInside];
[accessory addSubview:accessoryDone];
field.inputAccessoryView = accessory;
} else if (withAccessory) {
UIToolbar *accessory = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
accessory.items = @[
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil],
[[UIBarButtonItem alloc]
initWithPrimaryAction:[UIAction actionWithTitle:@"Done"
image:nil
identifier:nil
handler:^(__kindof UIAction *action) {
weakAnswer.text = @"Accessory";
[weakField resignFirstResponder];
}]],
];
field.inputAccessoryView = accessory;
}
AgentDeviceAddKeyboardFieldWithAnswer(self.view, field, answer, label);
if (withAccessory) {
// A screen-level Done with the toolbar Done's label and no identifier, far from the keyboard, as a
// navigation bar's would be: dismiss must still press the toolbar's, never this one.
UIButton *screenDone = [UIButton buttonWithType:UIButtonTypeSystem];
[screenDone setTitle:@"Done" forState:UIControlStateNormal];
[screenDone addAction:[UIAction actionWithHandler:^(__kindof UIAction *action) {
weakAnswer.text = @"Screen";
}]
forControlEvents:UIControlEventTouchUpInside];
screenDone.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:screenDone];
[NSLayoutConstraint activateConstraints:@[
[screenDone.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor constant:8],
[screenDone.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor constant:-16],
]];
}
}

// A text field nested far deeper than XCTest's whole-app snapshot can read, so the keyboard's own
// snapshot is the only read that works while its field has focus.
if ([NSProcessInfo.processInfo.arguments containsObject:@"--agent-device-keyboard-deep-tree"]) {
UIView *parent = self.view;
for (NSUInteger depth = 0; depth < 70; depth++) {
UIView *group = [[UIView alloc] initWithFrame:parent.bounds];
group.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
group.accessibilityContainerType = UIAccessibilityContainerTypeSemanticGroup;
[parent addSubview:group];
parent = group;
}
UITextField *deepField = [[UITextField alloc] initWithFrame:CGRectMake(40, 140, 260, 44)];
deepField.accessibilityIdentifier = @"agent-device-keyboard-deep-input";
deepField.placeholder = @"Deep field";
deepField.borderStyle = UITextBorderStyleRoundedRect;
[parent addSubview:deepField];
}

if ([NSProcessInfo.processInfo.arguments containsObject:@"--agent-device-native-states"]) {
for (NSUInteger index = 0; index < 3; index++) {
UITextField *field = [[UITextField alloc] initWithFrame:CGRectMake(40, 120 + index * 60, 260, 44)];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@ extension RunnerKeyboardStatus {
struct ObservedKeyboardKey {
let text: String?
let frame: CGRect
/// The control's accessibility identifier, where the read carries it. A return key can show
/// `done` as its label and `Done` as its identifier, so dismiss matches either.
var identifier: String? = nil
/// Whether the tree carries the control as a key or as a button. Only keys are character keys: a
/// QuickType candidate or an accessory toolbar's control is a button, whatever its wording.
var kind: Kind = .key
enum Kind: Equatable {
case key
case button
}
}

/// One snapshot of the keyboard: its frame and every key's wording and frame, taken together so a
/// decision never mixes two reads of a keyboard that may be sliding. The dismiss read also carries,
/// as buttons, the dismiss-worded controls the app holds outside the keyboard, such as
/// an input accessory's `Done`, from the same snapshot.
struct ObservedKeyboard {
let frame: CGRect
let keys: [ObservedKeyboardKey]
}

/// What identifies Apple's space bar in the accessibility tree: wording that is whitespace and
Expand Down Expand Up @@ -91,13 +110,92 @@ extension RunnerKeyboardStatus {
guard visible else {
return RunnerKeyboardStatus(visible: false, returnKey: nil, returnKeyLabel: nil)
}
let worded = keyboardKeys.filter { key in
!(key.text ?? "").trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
return observed(visible: true, returnControlText: returnControl(in: keyboardKeys)?.text)
}

/// The top edge of the first row of character keys: the highest single-character control of key type.
/// It anchors where the key rows start, so a control wholly above it is an input accessory's, not a
/// key. A button never anchors, however short its wording: a QuickType candidate such as `I` or `A`
/// is a button above the key rows and would pull the anchor up to the prediction bar. `nil` when no
/// character key was read with wording and a frame, and then nothing can be placed relative to the
/// key rows.
static func characterKeyRowTop(in keys: [ObservedKeyboardKey]) -> CGFloat? {
keys
.filter {
$0.kind == .key && $0.text?.trimmingCharacters(in: .whitespacesAndNewlines).count == 1
&& !$0.frame.isEmpty
}
.map { $0.frame.minY }
.min()
}
Comment thread
thymikee marked this conversation as resolved.
Resolved

/// The one decision that a control is the visible keyboard's return key, by wording first and by
/// slot otherwise (see `observed(visible:keyboardKeys:)`). `keyboard status` reports it, and
/// `keyboard dismiss` presses nothing that could be it, so the two commands cannot disagree about
/// which key is the return key.
///
/// A wording match is the return key only when it is placed inside the key rows: below the top of
/// the first row of character keys. A control above that line is an input accessory's `Next` or
/// `Done`, and with no character key to anchor on, nothing can be placed, so no wording names it.
static func returnControl(in keys: [ObservedKeyboardKey]) -> ObservedKeyboardKey? {
let rowTop = characterKeyRowTop(in: keys)
let named = keys.first { key in
guard RunnerKeyboardReturnKey.kind(of: key.text ?? "") != .unknown, let rowTop else { return false }
return !key.frame.isEmpty && key.frame.maxY > rowTop
}
if let named = worded.first(where: { RunnerKeyboardReturnKey.kind(of: $0.text ?? "") != .unknown }) {
return observed(visible: true, returnControlText: named.text)
return named ?? returnKeySlot(in: keys)
}

/// Wording of the controls that only hide the keyboard. Neither can be a return key.
static let hideKeyboardLabels = ["Hide keyboard", "Dismiss keyboard"]

/// The dismiss controls `keyboard dismiss` may press, in the order it tries them.
static let dismissLabels = hideKeyboardLabels + ["Done"]

/// How far above the keyboard an accessory's button can sit and still belong to it.
static let accessoryReach: CGFloat = 80

/// True when `frame` belongs to the keyboard: it has a frame, it does not start below the keyboard,
/// and it is inside the keyboard or no more than `accessoryReach` above it. An app button with the
/// same wording elsewhere on screen is not the keyboard's.
static func isNearKeyboard(_ frame: CGRect, keyboardFrame: CGRect) -> Bool {
!frame.isEmpty && !keyboardFrame.isEmpty
&& frame.minY < keyboardFrame.maxY
&& keyboardFrame.minY - frame.maxY <= accessoryReach
}

/// Whether a refusal should say the screen could not be read: the app tree was unreadable and the
/// keyboard's own read, the only one left, held no dismiss candidate. A fallback that held a candidate
/// the live lookup then rejected, as covered or ambiguous, is a keyboard whose key could not be pressed,
/// which is a different cause.
static func refusalIsTreeUnreadable(treeReadable: Bool, surface: ObservedKeyboard?) -> Bool {
!treeReadable && (surface.map { dismissControls(in: $0).isEmpty } ?? true)
}

/// Every control `keyboard dismiss` may press, in dismiss-label order then tree order, all read from
/// one snapshot so no decision mixes two reads of a keyboard that may be sliding.
///
/// A candidate carries dismiss wording as its label or identifier and is near the keyboard. A
/// hide-keyboard control is never a return key. A `Done` is pressed only when it cannot be the return
/// key: wholly above the keyboard, which holds an input accessory of any shape, or inside the keyboard
/// and above the first row of character keys, which needs that row as an anchor and so fails closed
/// without one. A candidate whose type, label and identifier name another control near the keyboard is
/// left out, because a live lookup could not tell the two apart; a same-wording button far from the
/// keyboard, such as a header `Done`, does not count.
static func dismissControls(in keyboard: ObservedKeyboard) -> [ObservedKeyboardKey] {
let near = keyboard.keys.filter { isNearKeyboard($0.frame, keyboardFrame: keyboard.frame) }
let rowTop = characterKeyRowTop(in: keyboard.keys)
return dismissLabels.flatMap { label in
near.filter { key in
guard key.text == label || key.identifier == label else { return false }
let canBeReturnKey = !hideKeyboardLabels.contains(label)
&& key.frame.maxY > keyboard.frame.minY && key.frame.maxY > (rowTop ?? -.infinity)
let identity = near.filter {
$0.kind == key.kind && $0.text == key.text && ($0.identifier ?? "") == (key.identifier ?? "")
}
return !canBeReturnKey && identity.count == 1
}
}
return observed(visible: true, returnControlText: returnKeySlot(in: keyboardKeys)?.text)
}

/// The worded control in the return key's slot, or `nil` when the keyboard exposes no space bar to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,13 @@ extension RunnerTests {
return Response(ok: false, error: ErrorPayload(message: "keyboardDismiss produced no result"))
}
if result.wasVisible && !result.dismissed {
return Response(ok: false, error: keyboardDismissRefusal(dispatchedDismissal: result.dispatchedDismissal))
return Response(
ok: false,
error: keyboardDismissRefusal(
dispatchedDismissal: result.dispatchedDismissal,
treeUnreadable: result.treeUnreadable
)
)
}
return Response(
ok: true,
Expand Down
Loading
Loading