Skip to content

Commit 19af3bf

Browse files
committed
fix(action-button): keep the recorded-failure conversion on the press
`isLifecycle` does two things: it skips the app-activation preflight, and it exempts the command from turning a recorded XCTest issue into `XCTEST_RECORDED_FAILURE`. The press joined the lifecycle group for the first and silently took the second, which matters most here because the press declares no settle and no post-action observation, so that conversion was the only evidence it landed. The press now classifies like `home` and skips activation through `shouldSkipAppActivationPreflight`, where `.alert` already exempts itself for the same reason. `pressActionButton` also refuses below iOS 16 instead of pressing a control that API cannot express there, and two Swift tests pin both decisions where they are decided.
1 parent 7f36e4d commit 19af3bf

3 files changed

Lines changed: 50 additions & 11 deletions

File tree

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,23 @@ extension RunnerTests {
521521
)
522522
}
523523

524+
func testXCTestRecordedFailureResponseFailsActionButtonSuccess() throws {
525+
// The Action Button press carries no settle and no post-action observation, so this conversion is
526+
// the only evidence the press landed. That is why the press is not classified runner-lifecycle:
527+
// `isLifecycle` would silence the conversion here (#2699, #2702 review).
528+
let command = try runnerCommandFixture(#"{"command":"actionButton","commandId":"action-button-1"}"#)
529+
let response = Response(ok: true, data: DataPayload(message: "actionButton"))
530+
531+
let failureResponse = xctestRecordedFailureResponse(command: command, response: response)
532+
533+
XCTAssertEqual(failureResponse?.ok, false)
534+
XCTAssertEqual(failureResponse?.error?.code, "XCTEST_RECORDED_FAILURE")
535+
XCTAssertEqual(
536+
failureResponse?.error?.message,
537+
"XCTest recorded a failure while executing actionButton; the action may not have been performed."
538+
)
539+
}
540+
524541
func testXCTestRecordedFailureResponseDoesNotWrapReadOnlyOrRunnerFatalResponses() throws {
525542
let snapshotCommand = try runnerCommandFixture(#"{"command":"snapshot","commandId":"snapshot-1"}"#)
526543
let tapCommand = try runnerCommandFixture(#"{"command":"tap","commandId":"tap-1"}"#)
@@ -610,6 +627,17 @@ extension RunnerTests {
610627
XCTAssertFalse(shouldSkipAppActivationPreflight(coordinateTap))
611628
}
612629

630+
func testActionButtonPressSkipsAppActivationPreflightWithoutBeingRunnerLifecycle() throws {
631+
currentApp = nil
632+
currentBundleId = nil
633+
let press = try runnerCommandFixture(#"{"command":"actionButton","commandId":"action-button-1"}"#)
634+
635+
// The skip is its own decision, reached without the lifecycle flag that would also drop the
636+
// recorded-failure conversion; no cached target and no foreground app is required for it.
637+
XCTAssertFalse(isRunnerLifecycleCommand(.actionButton))
638+
XCTAssertTrue(shouldSkipAppActivationPreflight(press))
639+
}
640+
613641
func testPrepareActiveCommandContextRoutesBlockingSystemModalToSpringboard() throws {
614642
blockingSystemModalPresenceOverrideForTesting = true
615643
currentApp = nil
@@ -2552,6 +2580,14 @@ extension RunnerTests {
25522580
if command.command == .alert {
25532581
return true
25542582
}
2583+
// A hardware Action Button press belongs to the system, not to the session app: the Shortcut or
2584+
// App Intent behind it is expected to run whether that app is foregrounded, backgrounded, or
2585+
// terminated, and activating first would foreground exactly what the press should leave alone.
2586+
// The press keeps its recorded-failure conversion, which `isLifecycle` would have removed
2587+
// (#2699, #2702 review).
2588+
if command.command == .actionButton {
2589+
return true
2590+
}
25552591
// Coordinate-only synthesized taps can run after an AX-fatal foreground screen because they do not
25562592
// need app activation, window lookup, keyboard lookup, or element resolution. Selector/text
25572593
// interactions intentionally stay on the normal AX path because they need an element query.

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,17 @@ extension RunnerTests {
124124
#endif
125125
}
126126

127-
/// Presses the iPhone Action Button.
127+
/// Presses the iPhone Action Button, returning false when this device cannot express the press.
128128
///
129129
/// `XCUIDevice.press(_:)` has no hold-duration overload, so a single press is the whole gesture
130130
/// this API can express. `hasHardwareButton(.action)` is what separates a model with the button
131-
/// from one without; returning false rather than pressing anyway is what stops a model without
132-
/// the hardware from reporting a press that never happened.
131+
/// from one without, and both it and `Button.action` need iOS 16 while the deployment target is
132+
/// lower, so an older system refuses rather than pressing a control that cannot exist there.
133133
@discardableResult
134134
func pressActionButton() -> Bool {
135135
#if os(iOS)
136-
if #available(iOS 16.0, *) {
137-
guard XCUIDevice.shared.hasHardwareButton(.action) else { return false }
138-
}
136+
guard #available(iOS 16.0, *) else { return false }
137+
guard XCUIDevice.shared.hasHardwareButton(.action) else { return false }
139138
XCUIDevice.shared.press(.action)
140139
return true
141140
#else

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,17 @@ extension CommandType {
9595
return CommandTraits(isInteraction: false, readOnly: .conditional, isLifecycle: false)
9696

9797
// Runner-lifecycle commands: skip the app-activation preflight.
98-
// .actionButton joins this group for its one property, not for a lifecycle meaning: a hardware
99-
// Action Button press has to reach a Shortcut or App Intent whether the session app is
100-
// foregrounded, backgrounded, or terminated, and the activation preflight would foreground it
101-
// first (#2699). It is not read-only, so it never takes the session-invalidating retry.
102-
case .actionButton, .recordStop, .uptime, .terminate, .targetReset, .shutdown:
98+
case .recordStop, .uptime, .terminate, .targetReset, .shutdown:
10399
return CommandTraits(isInteraction: false, readOnly: .never, isLifecycle: true)
104100

101+
// A hardware press mutates, is not an element interaction, and is not runner-lifecycle. It stays
102+
// outside the lifecycle group because that flag also exempts a command from the recorded-failure
103+
// conversion, and this command has no settle or post-action observation, so that conversion is
104+
// the only evidence the press landed. It skips the app-activation preflight on its own terms in
105+
// `shouldSkipAppActivationPreflight`, the way `.alert` does (#2699, #2702 review).
106+
case .actionButton:
107+
return CommandTraits(isInteraction: false, readOnly: .never, isLifecycle: false)
108+
105109
case .status:
106110
return CommandTraits(isInteraction: false, readOnly: .always, isLifecycle: true)
107111

0 commit comments

Comments
 (0)