Skip to content

Commit 8cbd747

Browse files
committed
refactor(ios): own the pin verdict rule in planVerdictReason
The requested-backend answer moves to its own producer (snapshotPlanPreSelectionReason), xcTestChannelStateFirstFailure returns only failure seeds, and planVerdictReason takes a preSelection parameter and owns the firstFailure ?? preSelection rule. This deletes the string-code filter and both call-site ?? sites. The tree-pin rejection test now asserts the accessibilityHealth == .unavailable side effect, and the private-AX pin test asserts its requested-backend pre-selection seeds no failure.
1 parent 5536e6d commit 8cbd747

4 files changed

Lines changed: 100 additions & 40 deletions

File tree

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

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -235,34 +235,19 @@ extension RunnerTests {
235235
///
236236
/// `requestPinnedBackend` separates the two ways the plan can arrive at the same
237237
/// deferred shape. A capture that ASKED for a private-AX-only reading (custom
238-
/// actions) degraded nothing, so reporting slow accessibility work would name a
239-
/// cause that does not exist.
240-
///
241-
/// The 'requested-backend' answer names a plan decision, not a failure, so the runner carries
242-
/// it in its own slot (`preSelectionReason`) and a tier that actually failed replaces it as the
243-
/// verdict reason. The breaker's 'deferred' and 'budget' answers stay first-failure seeds: a
244-
/// deferred plan reports the pre-selection until its bounded probe's tier runs; then the verdict
245-
/// reports that probe's 'budget' constraint.
238+
/// actions) degraded nothing, so it seeds no failure at all — reporting slow
239+
/// accessibility work would name a cause that does not exist. Its answer comes from
240+
/// `snapshotPlanPreSelectionReason`.
246241
static func xcTestChannelStateFirstFailure(
247242
_ state: SnapshotXCTestChannelPlanState,
248-
requestPinnedBackend: Bool = false,
249-
preferredBackend: String? = nil
243+
requestPinnedBackend: Bool = false
250244
) -> (reason: String, code: String)? {
251-
if state == .normal && preferredBackend == SnapshotBackendKind.recursiveTree.rawValue {
252-
return (
253-
"the recursive XCTest tree backend was explicitly selected for this capture",
254-
"requested-backend"
255-
)
256-
}
257245
switch state {
258246
case .normal:
259247
return nil
260248
case .deferredToIndependentBackend:
261249
if requestPinnedBackend {
262-
return (
263-
"the private AX backend was selected because this capture asked for accessibility custom actions",
264-
"requested-backend"
265-
)
250+
return nil
266251
}
267252
return (
268253
"XCTest-backed snapshot tiers were deferred after recent slow accessibility work on this screen",
@@ -276,16 +261,42 @@ extension RunnerTests {
276261
}
277262
}
278263

279-
/// The reason a capture's verdict carries. Once an XCTest-backed tier ran behind a deferred plan,
264+
/// The 'requested-backend' answer for a plan the request itself pinned: the recursive tree the
265+
/// caller asked for, or the private AX the custom-actions reading requires. A pin names a plan
266+
/// decision, not a failure, so it never enters the failure slot; `planVerdictReason` reports it
267+
/// only while no tier failed on this capture.
268+
static func snapshotPlanPreSelectionReason(
269+
_ state: SnapshotXCTestChannelPlanState,
270+
requestPinnedBackend: Bool = false,
271+
preferredBackend: String? = nil
272+
) -> (reason: String, code: String)? {
273+
if state == .normal && preferredBackend == SnapshotBackendKind.recursiveTree.rawValue {
274+
return (
275+
"the recursive XCTest tree backend was explicitly selected for this capture",
276+
"requested-backend"
277+
)
278+
}
279+
if state == .deferredToIndependentBackend && requestPinnedBackend {
280+
return (
281+
"the private AX backend was selected because this capture asked for accessibility custom actions",
282+
"requested-backend"
283+
)
284+
}
285+
return nil
286+
}
287+
288+
/// The reason a capture's verdict carries: the first tier failure when one exists, otherwise the
289+
/// pre-selection the plan started with. Once an XCTest-backed tier ran behind a deferred plan,
280290
/// it ran on the bounded probe's short slice, so the capture reports that constraint ('budget')
281291
/// whether the tier recovered it or the plan ended sparse, rather than the pre-selection
282292
/// ('deferred') the plan was seeded with.
283293
static func planVerdictReason(
284294
xCTestTierRan: Bool,
285295
state: SnapshotXCTestChannelPlanState,
286-
firstFailure: (reason: String, code: String)?
296+
firstFailure: (reason: String, code: String)?,
297+
preSelection: (reason: String, code: String)?
287298
) -> (reason: String, code: String)? {
288-
guard xCTestTierRan, state == .deferredToIndependentBackend else { return firstFailure }
299+
guard xCTestTierRan, state == .deferredToIndependentBackend else { return firstFailure ?? preSelection }
289300
return xcTestChannelStateFirstFailure(.boundedXCTestProbe)
290301
}
291302

@@ -404,18 +415,20 @@ extension RunnerTests {
404415
preferredBackend: options.preferredBackend
405416
)
406417
let effectivePlan = effective.plan
407-
// The pin seed must not occupy the failure slot: a tier that failed on this capture owns
408-
// the verdict reason there, and the pre-selection is reported only when nothing failed
409-
// (see xcTestChannelStateFirstFailure). Only a customActions-implied pin is request-pinned;
410-
// the daemon's same-backend evidence probe pins for its own reasons and keeps 'deferred'.
411-
let preSelectionReason = Self.xcTestChannelStateFirstFailure(
418+
// A request pin answers through its own slot, never the failure slot: a tier that failed on
419+
// this capture owns the verdict reason there, and planVerdictReason falls back to the pin only
420+
// when nothing failed. Only a customActions-implied pin is request-pinned; the daemon's
421+
// same-backend evidence probe pins for its own reasons and keeps its 'deferred' seed.
422+
let requestPinnedBackend = options.customActions && !xCTestChannelPenalizedByBreaker
423+
firstFailure = Self.xcTestChannelStateFirstFailure(
412424
effective.xCTestChannelState,
413-
requestPinnedBackend: options.customActions && !xCTestChannelPenalizedByBreaker,
425+
requestPinnedBackend: requestPinnedBackend
426+
)
427+
let preSelectionReason = Self.snapshotPlanPreSelectionReason(
428+
effective.xCTestChannelState,
429+
requestPinnedBackend: requestPinnedBackend,
414430
preferredBackend: effective.preferredBackend?.rawValue
415431
)
416-
if preSelectionReason?.code != "requested-backend" {
417-
firstFailure = preSelectionReason
418-
}
419432
switch effective.xCTestChannelState {
420433
case .normal:
421434
break
@@ -500,7 +513,8 @@ extension RunnerTests {
500513
let verdictReason = Self.planVerdictReason(
501514
xCTestTierRan: kind.usesXCTestAccessibilityChannel,
502515
state: effective.xCTestChannelState,
503-
firstFailure: firstFailure ?? preSelectionReason
516+
firstFailure: firstFailure,
517+
preSelection: preSelectionReason
504518
)
505519
if recovered {
506520
NSLog(
@@ -539,7 +553,8 @@ extension RunnerTests {
539553
let terminalReason = Self.planVerdictReason(
540554
xCTestTierRan: xCTestTierRan,
541555
state: effective.xCTestChannelState,
542-
firstFailure: firstFailure ?? preSelectionReason
556+
firstFailure: firstFailure,
557+
preSelection: preSelectionReason
543558
)
544559
let fallbackPayload =
545560
best.map { stampedSnapshotPayload($0.capture, backend: $0.kind, state: .sparse, reason: terminalReason) }

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,15 @@ extension RunnerTests {
170170
}
171171

172172
/// A request-pinned backend degraded nothing, so its verdict must not claim
173-
/// slow accessibility work — that reason drives a user-facing warning.
173+
/// slow accessibility work — that reason drives a user-facing warning. The pin
174+
/// answers through the pre-selection producer and seeds no failure.
174175
func testRequestPinnedBackendReportsItsOwnReason() {
175-
let requested = Self.xcTestChannelStateFirstFailure(
176+
let requested = Self.snapshotPlanPreSelectionReason(
176177
.deferredToIndependentBackend, requestPinnedBackend: true)
177178
XCTAssertEqual(requested?.code, "requested-backend")
178179
XCTAssertFalse(requested?.reason.contains("slow accessibility work") ?? true)
180+
XCTAssertNil(Self.xcTestChannelStateFirstFailure(
181+
.deferredToIndependentBackend, requestPinnedBackend: true))
179182

180183
// The circuit breaker's own deferral keeps its established code and wording.
181184
let breaker = Self.xcTestChannelStateFirstFailure(.deferredToIndependentBackend)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,9 @@ extension RunnerTests {
562562
"the tier's own rejection must replace the pin seed: \(quality.reason ?? "nil")"
563563
)
564564
XCTAssertEqual(quality.backend, SnapshotBackendKind.recursiveTree.rawValue)
565+
// The rejected verdict also declares the channel unavailable, which gates the
566+
// synthesized-gesture probe and the XCTest coordinate fallback (#3885 follow-up).
567+
XCTAssertEqual(mainOwned.accessibilityHealth, .unavailable)
565568
}
566569

567570
/// The healthy side of the same pin: a tree that answers keeps reporting the pin itself as the

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

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,13 @@ extension RunnerTests {
444444
XCTAssertEqual(forced.plan, [.recursiveTree])
445445
XCTAssertEqual(forced.xCTestChannelState, .normal)
446446
XCTAssertEqual(
447-
Self.xcTestChannelStateFirstFailure(
447+
Self.snapshotPlanPreSelectionReason(
448448
forced.xCTestChannelState,
449449
preferredBackend: forced.preferredBackend?.rawValue
450450
)?.code,
451451
"requested-backend"
452452
)
453+
XCTAssertNil(Self.xcTestChannelStateFirstFailure(forced.xCTestChannelState))
453454
}
454455

455456
/// Same-backend evidence probes: a daemon-pinned private-AX capture takes the
@@ -476,6 +477,18 @@ extension RunnerTests {
476477
)
477478
XCTAssertEqual(pinned.plan, [.privateAX])
478479
XCTAssertEqual(pinned.xCTestChannelState, .deferredToIndependentBackend)
480+
// The requested-backend rule covers this pin too: it answers through the pre-selection
481+
// slot and seeds no failure, so a failing private-AX tier owns the verdict reason.
482+
XCTAssertEqual(
483+
Self.snapshotPlanPreSelectionReason(
484+
pinned.xCTestChannelState,
485+
requestPinnedBackend: true,
486+
preferredBackend: pinned.preferredBackend?.rawValue
487+
)?.code,
488+
"requested-backend"
489+
)
490+
XCTAssertNil(Self.xcTestChannelStateFirstFailure(
491+
pinned.xCTestChannelState, requestPinnedBackend: true))
479492
}
480493

481494
func testEffectiveSnapshotCapturePlanPutsXCTestBackedTiersBehindPrivateAXOnlyWhenPenalizedRegularPlan() {
@@ -509,17 +522,43 @@ extension RunnerTests {
509522
let deferred = Self.xcTestChannelStateFirstFailure(.deferredToIndependentBackend)
510523
XCTAssertEqual(
511524
Self.planVerdictReason(
512-
xCTestTierRan: true, state: .deferredToIndependentBackend, firstFailure: deferred
525+
xCTestTierRan: true, state: .deferredToIndependentBackend,
526+
firstFailure: deferred, preSelection: deferred
513527
)?.code,
514528
"budget"
515529
)
530+
}
531+
532+
func testPlanVerdictReasonPrefersTheFirstFailureOverThePreSelection() {
533+
let deferred = Self.xcTestChannelStateFirstFailure(.deferredToIndependentBackend)
534+
let pin = Self.snapshotPlanPreSelectionReason(
535+
.normal, preferredBackend: SnapshotBackendKind.recursiveTree.rawValue)
536+
XCTAssertEqual(pin?.code, "requested-backend")
537+
// Nothing failed: the pre-selection owns the verdict.
516538
XCTAssertEqual(
517539
Self.planVerdictReason(
518-
xCTestTierRan: false, state: .deferredToIndependentBackend, firstFailure: deferred
540+
xCTestTierRan: false, state: .deferredToIndependentBackend,
541+
firstFailure: nil, preSelection: deferred
519542
)?.code,
520543
"deferred"
521544
)
522-
XCTAssertNil(Self.planVerdictReason(xCTestTierRan: true, state: .normal, firstFailure: nil))
545+
XCTAssertEqual(
546+
Self.planVerdictReason(
547+
xCTestTierRan: true, state: .normal,
548+
firstFailure: nil, preSelection: pin
549+
)?.code,
550+
"requested-backend"
551+
)
552+
// A tier failed: it owns the verdict, and a healthy plan with no seed stays silent.
553+
XCTAssertEqual(
554+
Self.planVerdictReason(
555+
xCTestTierRan: true, state: .normal,
556+
firstFailure: ("rejected", "ax-rejected"), preSelection: pin
557+
)?.code,
558+
"ax-rejected"
559+
)
560+
XCTAssertNil(Self.planVerdictReason(
561+
xCTestTierRan: true, state: .normal, firstFailure: nil, preSelection: nil))
523562
}
524563

525564
func testEffectiveSnapshotCapturePlanUsesBoundedXCTestProbeWhenNoIndependentBackendRuns() {

0 commit comments

Comments
 (0)