Skip to content

Commit 81b9bf5

Browse files
committed
feat(ios): decide the presented surface from a captured tree (#3565)
Add the rule that answers whether an iOS capture read a modal presentation over the app's own content, the golden table that pins it, and the publication that carries its answer, so the rule has a production consumer the moment it lands. The rule reads a dimming view without its enablement, unlike the occlusion cut that shares the same container class: a sheet resting at an undimmed detent keeps a dimming view that takes no touches and is still presented. `absent` is the strong answer and never the default, because a consumer arms a dismissal confirmation on it. It requires that the producer stated the capture was not capped, that every node carries the UIKit class name the rule reads, that each node is numbered once so the parent links the walk follows name the node they mean, and that the one content window under the app root holds exactly one presentation container. Positive evidence — the dimming view a presentation owns, an alert's own root class, or an element type that names a presentation — answers `presented` from a single node, so a capped capture still reports what it read. Producers that publish no class names, which is every XCTest runner tier, answer `presented` or `unknown` and never `absent`. The rule lives in `geometry-policy.ts` beside the occlusion cut rather than in `engine.ts`, because that module already owns the UIKit presentation vocabulary both readers consume and `geometry.ts` already imports it on the engine's eager path, so the placement costs nothing and leaves one module to change when UIKit does. Both readers now match class names through the same normalization, so a producer that spells a class with a module prefix cannot reach one answer in the occlusion cut and another here. Evidence is matched on the node occurrence a walk stood on, not on the number it carries, so a keyboard host's subtree cannot swallow an app window's own dimming view; only `absent`, a claim about every window the producer read, requires numbering that identifies each node once. The publication is in this layer rather than one up because `check:production-exports` refuses an exported rule with no production consumer, and a layer that ships a decision nobody can read is not a layer that passes. The Apple runner's Swift twin and its own consumer land in the next layer, where the runner acquires trees; both languages read the one fixture published here.
1 parent ecd8cb6 commit 81b9bf5

6 files changed

Lines changed: 539 additions & 13 deletions

File tree

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,29 @@ struct SnapshotBackendCapture {
8686
/// tree tier reads the keyboard, so only that tier has one; the daemon reads a missing band as "this
8787
/// producer could not measure", which is exactly what the query-sweep and private-AX tiers did.
8888
var keyboardBand: KeyboardBandFactPayload? = nil
89+
/// Whether this capture read a modal presentation over the app (#3565), classified on the
90+
/// acquisition this capture presents. A tier that classified nothing carries nothing, and the host
91+
/// reads that as no evidence rather than as absence.
92+
var presentedSurface: PresentedSurface? = nil
8993
}
9094

9195
extension RunnerTests {
96+
/// Assembles what one tier answered, from the tree it presented and the acquisition it read. The
97+
/// presented-surface fact is classified on the acquisition rather than the presentation, because
98+
/// interactive filtering, depth and scope are all cuts into what the tier actually saw (#3565): a
99+
/// capture of a presented screen that kept four nodes still read the presentation.
92100
static func makeSnapshotBackendCapture(
93-
from result: AgentDeviceSnapshotPresentation.SnapshotPresentationResult
101+
from result: AgentDeviceSnapshotPresentation.SnapshotPresentationResult,
102+
acquired acquisition: SnapshotAcquisition
94103
) -> SnapshotBackendCapture {
95104
SnapshotBackendCapture(
96105
payload: DataPayload(nodes: result.nodes, truncated: result.truncated),
97106
effectiveDepth: result.effectiveDepth,
98107
customActions: result.customActions,
99108
qualityPayload: result.qualityNodes.map {
100109
DataPayload(nodes: $0, truncated: result.truncated)
101-
}
110+
},
111+
presentedSurface: SnapshotPresentedSurface.classify(acquisition)
102112
)
103113
}
104114

@@ -576,7 +586,7 @@ extension RunnerTests {
576586
acquired: normalizedAcquisition.hint.projection
577587
)
578588
}
579-
return Self.makeSnapshotBackendCapture(from: result)
589+
return Self.makeSnapshotBackendCapture(from: result, acquired: normalizedAcquisition)
580590
}
581591
} catch let failure as SnapshotPresentationFailure {
582592
return SnapshotBackendAttempt(
@@ -754,6 +764,7 @@ extension RunnerTests {
754764
return SnapshotQualityPayload(nodes: nodes, truncated: quality.truncated == true)
755765
},
756766
snapshotQuality: quality,
767+
presentedSurface: capture.presentedSurface,
757768
keyboard: capture.keyboardBand,
758769
runnerFatal: payload.runnerFatal,
759770
runnerFatalReason: payload.runnerFatalReason

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

Lines changed: 85 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -269,24 +269,99 @@ extension RunnerTests {
269269
XCTAssertNil(payload.qualityPayload?.scope)
270270
}
271271

272+
/// The classification has to happen on the acquisition a tier read, not on the presentation the tier
273+
/// returns, and survive onto the response envelope. This drives the production assembly function with a
274+
/// tree that keeps only what the runner's own AX tier publishes — no UIKit class names, an element type
275+
/// the runner's name table cannot spell — and asks for a capture that dropped every node the acquisition
276+
/// held. Deleting the classification, or reading the presented tree instead of the acquired one, fails
277+
/// it (#3565).
278+
func testSnapshotCaptureAssemblyClassifiesTheAcquisitionItPresented() throws {
279+
let options = PresentationOptions(interactiveOnly: true, depth: nil, scope: nil, raw: false)
280+
let evidenceIndex = 2
281+
let acquisition = SnapshotAcquisition(
282+
hint: SnapshotPresentation.captureHint(for: options),
283+
nodes: [
284+
planTestRawNode(index: 0, type: "Application", parentIndex: nil),
285+
planTestRawNode(index: 1, type: "Window", parentIndex: 0),
286+
planTestRawNode(index: evidenceIndex, type: "Element(7)", parentIndex: 1),
287+
],
288+
truncated: false,
289+
effectiveDepth: nil,
290+
viewport: .reported(box: CGRect(x: 0, y: 0, width: 402, height: 874))
291+
)
292+
let presented = try SnapshotPresentation.presentRegular(acquisition, options: options)
293+
// The premise the assertion below turns on, pinned rather than assumed: this is the node the
294+
// evidence sits on, and the tier's own presentation does not carry it. Were it retained, the two
295+
// trees would agree and the next line would stop proving which one was read.
296+
XCTAssertFalse(
297+
presented.nodes.contains { $0.index == evidenceIndex },
298+
"the presentation has to drop the evidence node, or this test cannot tell the two trees apart"
299+
)
300+
301+
let capture = Self.makeSnapshotBackendCapture(from: presented, acquired: acquisition)
302+
XCTAssertEqual(capture.presentedSurface, .presented, "positive evidence below the presented cut")
303+
304+
// The same presentation assembled against an acquisition that holds no evidence must answer from
305+
// the acquisition. If the classifier ever read the presented tree instead, this pair collapses to
306+
// the same answer and the assertion above stops proving anything.
307+
let cleared = acquisition.replacingNodes([
308+
planTestRawNode(index: 0, type: "Application", parentIndex: nil)
309+
])
310+
XCTAssertEqual(
311+
Self.makeSnapshotBackendCapture(from: presented, acquired: cleared).presentedSurface,
312+
.unknown,
313+
"the fact follows the acquisition, not the presentation it produced"
314+
)
315+
316+
let payload = stampedSnapshotPayload(capture, backend: .recursiveTree, state: .healthy, reason: nil)
317+
XCTAssertEqual(payload.presentedSurface, .presented)
318+
// A tier that assembled no fact publishes nothing: silence is how the host reads "this producer
319+
// published no fact", and it must not be reachable by a default.
320+
XCTAssertNil(
321+
stampedSnapshotPayload(
322+
SnapshotBackendCapture(payload: capture.payload, effectiveDepth: nil),
323+
backend: .recursiveTree,
324+
state: .healthy,
325+
reason: nil
326+
).presentedSurface
327+
)
328+
}
329+
330+
private func planTestRawNode(index: Int, type: String, parentIndex: Int?) -> RawAXNode {
331+
RawAXNode(
332+
index: index,
333+
type: type,
334+
label: nil,
335+
identifier: nil,
336+
value: nil,
337+
rect: SnapshotRect(x: 0, y: 0, width: 10, height: 10),
338+
enabled: true,
339+
focused: nil,
340+
selected: nil,
341+
hittable: nil,
342+
depth: parentIndex == nil ? 0 : 1,
343+
parentIndex: parentIndex,
344+
hiddenContentAbove: nil,
345+
hiddenContentBelow: nil
346+
)
347+
}
348+
272349
func testDirectPresentationDoesNotClaimPlanTiming() {
273350
let options = PresentationOptions(
274351
interactiveOnly: false,
275352
depth: nil,
276353
scope: nil,
277354
raw: true
278355
)
279-
let result = SnapshotPresentation.presentRaw(
280-
SnapshotAcquisition(
281-
hint: SnapshotPresentation.captureHint(for: options),
282-
nodes: [],
283-
truncated: false,
284-
effectiveDepth: nil,
285-
viewport: .reported(box: CGRect(x: 0, y: 0, width: 402, height: 874))
286-
),
287-
options: options
356+
let acquisition = SnapshotAcquisition(
357+
hint: SnapshotPresentation.captureHint(for: options),
358+
nodes: [],
359+
truncated: false,
360+
effectiveDepth: nil,
361+
viewport: .reported(box: CGRect(x: 0, y: 0, width: 402, height: 874))
288362
)
289-
let capture = Self.makeSnapshotBackendCapture(from: result)
363+
let result = SnapshotPresentation.presentRaw(acquisition, options: options)
364+
let capture = Self.makeSnapshotBackendCapture(from: result, acquired: acquisition)
290365

291366
let payload = stampedSnapshotPayload(
292367
capture,

0 commit comments

Comments
 (0)