Skip to content

Commit a42f844

Browse files
thymikeeclaude
andcommitted
fix(ios): turn about a full-screen app's window when the display size is unreadable
A failed AXRuntime display read refused every synthesized gesture on a single-screen device, including iPhone taps that worked through the window before. When the sole-screen rule (RunnerResolveSoleScreen) proves the app fills the screen, its window is the display and stays the rotation basis; otherwise the gesture still refuses with UNSUPPORTED_OPERATION. Both routes log AGENT_DEVICE_RUNNER_APP_SCREEN_UNRESOLVED stage=rotation-basis. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a812073 commit a42f844

3 files changed

Lines changed: 83 additions & 24 deletions

File tree

‎.github/workflows/xctest-nightly.yml‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ jobs:
151151
152152
# The iPad leg runs a named selection: the smallest set that can execute the off-phone half of
153153
# the sole-screen rule — the admission boundary itself, the display box a synthesized turn
154-
# swaps (#4091 reported it off on iPads), one hostile-tree command that must reach synthesis,
155-
# and `back`'s route witness.
154+
# swaps (#4091 reported it off on iPads) and its refusal when that box cannot be read, one
155+
# hostile-tree command that must reach synthesis, and `back`'s route witness.
156156
# Geometry and error cases live in the host-runnable evidence matrix instead. `xcodebuild`
157157
# exits 0 when a selection matches nothing, so the reporter below asserts the executed count
158158
# against this lane's reach (`XCTEST_LANE=nightly-ipad`, derived by check:xctest-selection).
@@ -171,6 +171,7 @@ jobs:
171171
-destination "platform=iOS Simulator,id=$UDID" \
172172
-only-testing:AgentDeviceRunnerUITests/RunnerTests/testSoleScreenDisplayIDIsNamedOnlyForAnAppThatFillsItsScreen \
173173
-only-testing:AgentDeviceRunnerUITests/RunnerTests/testSynthesizedRotationFrameIsTheDisplayNotAPlacedWindow \
174+
-only-testing:AgentDeviceRunnerUITests/RunnerTests/testTapRefusesBeforeDispatchWhenTheSoleDisplayCannotBeMeasured \
174175
-only-testing:AgentDeviceRunnerUITests/RunnerTests/testLongPressOnAnUnserializableTreeIsSynthesizedOnTheSoleScreen \
175176
-only-testing:AgentDeviceRunnerUITests/RunnerTests/testInAppBackAfterARejectedQueryTapsThroughTheRouteThatOpens \
176177
-only-testing:AgentDeviceRunnerUITests/RunnerTests/testInAppBackAfterARejectedQueryWithUnprovableForegroundTapsThroughTheWindow \

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

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extension RunnerTests {
2828
)
2929
}
3030
let frame = context.referenceFrame
31-
guard let rotationFrame = synthesizedRotationFrame(fallback: frame, interfaceOrientation: orientation) else {
31+
guard let rotationFrame = synthesizedRotationFrame(app: app, fallback: frame, interfaceOrientation: orientation) else {
3232
return Self.unmeasuredSoleDisplayOutcome(gesture: "drag")
3333
}
3434
let start = CoordinateSpaceRotation.native(
@@ -114,6 +114,7 @@ extension RunnerTests {
114114
}
115115
guard
116116
let rotationFrame = synthesizedRotationFrame(
117+
app: app,
117118
fallback: context.referenceFrame,
118119
interfaceOrientation: orientation
119120
)
@@ -196,6 +197,7 @@ extension RunnerTests {
196197
let orientation = Int(RunnerSynthesizedGesture.interfaceOrientation(forApplication: app))
197198
guard
198199
let rotationFrame = synthesizedRotationFrame(
200+
app: app,
199201
fallback: context.referenceFrame,
200202
interfaceOrientation: orientation
201203
)
@@ -504,11 +506,7 @@ extension RunnerTests {
504506
/// anything else (a windowed iPad, a multi-screen foldable) keeps requiring a window.
505507
@MainActor
506508
func soleScreenReferenceFrame(app: XCUIApplication) -> CGRect? {
507-
var resolvedScreen: AnyObject?
508-
var resolvedDisplayID: UInt = 0
509-
guard RunnerResolveSoleScreen(app, &resolvedScreen, &resolvedDisplayID) == nil else {
510-
return nil
511-
}
509+
guard appFillsSoleScreen(app) else { return nil }
512510
let orientation = Int(RunnerSynthesizedGesture.interfaceOrientation(forApplication: app))
513511
let frame = soleDisplayPortraitSize().flatMap {
514512
Self.soleScreenReferenceFrame(portraitSize: $0, interfaceOrientation: orientation)
@@ -520,15 +518,32 @@ extension RunnerTests {
520518
return frame
521519
}
522520

521+
/// The rule `RunnerResolveSoleScreen` owns: an iPhone by its idiom, an iPad only on the
522+
/// fills-screen proof.
523+
@MainActor
524+
private func appFillsSoleScreen(_ app: XCUIApplication) -> Bool {
525+
var resolvedScreen: AnyObject?
526+
var resolvedDisplayID: UInt = 0
527+
return RunnerResolveSoleScreen(app, &resolvedScreen, &resolvedDisplayID) == nil
528+
}
529+
523530
/// The box a synthesized turn swaps side lengths about. The digitizer turns about its display, so a
524531
/// placed iPad window's smaller box is not the basis (#3899); a multi-screen host keeps the
525-
/// resolved window, which names its panel (ADR 0025). Nil when the device's only screen would not
526-
/// report its size: no box there is a known basis, so the gesture refuses before it dispatches. An
527-
/// unknown orientation keeps `fallback`, which a turn that does not rotate never reads.
532+
/// resolved window `fallback`, which names its panel (ADR 0025). When the device's only screen
533+
/// will not report its size, `fallback` is the basis only while the app provably fills that
534+
/// screen; otherwise this is nil and the gesture refuses before it dispatches. An unknown
535+
/// orientation keeps `fallback`, which a turn that does not rotate never reads.
528536
@MainActor
529-
func synthesizedRotationFrame(fallback: CGRect, interfaceOrientation: Int) -> CGRect? {
537+
func synthesizedRotationFrame(app: XCUIApplication, fallback: CGRect, interfaceOrientation: Int) -> CGRect? {
530538
guard XCUIScreen.screens.count == 1 else { return fallback }
531-
guard let portraitSize = soleDisplayPortraitSize() else { return nil }
539+
guard let portraitSize = soleDisplayPortraitSize() else {
540+
let fillsScreen = appFillsSoleScreen(app)
541+
NSLog(
542+
"AGENT_DEVICE_RUNNER_APP_SCREEN_UNRESOLVED stage=rotation-basis basis=%@",
543+
fillsScreen ? "window" : "refused"
544+
)
545+
return fillsScreen ? fallback : nil
546+
}
532547
return Self.soleScreenReferenceFrame(portraitSize: portraitSize, interfaceOrientation: interfaceOrientation)
533548
?? fallback
534549
}
@@ -547,7 +562,7 @@ extension RunnerTests {
547562

548563
static func unmeasuredSoleDisplayOutcome(gesture: String) -> RunnerInteractionOutcome {
549564
.unsupported(
550-
message: "synthesized \(gesture) could not read the size of the device's only screen, so its coordinates cannot be rotated",
565+
message: "synthesized \(gesture) could not read the size of the device's only screen, and the app is not proven to fill it, so its coordinates cannot be rotated",
551566
hint: "Retry after the app is foregrounded; the runner log records why the screen size could not be read."
552567
)
553568
}
@@ -723,7 +738,7 @@ extension RunnerTests {
723738
width: plan.viewport.width,
724739
height: plan.viewport.height
725740
)
726-
guard let rotationFrame = synthesizedRotationFrame(fallback: frame, interfaceOrientation: orientation) else {
741+
guard let rotationFrame = synthesizedRotationFrame(app: app, fallback: frame, interfaceOrientation: orientation) else {
727742
return Self.unmeasuredSoleDisplayOutcome(gesture: "gesture")
728743
}
729744
let pointerSamples: [[[String: NSNumber]]] = plan.pointers.map { pointer in

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+SynthesizedInteractionTests.swift‎

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ extension RunnerTests {
255255
(RunnerInterfaceOrientation.landscapeRight, CGSize(width: screen.height, height: screen.width)),
256256
]
257257
for (orientation, expected) in expectations {
258-
let frame = try XCTUnwrap(synthesizedRotationFrame(fallback: placedWindow, interfaceOrientation: orientation))
258+
let frame = try XCTUnwrap(synthesizedRotationFrame(app: app, fallback: placedWindow, interfaceOrientation: orientation))
259259
XCTAssertEqual(frame.origin, .zero)
260260
XCTAssertEqual(frame.width, expected.width, accuracy: 0.5)
261261
XCTAssertEqual(frame.height, expected.height, accuracy: 0.5)
@@ -271,22 +271,61 @@ extension RunnerTests {
271271
let placedWindow = CGRect(x: 224, y: 207, width: 386, height: 682)
272272
let portrait = RunnerInterfaceOrientation.portrait
273273
mainOwned.soleDisplayPortraitSize = nil
274-
let measured = try XCTUnwrap(synthesizedRotationFrame(fallback: placedWindow, interfaceOrientation: portrait))
274+
let measured = try XCTUnwrap(synthesizedRotationFrame(app: app, fallback: placedWindow, interfaceOrientation: portrait))
275275
XCTAssertNotEqual(measured, placedWindow)
276276

277277
let nextCommand = try runnerCommandFixture(#"{"command":"uptime","commandId":"next-command"}"#)
278278
// Nothing between the install and the restore throws, so the restore always runs.
279279
let restoreAXRuntime = try simulateUnreadableSystemApplication()
280-
XCTAssertEqual(synthesizedRotationFrame(fallback: placedWindow, interfaceOrientation: portrait), measured)
280+
XCTAssertEqual(synthesizedRotationFrame(app: app, fallback: placedWindow, interfaceOrientation: portrait), measured)
281281
_ = try? executeOnMainPrepared(command: nextCommand, activeApp: app)
282-
XCTAssertNil(synthesizedRotationFrame(fallback: placedWindow, interfaceOrientation: portrait))
282+
XCTAssertNotEqual(
283+
synthesizedRotationFrame(app: app, fallback: placedWindow, interfaceOrientation: portrait),
284+
measured,
285+
"the next command must read the size again rather than reuse the kept one"
286+
)
283287
restoreAXRuntime()
284-
XCTAssertEqual(synthesizedRotationFrame(fallback: placedWindow, interfaceOrientation: portrait), measured)
288+
XCTAssertEqual(synthesizedRotationFrame(app: app, fallback: placedWindow, interfaceOrientation: portrait), measured)
285289
}
286290

287-
/// #4091: when the device's only screen will not report its size, a placed window's smaller box is
288-
/// no basis to turn about either (#3899), so a tap through a resolved window refuses before it
289-
/// dispatches instead of landing off target.
291+
/// #4091: when the device's only screen will not report its size, an app the sole-screen rule
292+
/// proves full-screen (an iPhone by its idiom) has a window that is the display, so its tap still
293+
/// turns about that window and is dispatched.
294+
@MainActor
295+
func testTapTurnsAboutTheWindowWhenTheSoleDisplayCannotBeMeasuredOnAFullScreenApp() throws {
296+
try XCTSkipUnless(XCUIScreen.screens.count == 1, "a multi-screen host keeps its panel's window box")
297+
app.launch()
298+
mainOwned.app = app
299+
defer {
300+
invalidateCachedTarget(reason: "unit_test_cleanup")
301+
app.terminate()
302+
}
303+
let resolved = try XCTUnwrap(resolveRunnerWindowElement(app: app))
304+
let context = try XCTUnwrap(
305+
SynthesizedCoordinateContext(validating: resolved.frame, resolvedWindow: resolved.window, accessibilityHealth: .healthy)
306+
)
307+
let restoreAXRuntime = try simulateUnreadableSystemApplication()
308+
defer { restoreAXRuntime() }
309+
mainOwned.soleDisplayPortraitSize = nil
310+
try XCTSkipUnless(
311+
soleScreenRouteIsOpen(for: app),
312+
"without AXRuntime an iPad cannot prove the app fills the screen; the refusal test covers it"
313+
)
314+
315+
let orientation = Int(RunnerSynthesizedGesture.interfaceOrientation(forApplication: app))
316+
XCTAssertEqual(
317+
synthesizedRotationFrame(app: app, fallback: resolved.frame, interfaceOrientation: orientation),
318+
resolved.frame
319+
)
320+
let outcome = synthesizedTapAt(app: app, x: 40, y: 40, context: context)
321+
guard case .performed? = outcome else {
322+
return XCTFail("expected the tap to be dispatched about the window, got \(String(describing: outcome))")
323+
}
324+
}
325+
326+
/// #4091: when the device's only screen will not report its size and the app is not proven to fill
327+
/// it, a placed window's smaller box is no basis to turn about (#3899), so a tap through a resolved
328+
/// window refuses before it dispatches instead of landing off target.
290329
@MainActor
291330
func testTapRefusesBeforeDispatchWhenTheSoleDisplayCannotBeMeasured() throws {
292331
try XCTSkipUnless(XCUIScreen.screens.count == 1, "a multi-screen host keeps its panel's window box")
@@ -305,9 +344,13 @@ extension RunnerTests {
305344
defer { restoreAXRuntime() }
306345
// An earlier gesture may have kept a successful read; this one must reach AXRuntime.
307346
mainOwned.soleDisplayPortraitSize = nil
347+
try XCTSkipIf(
348+
soleScreenRouteIsOpen(for: app),
349+
"an app proven full-screen turns about its window; the full-screen test covers it"
350+
)
308351

309352
XCTAssertNil(
310-
synthesizedRotationFrame(fallback: placedWindow, interfaceOrientation: RunnerInterfaceOrientation.landscapeRight)
353+
synthesizedRotationFrame(app: app, fallback: placedWindow, interfaceOrientation: RunnerInterfaceOrientation.landscapeRight)
311354
)
312355
let outcome = synthesizedTapAt(app: app, x: 40, y: 40, context: context)
313356
guard case .unsupported(let message, _)? = outcome else {

0 commit comments

Comments
 (0)