Skip to content

Commit a556e11

Browse files
authored
refactor(ios): move the coordinate-space rule into the presentation package (#2664)
* refactor(ios): declare bridge failure scope at the throw site, disclose unplaced surface hosts, move the coordinate-space rule into the presentation package Three follow-ups to #2653 (fixes #2612), each inside that PR's own new code. Failure scope. Whether a Simulator AX bridge failure retires the app generation from the bridge was decided at the route by matching the failure's kind and code. SnapshotSourceFailure now carries scope: 'capture' | 'generation', set where the failure is thrown (snapshotSourceCaptureError for bridge-preparation-pending and window-coordinate-space-unresolved), and the route reads the field. Disclosure. A runner capture that could not turn a rotated surface host back (orientation unreadable, or the private-AX tier anchored on the bridge's root box) published two coordinate spaces silently. SnapshotGeometrySpace.unplacedSurfaceHostCount runs after every tier's acquisition; a non-zero count rides the quality verdict as unresolvedCoordinateSpaceWindows and the daemon renders a warning. Package. The rotation table and the coordinate-space rule are pure CoreGraphics and now live in AgentDeviceSnapshotPresentation (SnapshotCoordinateSpace.swift) with their tests in the package suite, so swift test replays the golden table without a simulator. isSurfaceHost takes booleans instead of an XCUIElement.ElementType. * docs(ios): point the bridge refusal decision at the #2659 spike verdict The ADR 0004 refusal decision and the TS detector's header now cite the measurement (issue #2659, diff of #2667): the AX orientation attribute resolves but reads 0 through the guest channel, and the only cheap service read is device orientation, which diverges on a rotation-locked app. * refactor(ios): make failure scope a required constructor arg; count a turned surface once Addresses review on #2664. - SnapshotSourceError takes scope as a required argument (no 'generation' default), positioned after the required code. The two factories name their side: snapshotSourceError -> 'generation', snapshotSourceCaptureError -> 'capture'. New errors.test.ts pins both. - unplacedSurfaceHostCount folds a turned surface's window and the surface directly under it into one host, so the disclosed count is a surface count even when both report the turned box. Package test covers the both-turned pair. * refactor(ios): keep only the coordinate-space package move; drop scope field and unplaced-geometry disclosure Measured against main with npm pack: the earlier +9.3 kB was 6.8 kB of prose comments in the moved file (the presentation package is written comment-free and copied verbatim), ~1.5 kB of disclosure plumbing, and ~0.2 kB for the failure scope field. The move alone is now +25 bytes. - Moved file rewritten in the package's comment-free style; rationale stays in ADR 0004 and the golden fixture description. - Failure scope field reverted to main's opensGenerationCircuit predicate: a required constructor argument guarded what the route tests already guard, for two fixed codes. - unresolvedCoordinateSpaceWindows disclosure reverted: its only trigger path (private-AX tier with a penalized XCTest channel) anchors on a root frame whose space is unmeasured and is infinite in the common case, so the count is zero by construction there; never observed live. Noted on #2661 where one-pass normalization makes it a measured one-liner if ever wanted. - ADR 0004 keeps the #2659 spike pointer and the package-home sentence only.
1 parent 94a0b61 commit a556e11

10 files changed

Lines changed: 273 additions & 324 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
in the app's own orientation space.` — and the route sends that one capture to the runner instead of
3535
retiring the app generation, so the next capture of a healthy app still uses the bridge. One table
3636
proves both languages apply one rule: `contracts/fixtures/window-coordinate-space.json` (#2612).
37+
- Changed (ios): the rotation table and the coordinate-space rule moved from the XCTest runner bundle
38+
into the `AgentDeviceSnapshotPresentation` package, where `swift test` replays the golden table
39+
without a simulator. No behaviour change.
3740
- Added (limrun): `longpress` on Limrun iOS direct sessions. The interactor refused it as
3841
unsupported although the SDK exposes the HID primitives; it now holds one touch as a
3942
`performActions` batch of `touchDown`, `wait`, `touchUp`, defaulting to the 800 ms the Android

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerScrollViewportPolicy.swift‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import XCTest
2+
import AgentDeviceSnapshotPresentation
23

34
// The scroll viewport rule the runner shares with the TS runtime (#2500).
45
//

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ extension RunnerTests {
4444
let fields = privateAXFields(raw)
4545
let nodeSpace = SnapshotGeometrySpace.space(
4646
reportedBySurfaceHost: SnapshotGeometrySpace.isSurfaceHost(
47-
elementType: fields.elementType,
47+
isWindow: isWindowElement(fields.elementType),
4848
parentIsWindow: parentIsWindow
4949
),
5050
reportedFrame: fields.rect,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ extension RunnerTests {
10691069
) -> SnapshotGeometrySpace {
10701070
SnapshotGeometrySpace.space(
10711071
reportedBySurfaceHost: SnapshotGeometrySpace.isSurfaceHost(
1072-
elementType: snapshot.elementType,
1072+
isWindow: isWindowElement(snapshot.elementType),
10731073
parentIsWindow: parentIsWindow
10741074
),
10751075
reportedFrame: snapshot.frame,
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
import Foundation
2+
import CoreGraphics
3+
4+
// Rotation between an app's interface space and the device's native (portrait-up) space, shared by
5+
// synthesized dispatch (forward) and capture (inverse). Rationale and measurements: ADR 0004
6+
// "the coordinate space of a captured subtree" and contracts/fixtures/window-coordinate-space.json.
7+
8+
public enum RunnerInterfaceOrientation {
9+
public static let unknown = 0
10+
public static let portrait = 1
11+
public static let portraitUpsideDown = 2
12+
public static let landscapeRight = 3
13+
public static let landscapeLeft = 4
14+
}
15+
16+
public enum CoordinateSpaceRotation {
17+
public static func native(
18+
point: CGPoint,
19+
in frame: CGRect,
20+
interfaceOrientation: Int
21+
) -> CGPoint {
22+
let localX = Double(point.x) - Double(frame.minX)
23+
let localY = Double(point.y) - Double(frame.minY)
24+
let width = Double(frame.width)
25+
let height = Double(frame.height)
26+
switch interfaceOrientation {
27+
case RunnerInterfaceOrientation.landscapeRight:
28+
return CGPoint(x: height - localY, y: localX)
29+
case RunnerInterfaceOrientation.landscapeLeft:
30+
return CGPoint(x: localY, y: width - localX)
31+
case RunnerInterfaceOrientation.portraitUpsideDown:
32+
return CGPoint(x: width - localX, y: height - localY)
33+
default:
34+
return CGPoint(x: localX, y: localY)
35+
}
36+
}
37+
38+
public static func native(vector: CGVector, interfaceOrientation: Int) -> CGVector {
39+
switch interfaceOrientation {
40+
case RunnerInterfaceOrientation.landscapeRight:
41+
return CGVector(dx: -vector.dy, dy: vector.dx)
42+
case RunnerInterfaceOrientation.landscapeLeft:
43+
return CGVector(dx: vector.dy, dy: -vector.dx)
44+
case RunnerInterfaceOrientation.portraitUpsideDown:
45+
return CGVector(dx: -vector.dx, dy: -vector.dy)
46+
default:
47+
return vector
48+
}
49+
}
50+
51+
public static func oriented(
52+
point: CGPoint,
53+
in frame: CGRect,
54+
interfaceOrientation: Int
55+
) -> CGPoint {
56+
let width = Double(frame.width)
57+
let height = Double(frame.height)
58+
let localX: Double
59+
let localY: Double
60+
switch interfaceOrientation {
61+
case RunnerInterfaceOrientation.landscapeRight:
62+
localX = Double(point.y)
63+
localY = height - Double(point.x)
64+
case RunnerInterfaceOrientation.landscapeLeft:
65+
localX = width - Double(point.y)
66+
localY = Double(point.x)
67+
case RunnerInterfaceOrientation.portraitUpsideDown:
68+
localX = width - Double(point.x)
69+
localY = height - Double(point.y)
70+
default:
71+
localX = Double(point.x)
72+
localY = Double(point.y)
73+
}
74+
return CGPoint(x: localX + Double(frame.minX), y: localY + Double(frame.minY))
75+
}
76+
77+
public static func oriented(
78+
rect: CGRect,
79+
in frame: CGRect,
80+
interfaceOrientation: Int
81+
) -> CGRect {
82+
let leading = oriented(
83+
point: CGPoint(x: rect.minX, y: rect.minY),
84+
in: frame,
85+
interfaceOrientation: interfaceOrientation
86+
)
87+
let trailing = oriented(
88+
point: CGPoint(x: rect.maxX, y: rect.maxY),
89+
in: frame,
90+
interfaceOrientation: interfaceOrientation
91+
)
92+
return CGRect(
93+
x: min(leading.x, trailing.x),
94+
y: min(leading.y, trailing.y),
95+
width: abs(trailing.x - leading.x),
96+
height: abs(trailing.y - leading.y)
97+
)
98+
}
99+
}
100+
101+
public enum SnapshotGeometrySpace: Equatable {
102+
case appOrientation
103+
case deviceNative(appFrame: CGRect, interfaceOrientation: Int)
104+
105+
public static let quarterTurnTolerance: Double = 1
106+
107+
public func orientedFrame(of reportedFrame: CGRect) -> CGRect {
108+
switch self {
109+
case .appOrientation:
110+
return reportedFrame
111+
case .deviceNative(let appFrame, let interfaceOrientation):
112+
return CoordinateSpaceRotation.oriented(
113+
rect: reportedFrame,
114+
in: appFrame,
115+
interfaceOrientation: interfaceOrientation
116+
)
117+
}
118+
}
119+
120+
public static func space(
121+
reportedBySurfaceHost isSurfaceHost: Bool,
122+
reportedFrame: CGRect,
123+
inheritedFrom inherited: SnapshotGeometrySpace,
124+
appFrame: CGRect,
125+
interfaceOrientation: Int
126+
) -> SnapshotGeometrySpace {
127+
guard isSurfaceHost else { return inherited }
128+
guard namesQuarterTurn(interfaceOrientation) else { return .appOrientation }
129+
guard isQuarterTurned(reportedFrame, relativeTo: appFrame) else { return .appOrientation }
130+
return .deviceNative(appFrame: appFrame, interfaceOrientation: interfaceOrientation)
131+
}
132+
133+
public static func namesQuarterTurn(_ interfaceOrientation: Int) -> Bool {
134+
interfaceOrientation == RunnerInterfaceOrientation.landscapeLeft
135+
|| interfaceOrientation == RunnerInterfaceOrientation.landscapeRight
136+
}
137+
138+
public static func isSurfaceHost(isWindow: Bool, parentIsWindow: Bool) -> Bool {
139+
isWindow || parentIsWindow
140+
}
141+
142+
private static func isQuarterTurned(_ frame: CGRect, relativeTo appFrame: CGRect) -> Bool {
143+
guard isPlottable(frame), isPlottable(appFrame),
144+
abs(appFrame.width - appFrame.height) > quarterTurnTolerance
145+
else {
146+
return false
147+
}
148+
return abs(frame.width - appFrame.height) <= quarterTurnTolerance
149+
&& abs(frame.height - appFrame.width) <= quarterTurnTolerance
150+
}
151+
152+
private static func isPlottable(_ frame: CGRect) -> Bool {
153+
frame.origin.x.isFinite && frame.origin.y.isFinite
154+
&& frame.width.isFinite && frame.height.isFinite
155+
&& frame.width > 0 && frame.height > 0
156+
}
157+
}

0 commit comments

Comments
 (0)