Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,11 @@ extension RunnerTests {
guard pressTvRemote(button, duration: duration) else {
return Response(
ok: false,
error: ErrorPayload(code: "UNSUPPORTED_OPERATION", message: "remotePress is only supported on tvOS")
error: ErrorPayload(
code: RunnerWireErrorCode.hardwareControlUnavailable,
message: "remotePress is only supported on tvOS",
hint: "Only a tvOS target has a Siri Remote. On a TV target use tv-remote; on a phone or Mac, press the app's own control by its ref."
)
)
}
return Response(ok: true, data: DataPayload(message: "remote pressed"))
Expand Down Expand Up @@ -567,7 +571,7 @@ extension RunnerTests {
return Response(
ok: false,
error: ErrorPayload(
code: "UNSUPPORTED_OPERATION",
code: RunnerWireErrorCode.hardwareControlUnavailable,
message: "actionButton requires a device model with an Action Button",
hint: "The Action Button is on iPhone 15 Pro and later and iPad Pro (M4) and later. Assign a Shortcut or App Intent to it in Settings > Action Button."
)
Expand All @@ -579,7 +583,7 @@ extension RunnerTests {
return Response(
ok: false,
error: ErrorPayload(
code: "UNSUPPORTED_OPERATION",
code: RunnerWireErrorCode.hardwareControlUnavailable,
message: "\(command.command) requires a physical iPhone or iPad; XCUIDevice exposes no volume press on a simulator",
hint: "hardware-button volume-up/volume-down is supported on physical iOS devices through the runner or Appium; iOS Simulators have no pressable volume key."
)
Expand Down Expand Up @@ -616,13 +620,7 @@ extension RunnerTests {
return Response(ok: false, error: ErrorPayload(message: "keyboardReturn produced no result"))
}
if !result.pressed {
return Response(
ok: false,
error: ErrorPayload(
code: "UNSUPPORTED_OPERATION",
message: "Unable to press the iOS keyboard return key"
)
)
return Response(ok: false, error: keyboardReturnRefusal)
}
return Response(
ok: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,19 @@ extension RunnerTests {
"An element whose center sits behind the on-screen keyboard is refused with tap_keyboard_occludes_target; one whose center stays above the keys presses normally. To end editing, tap the app's own Done/Cancel control, or use keyboard enter to press the return key when submission is wanted."
}

/// The refusal a `keyboard enter` answers with when nothing was submitted: the keyboard exposes no
/// return-like key, and typing a return found no field to type into. It carries the runner's own code
/// so the host publishes `details.reason` instead of leaving callers to read the prose. The dispatch
/// disclosure stays `unknown`: the sole-text-field route taps that field before it types, and that
/// tap can be the step that failed.
var keyboardReturnRefusal: ErrorPayload {
return ErrorPayload(
code: RunnerWireErrorCode.keyboardReturnUnavailable,
message: "Unable to press the keyboard return key: the keyboard exposes no return-like key and no text field was available to submit",
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
hint: "Tap the app's own submit control by its ref, or focus a text field with fill or type before asking keyboard enter to submit it."
)
}


// AX-free on purpose (screenshot bytes, not the accessibility tree) so it holds
// under the same AX degradation the synthesized gesture lane is built to survive.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ extension RunnerTests {
func performInAppBack(app: XCUIApplication) throws -> InAppBackOutcome {
#if os(macOS)
guard let back = macOSNavigationBackElement(app: app) else {
return .refused(ErrorPayload(message: "in-app back control is not available"))
return .refused(Self.macOSInAppBackControlRefusal)
}
let frame = back.frame
if frame.isEmpty {
Expand Down Expand Up @@ -602,6 +602,15 @@ extension RunnerTests {
)
}

/// macOS `back` presses the app's own back control, read from its tree; when the app exposes none,
/// there is no gesture left to try, so it sends nothing. The refusal carries the runner's own code so
/// the host publishes `details.reason` and a caller never reads the refusal off the message prose.
static let macOSInAppBackControlRefusal = ErrorPayload(
code: RunnerWireErrorCode.inAppBackControlUnavailable,
message: "in-app back control is not available",
hint: "Press the app's visible back control by its ref."
)

#if os(iOS)
/// The last settle sample: the baseline the swipe's change is measured from. `stableSinceMs` is
/// when the run of agreeing samples it ends began, and `sampledMs` when it was captured.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ final class RunnerTests: XCTestCase {
/// `BACK_SWIPE_UNVERIFIED` is one whose screen kept changing on its own before the swipe, or could
/// not be sampled afterwards. Both ran the swipe. `BACK_SWIPE_NOT_DISPATCHED` is a back swipe that
/// was refused before any touch went down, so dispatched: no.
/// `IN_APP_BACK_CONTROL_UNAVAILABLE` is macOS `back` finding no in-app back control, so it pressed
/// nothing. `KEYBOARD_RETURN_UNAVAILABLE` is `keyboard enter` finding nothing to submit.
/// `HARDWARE_CONTROL_UNAVAILABLE` is a press the runner answers that its target cannot perform.
/// The host publishes `details.reason` for all three.
enum RunnerWireErrorCode {
static let mainThreadTimeout = "MAIN_THREAD_TIMEOUT"
static let appNotRunning = "APP_NOT_RUNNING"
Expand All @@ -62,6 +66,20 @@ final class RunnerTests: XCTestCase {
/// runner vouches for (#1606). The host reports it under `UNSUPPORTED_OPERATION` and publishes
/// `details.reason`, so a caller never reads the refusal off the message prose.
static let keyboardDismissUnavailable = "KEYBOARD_DISMISS_UNAVAILABLE"
/// A `keyboard enter` that found no return key to press and no text entry to submit through, so
/// nothing was submitted. The host reports it under `UNSUPPORTED_OPERATION` and publishes
/// `details.reason`; the disclosure stays `unknown` because the sole-field route taps the field
/// before it types, and that tap can be the last thing that fails.
static let keyboardReturnUnavailable = "KEYBOARD_RETURN_UNAVAILABLE"
/// A press of a hardware or Siri Remote control this target cannot perform: the press helper refuses
/// before pressing anything, so the host reports `UNSUPPORTED_OPERATION` with `details.reason` and
/// `dispatched: no`. Through the daemon the reachable case today is the Action Button on an iPhone
/// or iPad model without one; the simulator volume and non-tvOS remote cases are refused by runtime
/// admission before the runner is asked.
static let hardwareControlUnavailable = "HARDWARE_CONTROL_UNAVAILABLE"
/// macOS `back` found no in-app back control to press, so it sent nothing. The host keeps the
/// `COMMAND_FAILED` code such a code-less refusal always had and publishes `details.reason`.
static let inAppBackControlUnavailable = "IN_APP_BACK_CONTROL_UNAVAILABLE"
/// Refuses a repeat of a `commandId` the runner already finished, when that command's own
/// classification keeps no response body to replay. Nothing ran for the repeat, but the daemon's
/// dispatch disclosure stays `unknown` — only the runner knows whether an earlier send of that id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ extension RunnerTests {
XCTAssertNotEqual(dispatched.code, notDispatched.code)
}

/// `keyboard enter` refusing for having nothing to submit is its own typed refusal, and the host
/// reads this code's literal to publish `details.reason`. The wire code alone is the contract.
func testKeyboardReturnRefusalNamesItsOwnCode() {
let refusal = keyboardReturnRefusal
XCTAssertEqual(refusal.code, "KEYBOARD_RETURN_UNAVAILABLE")
XCTAssertNotNil(refusal.hint)
}

func testKeyboardBandFactPublishesAbsenceWhenTheCompleteCaptureHasNoKeyboard() {
let fact = runnerKeyboardBandFact(exists: false, frame: .zero)
XCTAssertEqual(fact, .absent)
Expand Down Expand Up @@ -312,7 +320,10 @@ extension RunnerTests {

XCTAssertEqual(textEntryInputCount(), 0)
XCTAssertEqual(recordedFailures, 0)
XCTAssertEqual(response.error?.code, "UNSUPPORTED_OPERATION")
// The refusal names itself, so the host publishes its `details.reason`; the host still reports the
// command's own `UNSUPPORTED_OPERATION` for the caller.
XCTAssertEqual(response.error?.code, RunnerWireErrorCode.keyboardReturnUnavailable)
XCTAssertNotNil(response.error?.hint)
}

@MainActor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,15 @@ extension RunnerTests {

#endif

/// macOS `back` has one route: the app's own back control. Finding none sends nothing, so the refusal
/// names itself — the host publishes its `details.reason`, and a caller never reads the refusal off
/// the message. The literal is pinned as the wire value the host reads.
func testInAppBackControlRefusalNamesItsOwnCode() {
let refusal = Self.macOSInAppBackControlRefusal
XCTAssertEqual(refusal.code, "IN_APP_BACK_CONTROL_UNAVAILABLE")
XCTAssertNotNil(refusal.hint)
}

func testNavigationVisualObservationSeparatesChangeFromRefusal() {
// A refused side makes the pair uncomparable, not "unchanged"; reading it as "unchanged" would
// let a capture that refused become the reason `back` claims its swipe changed nothing.
Expand Down
10 changes: 10 additions & 0 deletions apple/runner/RUNNER_PROTOCOL.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,16 @@ next step also carries `hint`, omitted here. A keyboard that stayed up answers o
and the keyboard stayed visible. The host reports both under `UNSUPPORTED_OPERATION` and publishes the
first one's `details.reason`.

Three more refusals name the control the target could not supply, so a caller never reads the refusal
off `message`. `KEYBOARD_RETURN_UNAVAILABLE` is a `keyboard enter` whose keyboard exposed no return-like
key and for which no text field could be found; it proves no submission, not that nothing ran, because
the sole-text-field route taps the field before typing. `HARDWARE_CONTROL_UNAVAILABLE` is a press the
runner answers that its target cannot perform, today the Action Button on an iPhone or iPad model that
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
has none, and `IN_APP_BACK_CONTROL_UNAVAILABLE` is macOS `back` finding no in-app back control in the
app's tree. The last two press nothing. The host maps each to the code its command already refused with
(the first two to `UNSUPPORTED_OPERATION`, the macOS back refusal to the `COMMAND_FAILED` a code-less
reply produced) and publishes its `details.reason`.

`data` is command-specific. Common fields include snapshot nodes, text lookup results, gesture timing, visibility metadata, and screenshot or recording output details.

Capture-plan snapshots carry `snapshotViewport`, the acquisition's declared viewport evidence.
Expand Down
24 changes: 24 additions & 0 deletions contracts/fixtures/dispatch-disclosure.json
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,24 @@
"trigger": "structured runner reply with code KEYBOARD_DISMISS_UNAVAILABLE: `keyboard dismiss` refused because the visible keyboard exposes no dismiss key, before any tap",
"dispatched": "no"
},
{
"id": "ios-runner.reply.KEYBOARD_RETURN_UNAVAILABLE",
"producer": "ios-runner",
"trigger": "structured runner reply with code KEYBOARD_RETURN_UNAVAILABLE: `keyboard enter` found no return key to press; the sole-text-field route taps the field before typing, so a tap may have landed",
"dispatched": "unknown"
},
{
"id": "ios-runner.reply.HARDWARE_CONTROL_UNAVAILABLE",
"producer": "ios-runner",
"trigger": "structured runner reply with code HARDWARE_CONTROL_UNAVAILABLE: this target cannot perform the asked-for hardware or Siri Remote press, so nothing was pressed",
"dispatched": "no"
},
{
"id": "ios-runner.reply.IN_APP_BACK_CONTROL_UNAVAILABLE",
"producer": "ios-runner",
"trigger": "structured runner reply with code IN_APP_BACK_CONTROL_UNAVAILABLE: macOS `back` found no in-app back control in the app's tree and pressed nothing",
"dispatched": "no"
},
{
"id": "ios-runner.reply.unlisted-code",
"producer": "ios-runner",
Expand Down Expand Up @@ -493,6 +511,12 @@
"trigger": "fill's first clear-and-retype pass typed and failed verification; the second pass's adb input text then failed, so the fill reports unknown with details.dispatchedSteps counting the steps both passes sent",
"dispatched": "unknown"
},
{
"id": "android-adb.keyboard-dismiss.ime-ignored-escape",
"producer": "android-adb",
"trigger": "keyboard dismiss: the IME kept the keyboard visible through every escape keyevent, which were already sent (details.reason keyboard_dismiss_unavailable)",
"dispatched": "unknown"
},
{
"id": "android-helper.gesture.reported-failure",
"producer": "android-helper",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ const DRIVERS: Record<string, () => Promise<unknown>> = {
replyFailure('SYNTHESIZED_GESTURE_OUTCOME_UNKNOWN'),
'ios-runner.reply.KEYBOARD_DISMISS_UNAVAILABLE': () =>
replyFailure('KEYBOARD_DISMISS_UNAVAILABLE'),
'ios-runner.reply.KEYBOARD_RETURN_UNAVAILABLE': () => replyFailure('KEYBOARD_RETURN_UNAVAILABLE'),
'ios-runner.reply.HARDWARE_CONTROL_UNAVAILABLE': () =>
replyFailure('HARDWARE_CONTROL_UNAVAILABLE'),
'ios-runner.reply.IN_APP_BACK_CONTROL_UNAVAILABLE': () =>
replyFailure('IN_APP_BACK_CONTROL_UNAVAILABLE'),
'ios-runner.reply.unlisted-code': () => replyFailure('XCTEST_RECORDED_FAILURE'),
'ios-runner.series.later-chunk-refused': pressSeriesRefusedOnSecondChunk,
'ios-runner.series.invalid-step-before-send': pressSeriesWithInvalidStep,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { test } from 'vitest';
import { AppError, createRequestCanceledError } from '@agent-device/kernel/errors';
import {
COMMAND_ALREADY_FINISHED_RUNNER_CODE,
HARDWARE_CONTROL_UNAVAILABLE_RUNNER_CODE,
IN_APP_BACK_CONTROL_UNAVAILABLE_RUNNER_CODE,
KEYBOARD_DISMISS_UNAVAILABLE_RUNNER_CODE,
KEYBOARD_RETURN_UNAVAILABLE_RUNNER_CODE,
MAIN_THREAD_TIMEOUT_RUNNER_CODE,
NO_TEXT_INPUT_AT_POINT_RUNNER_CODE,
RUNNER_SCREEN_CAPTURE_REFUSAL_RUNNER_CODES,
Expand All @@ -24,6 +27,7 @@ import {
} from '../runner-error-classification.ts';
import { runnerConnectFailure, unwrittenConnectRefusal } from './runner-session-fixtures.ts';
import {
requireSwiftControlRefusalWireCodes,
requireSwiftKeyboardDismissRefusalWireCode,
requireSwiftThrownErrorWireCode,
} from './runner-swift-settlement-fixtures.ts';
Expand Down Expand Up @@ -209,6 +213,61 @@ test('a keyboard dismiss refused for having no dismiss key keeps its code and pu
assert.equal(dispatched.details.dispatched, 'unknown');
});

// Three more refusals a caller could only tell apart by reading `message`. Each keeps the code its
// command already refused with, so only `details.reason` is added; the two that provably pressed
// nothing disclose `no`, and `keyboard enter` cannot, because its sole-field route taps the field
// before typing.
test('the hardware-control refusal keeps UNSUPPORTED_OPERATION and says nothing was pressed', () => {
assert.equal(HARDWARE_CONTROL_UNAVAILABLE_RUNNER_CODE, 'HARDWARE_CONTROL_UNAVAILABLE');
const refusal = classifyRunnerReportedError(HARDWARE_CONTROL_UNAVAILABLE_RUNNER_CODE);
assert.equal(refusal.code, 'UNSUPPORTED_OPERATION');
assert.deepEqual(refusal.details, {
runnerErrorCode: 'HARDWARE_CONTROL_UNAVAILABLE',
reason: 'hardware_control_unavailable',
dispatched: 'no',
});
// The closest negative: the same sentence with no code earns no reason, so a consumer keyed on
// `reason` cannot mistake prose for the typed refusal.
const untyped = commandFailed('actionButton requires a device model with an Action Button');
assert.equal(untyped.details?.reason, undefined);
});

test('the keyboard-return refusal keeps UNSUPPORTED_OPERATION and reports an unknown dispatch', () => {
assert.equal(KEYBOARD_RETURN_UNAVAILABLE_RUNNER_CODE, 'KEYBOARD_RETURN_UNAVAILABLE');
const refusal = classifyRunnerReportedError(KEYBOARD_RETURN_UNAVAILABLE_RUNNER_CODE);
assert.equal(refusal.code, 'UNSUPPORTED_OPERATION');
// The refusal says nothing about dispatch: the sole-text-field route taps the field before typing the
// return, so a refusal can follow a tap that landed.
assert.deepEqual(refusal.details, {
runnerErrorCode: 'KEYBOARD_RETURN_UNAVAILABLE',
reason: 'keyboard_return_unavailable',
dispatched: 'unknown',
});
// The closest negative: the same sentence with no code earns no reason, so a consumer keyed on
// `reason` cannot mistake prose for the typed refusal.
const untyped = commandFailed(
'Unable to press the keyboard return key: the keyboard exposes no return-like key and no text field was available to submit',
);
assert.equal(untyped.details?.reason, undefined);
});

test('the macOS in-app back refusal publishes its reason under the code a code-less reply had', () => {
assert.equal(IN_APP_BACK_CONTROL_UNAVAILABLE_RUNNER_CODE, 'IN_APP_BACK_CONTROL_UNAVAILABLE');
const refusal = classifyRunnerReportedError(IN_APP_BACK_CONTROL_UNAVAILABLE_RUNNER_CODE);
// That reply carried no code, so the host read COMMAND_FAILED; naming it must not move the command
// to a code its callers never saw.
assert.equal(refusal.code, 'COMMAND_FAILED');
assert.deepEqual(refusal.details, {
runnerErrorCode: 'IN_APP_BACK_CONTROL_UNAVAILABLE',
reason: 'in_app_back_control_unavailable',
dispatched: 'no',
});
// The closest negative: the base reply was a code-less COMMAND_FAILED, and prose alone still earns no
// reason, so a consumer keyed on `reason` cannot mistake it for the typed refusal.
const untyped = commandFailed('in-app back control is not available');
assert.equal(untyped.details?.reason, undefined);
});

test('retryable requires an AppError with COMMAND_FAILED', () => {
assert.equal(isRetryableRunnerError(new Error('fetch failed')), false);
assert.equal(isRetryableRunnerError(new AppError('DEVICE_NOT_FOUND', 'fetch failed')), false);
Expand Down Expand Up @@ -609,6 +668,28 @@ test('the runner declares the wire code the keyboard-dismiss refusal publishes i
);
});

test('the runner declares the wire codes the control refusals publish their reasons under', () => {
const swift = requireSwiftControlRefusalWireCodes();
assert.equal(
swift.keyboardReturnCode,
KEYBOARD_RETURN_UNAVAILABLE_RUNNER_CODE,
'the runner must encode its nothing-to-submit refusal under the code the daemon maps to ' +
'details.reason, or that reason becomes unreachable',
);
assert.equal(
swift.hardwareControlCode,
HARDWARE_CONTROL_UNAVAILABLE_RUNNER_CODE,
'the runner must encode its cannot-press-here refusal under the code the daemon maps to ' +
'details.reason, or that reason becomes unreachable',
);
assert.equal(
swift.inAppBackControlCode,
IN_APP_BACK_CONTROL_UNAVAILABLE_RUNNER_CODE,
'the runner must encode its macOS no-back-control refusal under the code the daemon maps to ' +
'details.reason, or that reason becomes unreachable',
);
});

// --- runner that predates the listener token ---

test('a runner that does not require the token is session-fatal and never retried or replayed', () => {
Expand Down
Loading
Loading