diff --git a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift index 03d14d5996..db80b6e462 100644 --- a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +++ b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift @@ -607,7 +607,9 @@ extension RunnerTests { } if command.command == .keyboardDismiss { guard !status.visible else { - return Response(ok: false, error: keyboardDismissRefusal()) + return Response(ok: false, error: keyboardDismissRefusal( + returnKey: status.returnKey.flatMap(RunnerKeyboardReturnKey.init(rawValue:)) + )) } return Response(ok: true, data: DataPayload( message: "keyboardDismiss", visible: false, wasVisible: false, dismissed: false diff --git a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Keyboard.swift b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Keyboard.swift index a6575092a4..a774361e1d 100644 --- a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Keyboard.swift +++ b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Keyboard.swift @@ -211,14 +211,27 @@ extension RunnerTests { } #endif - func keyboardDismissRefusal() -> ErrorPayload { - ErrorPayload( + /// `returnKey` is the Return key the refusing status observed: where Return itself ends the edit, + /// the hint names `keyboard enter` and what it will do. Dismiss never presses Return (#4644). + func keyboardDismissRefusal(returnKey: RunnerKeyboardReturnKey?) -> ErrorPayload { + let dismissal = "Inspect the screen and press the visible Hide Keyboard key or an app control that ends editing. If the app supports interactive dismissal, use gesture pan to drag a finger down from inside its scrollable content and check the keyboard state again." + return ErrorPayload( code: RunnerWireErrorCode.keyboardDismissUnavailable, message: "The Apple runner cannot dismiss this keyboard automatically", - hint: "Inspect the screen and press the visible Hide Keyboard key or an app control that ends editing. If the app supports interactive dismissal, use gesture pan to drag a finger down from inside its scrollable content and check the keyboard state again." + hint: [Self.keyboardReturnEndsEditingHint(returnKey), dismissal].compactMap { $0 }.joined(separator: " ") ) } + static func keyboardReturnEndsEditingHint(_ returnKey: RunnerKeyboardReturnKey?) -> String? { + switch returnKey { + case .search: return "To submit this search, run keyboard enter." + case .go: return "To submit this field, run keyboard enter (Return is Go)." + case .done: return "To finish editing, run keyboard enter (Return is Done)." + case .send: return "keyboard enter would send this message (Return is Send); run it only to send." + default: return nil + } + } + var keyboardReturnRefusal: ErrorPayload { ErrorPayload( code: RunnerWireErrorCode.keyboardReturnUnavailable, diff --git a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+KeyboardReturnKeyTests.swift b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+KeyboardReturnKeyTests.swift index eb7356a839..2701bd4285 100644 --- a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+KeyboardReturnKeyTests.swift +++ b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+KeyboardReturnKeyTests.swift @@ -3,6 +3,16 @@ import AgentDeviceSnapshotPresentation #if AGENT_DEVICE_RUNNER_UNIT_TESTS extension RunnerTests { + func testKeyboardDismissRefusalNamesKeyboardEnterOnlyWhereReturnEndsTheEdit() { + let search = keyboardDismissRefusal(returnKey: .search) + XCTAssertEqual(search.code, RunnerWireErrorCode.keyboardDismissUnavailable) + XCTAssertTrue(search.hint?.hasPrefix("To submit this search, run keyboard enter.") == true) + XCTAssertTrue(keyboardDismissRefusal(returnKey: .send).hint?.contains("run it only to send") == true) + for key: RunnerKeyboardReturnKey? in [nil, .unknown, .enter, .next] { + XCTAssertFalse(keyboardDismissRefusal(returnKey: key).hint?.contains("keyboard enter") == true) + } + } + func testKeyboardStatusRequiresMeasuredDisplayBounds() { let keyboard = CGRect(x: 0, y: 925, width: 834, height: 282) XCTAssertNil(RunnerKeyboardStatus.observed( diff --git a/packages/command-surface/src/system/index.ts b/packages/command-surface/src/system/index.ts index 029c9e5df8..01a2161062 100644 --- a/packages/command-surface/src/system/index.ts +++ b/packages/command-surface/src/system/index.ts @@ -319,7 +319,7 @@ const foldCommandDescription = `Fold or unfold a foldable iPhone simulator (iPho const appSwitcherCommandDescription = 'Open the device app switcher to inspect or change foreground apps. This changes the visible system UI and may move focus away from the current app.'; const keyboardCommandDescription = - 'status (alias get) reads the keyboard state; a visible keyboard reports returnKey and its label. Unreadable Apple keyboard state reports OBSERVATION_UNAVAILABLE. Enter (alias return) sends Return to the focused input; it may submit, move focus, or insert a newline, and unconfirmed delivery reports keyboard_return_unavailable with dispatched: unknown (Return may have landed). On the native iOS runner, dismiss is a no-op when the keyboard is hidden; a visible keyboard returns keyboard_dismiss_unavailable with dispatched: no. Press the visible Hide Keyboard key or an app control that ends editing, or gesture pan down from the scrollable content with interactive dismissal, and verify with status. Android dismiss sends platform dismissal.'; + 'status (alias get) reads the keyboard state; a visible keyboard reports returnKey and its label. Unreadable Apple keyboard state reports OBSERVATION_UNAVAILABLE. Enter (alias return) sends Return to the focused input; it may submit, move focus, or insert a newline, and unconfirmed delivery reports keyboard_return_unavailable with dispatched: unknown (Return may have landed). On the native iOS runner, dismiss is a no-op when the keyboard is hidden; a visible keyboard returns keyboard_dismiss_unavailable with dispatched: no. When Return would submit or finish the edit (search, go, done, send), that refusal names keyboard enter. Press the visible Hide Keyboard key or an app control that ends editing, or gesture pan down from the scrollable content with interactive dismissal, and verify with status. Android dismiss sends platform dismissal.'; const clipboardCommandDescription = 'Read the current device clipboard text, or replace its contents with the given text. Android runs both through the clipboard service shell command, and a build that implements none (Android 16 does not) refuses with UNSUPPORTED_OPERATION rather than reporting an empty clipboard.'; const actionButtonCommandDescription =