Repository navigation
feat(ios): replay recorded alert surfaces on the host #4115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -235,15 +235,11 @@ | |||||||||||||
| var textInputProbeIssues: TextInputProbeIssues? | ||||||||||||||
| let suppressedIssueLock = NSLock() | ||||||||||||||
| var suppressedAxSnapshotIssueCount = 0 | ||||||||||||||
| // Keep blocker actions narrow to avoid false positives from generic hittable containers. | ||||||||||||||
| let actionableTypes: Set<XCUIElement.ElementType> = [ | ||||||||||||||
| .button, | ||||||||||||||
| .cell, | ||||||||||||||
| .link, | ||||||||||||||
| .menuItem, | ||||||||||||||
| .checkBox, | ||||||||||||||
| .switch | ||||||||||||||
| ] | ||||||||||||||
| let actionableTypes: Set<XCUIElement.ElementType> = Set( | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Minor · Runner
Suggested change
Suggested change Assert the invariant instead of trusting it: a unit test that every name in DetailsAlso raised hereAlso raised at this location by senior-developer: Runner actionableTypes now depends on unenforced string equality between two tables — Also raised at this location by swift-ios: actionableTypes now derived through string names, so a name divergence silently drops an element type — RunnerTests.actionableTypes was a literal set of six XCUIElement.ElementType values. It is now rebuilt by matching Also raised at this location by maintainability: RunnerTests.actionableTypes is now derived from a name table with nothing pinning the six names — RunnerTests.swift:238-242 replaces the literal persona: Reply Useful? Reply |
||||||||||||||
| RunnerTests.elementTypeNamesByRawValue.compactMap { rawValue, name in | ||||||||||||||
| AlertSurface.actionableTypes.contains(name) ? XCUIElement.ElementType(rawValue: rawValue) : nil | ||||||||||||||
| } | ||||||||||||||
| ) | ||||||||||||||
|
Check warning on line 242 in apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift
|
||||||||||||||
|
|
||||||||||||||
| // MARK: - XCTest Entry | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import XCTest | ||
| import AgentDeviceSnapshotPresentation | ||
|
|
||
| #if AGENT_DEVICE_RUNNER_UNIT_TESTS | ||
| /// A frame as the corpus spells it: the `FixtureRect` spelling, so an unusable box is named. | ||
| private struct RecordedAlertSurfaceRect: Encodable { | ||
| let frame: CGRect | ||
|
|
||
| func encode(to encoder: Encoder) throws { | ||
| var container = encoder.container(keyedBy: CodingKeys.self) | ||
| if frame.isInfinite { | ||
| try container.encode(true, forKey: .infinite) | ||
| } else if ![frame.minX, frame.minY, frame.width, frame.height].allSatisfy(\.isFinite) { | ||
| try container.encode(true, forKey: .nonFinite) | ||
| } else { | ||
| try container.encode(frame.minX, forKey: .x) | ||
| try container.encode(frame.minY, forKey: .y) | ||
| try container.encode(frame.width, forKey: .width) | ||
| try container.encode(frame.height, forKey: .height) | ||
| } | ||
| } | ||
|
|
||
| private enum CodingKeys: String, CodingKey { | ||
| case x, y, width, height, infinite, nonFinite | ||
| } | ||
| } | ||
|
|
||
| private struct RecordedAlertSurfaceNode: Encodable { | ||
| let index: Int | ||
| let parentIndex: Int? | ||
| let type: String | ||
| let identifier: String | ||
| let label: String | ||
| let rect: RecordedAlertSurfaceRect | ||
| } | ||
|
|
||
| extension RunnerTests { | ||
| /// Records an app's whole accessibility tree for the alert surface corpus. It runs only from | ||
| /// `pnpm capture:alert-surface`, which sets the bundle and the output path. | ||
| @MainActor | ||
| func testCaptureAlertSurfaceTree() throws { | ||
| let environment = ProcessInfo.processInfo.environment | ||
| guard let bundleId = environment["AGENT_DEVICE_ALERT_SURFACE_BUNDLE_ID"], | ||
| let output = environment["AGENT_DEVICE_ALERT_SURFACE_OUTPUT"] | ||
| else { | ||
| throw XCTSkip("Run through pnpm capture:alert-surface") | ||
| } | ||
| let snapshot = try XCUIApplication(bundleIdentifier: bundleId).snapshot() | ||
| var nodes: [RecordedAlertSurfaceNode] = [] | ||
| func record(_ node: AlertSurfaceNode, parentIndex: Int?) { | ||
| let index = nodes.count | ||
| nodes.append(RecordedAlertSurfaceNode( | ||
| index: index, | ||
| parentIndex: parentIndex, | ||
| type: node.type, | ||
| identifier: node.identifier, | ||
| label: node.label, | ||
| rect: RecordedAlertSurfaceRect(frame: node.frame) | ||
| )) | ||
| node.children.forEach { record($0, parentIndex: index) } | ||
| } | ||
| record(alertSurfaceNode(snapshot), parentIndex: nil) | ||
| let encoder = JSONEncoder() | ||
| encoder.outputFormatting = [.sortedKeys] | ||
| try encoder.encode(nodes).write(to: URL(fileURLWithPath: output)) | ||
| } | ||
| } | ||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import XCTest | ||
| import AgentDeviceSnapshotPresentation | ||
|
|
||
| #if AGENT_DEVICE_RUNNER_UNIT_TESTS | ||
| extension RunnerTests { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔵 Nit · observeAlert converts the whole snapshot tree into AlertSurfaceNode structs on every verification poll
observeAlertnow builds anAlertSurfaceNodefor every node of the owner app's snapshot tree (alertSurfaceNode(snapshot)at RunnerTests+AlertObservation.swift:40) before it applies any rule, andhandleAlertre-runsobserveAlertin a loop every 0.2 s until the deadline (while trueat RunnerTests+Alert.swift:118-131). The predecessor walkedXCUIElementSnapshotin place, so the only allocation was the[XCUIElementSnapshot]candidate array, and it stopped recursing once a match was found. Each converted node allocates a struct holding two SwiftStrings (identifier, label) plus a children array, so a SpringBoard tree of the size in the corpus (254 nodes, many with long labels) is deep-copied on each poll for the whole alert budget — up to ~50 full-tree copies for the default 10 sdefaultAlertCommandTimeout, all on the main actor while the app is still settling.captureAlertPresentationpays the same conversion once peralert accept. Nothing is incorrect today; the cost is new and it lands on the slow path the surrounding comments already care about (a starved host delaying reads).AlertSurface.candidatescould take the snapshot tree through a protocol/accessor, or the conversion could stop descending once a candidate is found.Suggested change
Avoid rebuilding the whole tree as AlertSurfaceNode per observation poll: either give AlertSurface a view over XCUIElementSnapshot, or reuse one conversion across the verification loop when the tree is unchanged.
Details
persona:
swift-iosReply
@apex-sentinel-staging note ...to add context, or@apex-sentinel-staging pivot ...if this is wrong — I will re-check the cited code.Useful? Reply
@apex-sentinel-staging like, or@apex-sentinel-staging dislike <why>if it is not.