Skip to content

Commit 88d7d73

Browse files
thymikeeclaude
andcommitted
Merge perf/ios-command-suite into perf/android-command-suite
#3885 was rebased onto main after #3884 merged. This merge takes its new head with the Android layer's two commits replayed on it. Suite conflicts resolve to the renamed suite.ts and suite-harness.ts: the pinned-tree capture moves to home-reads (iOS only) and the Android one-shot step keeps its transport check. Co-Authored-By: Claude Opus 5.5 <[email protected]>
2 parents 4f18a1a + 8958314 commit 88d7d73

127 files changed

Lines changed: 3316 additions & 842 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ name: Perf Nightly
55
# - Catches: a command whose daemon time moves beyond the noise of earlier nights, or that starts
66
# failing. PR lanes check behavior, not time.
77
# - Wanted for: tuning runner, snapshot, and settle paths while watching the effect. iOS medians
8-
# swing up to +122% between single nights at n=5, so a step is judged against the median of up to
9-
# seven earlier nights and must clear their spread, its own sampling error, 20%, and 50 ms.
8+
# swing up to +122% between single nights, so a step is judged against the median of up to seven
9+
# earlier nights and must clear their spread, its own sampling error, 20%, and 50 ms. A night
10+
# runs 3 rounds, the minimum for a timing verdict, so one failed sample withholds that step's
11+
# timing verdict.
1012
# - Cost: one macos-26 job of about 45 minutes and one ubuntu emulator job a night; summaries are
1113
# kept 90 days, raw logs 30.
1214
# - Delete or park when: no flagged change has been acted on for 60 nights.

‎android/snapshot-helper/src/main/java/com/callstack/agentdevice/snapshothelper/AccessibilityNodeReads.java‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,19 @@ static AccessibilityNodeInfo root(AccessibilityWindowInfo window) {
3030
return window.getRoot();
3131
}
3232

33+
/**
34+
* The child, or null when it is gone. When the child's window closes during the read, the
35+
* framework can throw a NullPointerException from its result integrity check instead of answering
36+
* null (seen on API 35 while an alert dialog closed), so that throw means the same as null.
37+
*/
3338
static AccessibilityNodeInfo child(AccessibilityNodeInfo node, int index) {
34-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
35-
return node.getChild(index, PREFETCH_STRATEGY);
39+
try {
40+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
41+
return node.getChild(index, PREFETCH_STRATEGY);
42+
}
43+
return node.getChild(index);
44+
} catch (NullPointerException vanished) {
45+
return null;
3646
}
37-
return node.getChild(index);
3847
}
3948
}

‎apple/macos-helper/Sources/AgentDeviceMacOSHelper/BackgroundInteraction.swift‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,18 @@ func scrollBarValue(current: Double, signedTravel: Double, overflow: Double) ->
259259
min(1, max(0, current + signedTravel / overflow))
260260
}
261261

262+
/// A SwiftUI `Form` lists each row as a child of the scroll area, with no single document view as
263+
/// tall as the content, so the content is the span all of the area's children cover.
264+
func scrollContentOverflow(area: RectResponse, contentFrames: [RectResponse], isVertical: Bool)
265+
-> Double
266+
{
267+
let spans = contentFrames
268+
.filter { $0.width > 0 && $0.height > 0 }
269+
.map { isVertical ? ($0.y, $0.y + $0.height) : ($0.x, $0.x + $0.width) }
270+
guard let start = spans.map(\.0).min(), let end = spans.map(\.1).max() else { return 0 }
271+
return end - start - (isVertical ? area.height : area.width)
272+
}
273+
262274
func isPressableControlRole(_ role: String) -> Bool {
263275
pressableControlRoles.contains(role)
264276
}
@@ -426,15 +438,17 @@ private func performScrollBarScroll(
426438
guard let bar = elementAttribute(element, attribute: barAttribute as String),
427439
isAttributeSettable(bar, attribute: kAXValueAttribute as String),
428440
let value = numberAttribute(bar, attribute: kAXValueAttribute as String),
429-
let area = rectAttribute(element),
430-
let content = children(of: element)
431-
.filter({ role(of: $0) != "AXScrollBar" })
432-
.compactMap(rectAttribute)
433-
.max(by: { $0.width * $0.height < $1.width * $1.height })
441+
let area = rectAttribute(element)
434442
else {
435443
continue
436444
}
437-
let overflow = isVertical ? content.height - area.height : content.width - area.width
445+
let overflow = scrollContentOverflow(
446+
area: area,
447+
contentFrames: children(of: element)
448+
.filter({ role(of: $0) != "AXScrollBar" })
449+
.compactMap(rectAttribute),
450+
isVertical: isVertical
451+
)
438452
guard overflow > 0 else { continue }
439453
let next = scrollBarValue(current: value, signedTravel: signedTravel, overflow: overflow)
440454
return AXUIElementSetAttributeValue(bar, kAXValueAttribute as CFString, NSNumber(value: next))

‎apple/macos-helper/Tests/AgentDeviceMacOSHelperTests/BackgroundInteractionTests.swift‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,33 @@ final class BackgroundInteractionTests: XCTestCase {
7878
XCTAssertEqual(scrollBarValue(current: 0.1, signedTravel: -600, overflow: 1200), 0)
7979
}
8080

81+
func testScrollOverflowSpansEveryContentChild() {
82+
let area = RectResponse(x: 0, y: 100, width: 400, height: 600)
83+
let rows = (0..<10).map { row in
84+
RectResponse(x: 20, y: 100 + Double(row) * 120, width: 360, height: 100)
85+
}
86+
XCTAssertEqual(scrollContentOverflow(area: area, contentFrames: rows, isVertical: true), 580)
87+
XCTAssertEqual(scrollContentOverflow(area: area, contentFrames: rows, isVertical: false), -40)
88+
}
89+
90+
func testScrollOverflowCountsAChildFarOutsideTheContent() {
91+
let area = RectResponse(x: 0, y: 100, width: 400, height: 600)
92+
let rows = (0..<10).map { row in
93+
RectResponse(x: 20, y: 100 + Double(row) * 120, width: 360, height: 100)
94+
}
95+
let header = RectResponse(x: 0, y: -5000, width: 400, height: 40)
96+
XCTAssertEqual(
97+
scrollContentOverflow(area: area, contentFrames: rows + [header], isVertical: true), 5680)
98+
}
99+
100+
func testScrollOverflowIgnoresEmptyFrames() {
101+
let area = RectResponse(x: 0, y: 100, width: 400, height: 600)
102+
let document = RectResponse(x: 0, y: -400, width: 400, height: 2000)
103+
let empty = RectResponse(x: 0, y: -5000, width: 0, height: 0)
104+
XCTAssertEqual(
105+
scrollContentOverflow(area: area, contentFrames: [document, empty], isVertical: true), 1400)
106+
}
107+
81108
/// Chromium marks wrapper groups pressable; only a control role may win the press outright.
82109
func testWrapperGroupsAreNotPressableControls() {
83110
XCTAssertTrue(isPressableControlRole("AXButton"))

‎apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerApp.m‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ - (NSString *)accessibilityValue {
8383
#endif
8484

8585
@interface AgentDeviceRunnerViewController : UIViewController
86+
@property(nonatomic, strong) UILabel *navigationBackStatus;
8687
@property(nonatomic, strong) UILabel *maskedToggleStatus;
8788
@property(nonatomic, strong) UILabel *maskedDeliveryStatus;
8889
@property(nonatomic, assign) NSUInteger maskedTogglePresses;
@@ -586,6 +587,10 @@ - (void)updateMaskedToggleStatus {
586587
}
587588
#endif
588589

590+
- (void)navigationBackPressed {
591+
self.navigationBackStatus.text = @"Back performed";
592+
}
593+
589594
- (void)viewDidLoad {
590595
[super viewDidLoad];
591596

@@ -605,6 +610,24 @@ - (void)viewDidLoad {
605610

606611
// Keep the fixture behind a launch argument so normal runner snapshots remain unchanged.
607612
#if TARGET_OS_IOS
613+
if ([NSProcessInfo.processInfo.arguments containsObject:@"--agent-device-back-regression"]) {
614+
self.navigationBackStatus = label;
615+
label.accessibilityIdentifier = @"agent-device-back-status";
616+
if ([NSProcessInfo.processInfo.arguments containsObject:@"--navigation-bar"]) {
617+
UINavigationBar *bar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 62, self.view.bounds.size.width, 44)];
618+
UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:@"Thread"];
619+
item.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Go back" style:UIBarButtonItemStylePlain target:self action:@selector(navigationBackPressed)];
620+
bar.items = @[item];
621+
[self.view addSubview:bar];
622+
} else {
623+
UIButton *back = [UIButton buttonWithType:UIButtonTypeSystem];
624+
back.frame = CGRectMake(12, 62, 88, 44);
625+
[back setTitle:@"Go back" forState:UIControlStateNormal];
626+
[back addTarget:self action:@selector(navigationBackPressed) forControlEvents:UIControlEventTouchUpInside];
627+
[self.view addSubview:back];
628+
}
629+
}
630+
608631
if ([NSProcessInfo.processInfo.arguments containsObject:@"--agent-device-alert-replacement-regression"]) {
609632
self.alertActionStatus = label;
610633
label.accessibilityIdentifier = @"agent-device-alert-actions";

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

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,15 @@ extension RunnerTests {
6060
#else
6161
let buttons = app.navigationBars.buttons.allElementsBoundByIndex
6262
if let back = buttons.first(where: { $0.isHittable }) {
63+
// `isHittable` promises a hittable point, not a hittable center: a bar button partly under an
64+
// overlay keeps the element tap, which aims at the point XCTest computed.
6365
back.tap()
6466
return .performed
6567
}
6668
if isSnapshotXCTestChannelPenalized(bundleId: mainOwned.bundleId) {
6769
NSLog("AGENT_DEVICE_RUNNER_IN_APP_BACK_SKIPPED_XCTEST_ENUMERATION bundle=%@", mainOwned.bundleId ?? "")
68-
} else if let back = topNavigationBackElement(app: app) {
69-
tapElementCenter(app: app, element: back)
70-
return .performed
70+
} else if let frame = topNavigationBackFrame(app: app) {
71+
return tapResolvedNavigationBackControl(app: app, frame: frame)
7172
}
7273
return tapTopLeadingNavigationFallback(app: app)
7374
#endif
@@ -84,32 +85,48 @@ extension RunnerTests {
8485
#endif
8586
}
8687

87-
private func topNavigationBackElement(app: XCUIApplication) -> XCUIElement? {
88+
@MainActor
89+
private func tapResolvedNavigationBackControl(app: XCUIApplication, frame: CGRect) -> InAppBackOutcome {
90+
guard SnapshotGeometry.isPositiveFinite(frame) else { return .unavailable }
91+
let context = synthesizedCoordinateContext(
92+
app: app,
93+
policy: synthesizedGesturePolicy(.coordinateTap)
94+
)
95+
switch performSynthesizedGesture(app, kind: .coordinateTap, context: context, synthesize: {
96+
synthesizedTapAt(app: app, x: frame.midX, y: frame.midY, context: context)
97+
}) {
98+
case .performed:
99+
return .performed
100+
case .refused:
101+
return .unavailable
102+
case .xctestFallback:
103+
let fallback = performGesture(app) {
104+
tapAt(app: app, x: frame.midX, y: frame.midY)
105+
}
106+
if case .performed = fallback.outcome { return .performed }
107+
return .unavailable
108+
}
109+
}
110+
111+
private func topNavigationBackFrame(app: XCUIApplication) -> CGRect? {
88112
#if os(iOS)
89-
let frame = onScreenWindowFrame(app: app)
113+
let window = onScreenWindowFrame(app: app)
90114
let candidates = app.buttons.matching(Self.navigationBackPredicate()).allElementsBoundByIndex.compactMap {
91-
element -> (XCUIElement, Int)? in
115+
element -> (frame: CGRect, rank: Int)? in
92116
guard element.exists, element.isHittable else { return nil }
93-
guard Self.isTopNavigationBackCandidateFrame(
94-
element.frame,
95-
in: frame,
96-
identifier: element.identifier
97-
) else { return nil }
98-
guard let rank = Self.navigationBackControlRank(
99-
label: element.label,
100-
identifier: element.identifier
101-
) else {
102-
return nil
103-
}
104-
return (element, rank)
117+
let frame = element.frame
118+
let identifier = element.identifier
119+
guard Self.isTopNavigationBackCandidateFrame(frame, in: window, identifier: identifier)
120+
else { return nil }
121+
guard let rank = Self.navigationBackControlRank(label: element.label, identifier: identifier)
122+
else { return nil }
123+
return (frame, rank)
105124
}
106125
return candidates.sorted { lhs, rhs in
107-
if lhs.1 != rhs.1 { return lhs.1 < rhs.1 }
108-
let leftFrame = lhs.0.frame
109-
let rightFrame = rhs.0.frame
110-
if leftFrame.minY != rightFrame.minY { return leftFrame.minY < rightFrame.minY }
111-
return leftFrame.minX < rightFrame.minX
112-
}.first?.0
126+
if lhs.rank != rhs.rank { return lhs.rank < rhs.rank }
127+
if lhs.frame.minY != rhs.frame.minY { return lhs.frame.minY < rhs.frame.minY }
128+
return lhs.frame.minX < rhs.frame.minX
129+
}.first?.frame
113130
#else
114131
return nil
115132
#endif

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,67 @@
11
import XCTest
2+
#if AGENT_DEVICE_RUNNER_UNIT_TESTS && os(iOS)
3+
import ObjectiveC.runtime
4+
#endif
25

36
#if AGENT_DEVICE_RUNNER_UNIT_TESTS
47
extension RunnerTests {
8+
#if os(iOS)
9+
@MainActor
10+
func testRankedInAppBackUsesSynthesisWithoutXCTestTap() throws {
11+
try assertInAppBackDispatch(navigationBar: false)
12+
}
13+
14+
/// A navigation bar button keeps XCTest's element tap, which aims at its computed hittable point.
15+
@MainActor
16+
func testNavigationBarBackKeepsTheElementTap() throws {
17+
try assertInAppBackDispatch(navigationBar: true)
18+
}
19+
20+
@MainActor
21+
private func assertInAppBackDispatch(navigationBar: Bool) throws {
22+
app.launchArguments = ["--agent-device-back-regression"] + (navigationBar ? ["--navigation-bar"] : [])
23+
app.launch()
24+
mainOwned.app = app
25+
mainOwned.bundleId = "com.callstack.agentdevice.runner"
26+
clearSnapshotXCTestChannelPenalty(reason: "navigation-test")
27+
defer {
28+
invalidateCachedTarget(reason: "unit_test_cleanup")
29+
app.terminate()
30+
}
31+
let status = app.staticTexts["agent-device-back-status"]
32+
XCTAssertTrue(status.waitForFixtureExistence(timeout: appExistenceTimeout))
33+
var xctestTaps = 0
34+
var restorations: [() -> Void] = []
35+
defer { restorations.reversed().forEach { $0() } }
36+
for type in [XCUIElement.self, XCUICoordinate.self] {
37+
let selector = NSSelectorFromString("tap")
38+
let method = try XCTUnwrap(class_getInstanceMethod(type, selector))
39+
let original = method_getImplementation(method)
40+
let replacement = imp_implementationWithBlock({ (target: AnyObject) in
41+
xctestTaps += 1
42+
typealias Tap = @convention(c) (AnyObject, Selector) -> Void
43+
unsafeBitCast(original, to: Tap.self)(target, selector)
44+
} as @convention(block) (AnyObject) -> Void)
45+
method_setImplementation(method, replacement)
46+
restorations.append {
47+
method_setImplementation(method, original)
48+
imp_removeBlock(replacement)
49+
}
50+
}
51+
52+
guard case .performed = tapInAppBackControl(app: app) else {
53+
return XCTFail("the selected back control must dispatch")
54+
}
55+
let changed = expectation(for: NSPredicate(format: "label == %@", "Back performed"), evaluatedWith: status)
56+
wait(for: [changed], timeout: appExistenceTimeout)
57+
if navigationBar {
58+
XCTAssertEqual(xctestTaps, 1, "a navigation bar button keeps the element tap")
59+
} else {
60+
XCTAssertEqual(xctestTaps, 0, "a ranked back control uses synthesized dispatch without idle waits")
61+
}
62+
}
63+
#endif
64+
565
func testTopLeadingNavigationFallbackPointTargetsHeaderControlBand() throws {
666
let point = try XCTUnwrap(
767
Self.topLeadingNavigationFallbackPoint(

‎apple/snapshot-bridge/README.md‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ This directory contains the small private accessibility reader used by the
44
Apple platform acquisition facet. The framed server and request validation
55
live in `SnapshotBridge.m`; private runtime binding lives in
66
`SnapshotBridgeRuntime.m`. It is compiled for the iOS Simulator on first use
7-
and is never downloaded, pre-signed, or built by npm installation.
7+
and is never downloaded, pre-signed, or built by npm installation. It serves
8+
iPhone and iPad Simulators, which both run the iOS Simulator runtime (#3844).
89

910
The guest process uses the `XCTAccessibilityFramework` remote-access client
1011
from the simulator runtime and the `userTestingSnapshotForElement:options:error:`
@@ -49,6 +50,17 @@ not replace the native primary owner. An ownership refusal is evidence about
4950
the screen, so the route sends only that capture to XCTest and keeps the app
5051
generation on the bridge.
5152

53+
## Window placement
54+
55+
The snapshot API reports the frames of an app that runs in an iPadOS window
56+
(Windowed Apps or Stage Manager) relative to that window, not to the screen.
57+
Before acquisition, the reader compares the AXRuntime frame of the primary app
58+
with the frame of the system app. Both frames use the native space of the
59+
screen, also in landscape. If they differ, the reader returns `app-window-not-full-screen` without
60+
the app tree. Like an ownership refusal, this is evidence about the screen, so
61+
the route sends only that capture to XCTest. If the runtime cannot report either
62+
frame, the reader keeps the capture.
63+
5264
## Remote content
5365

5466
The reader snapshots one process. Two hosts put another process's UI into that

0 commit comments

Comments
 (0)