@@ -54,6 +54,7 @@ enum SnapshotBackendKind: String, CaseIterable {
5454
5555enum SnapshotXCTestChannelPlanState : Equatable {
5656 case normal
57+ case preferredIndependentBackend
5758 case deferredToIndependentBackend
5859 case boundedXCTestProbe
5960}
@@ -150,16 +151,34 @@ extension RunnerTests {
150151 static func effectiveSnapshotCapturePlan (
151152 _ plan : [ SnapshotBackendKind ] ,
152153 xCTestChannelPenalized : Bool ,
153- availableBackends : Set < SnapshotBackendKind > = Set ( SnapshotBackendKind . allCases )
154+ availableBackends : Set < SnapshotBackendKind > = Set ( SnapshotBackendKind . allCases ) ,
155+ preferIndependentBackend : Bool = false
154156 ) -> EffectiveSnapshotCapturePlan {
155- guard xCTestChannelPenalized , plan == Self . regularVisiblePlan else {
157+ guard plan == Self . regularVisiblePlan else {
156158 return EffectiveSnapshotCapturePlan (
157159 plan : plan ,
158160 xCTestChannelState : . normal ,
159161 treeCaptureSliceBudgetOverride : nil
160162 )
161163 }
162164 let availablePlan = plan . filter { availableBackends . contains ( $0 ) }
165+ if preferIndependentBackend && ! xCTestChannelPenalized {
166+ let independentPlan = availablePlan . filter { ! $0 . usesXCTestAccessibilityChannel }
167+ if ! independentPlan . isEmpty {
168+ return EffectiveSnapshotCapturePlan (
169+ plan : independentPlan + availablePlan . filter ( \. usesXCTestAccessibilityChannel ) ,
170+ xCTestChannelState : . preferredIndependentBackend ,
171+ treeCaptureSliceBudgetOverride : nil
172+ )
173+ }
174+ }
175+ guard xCTestChannelPenalized else {
176+ return EffectiveSnapshotCapturePlan (
177+ plan : availablePlan ,
178+ xCTestChannelState : . normal ,
179+ treeCaptureSliceBudgetOverride : nil
180+ )
181+ }
163182 let recoveryPlan = availablePlan . filter { ! $0 . usesXCTestAccessibilityChannel }
164183 if ! recoveryPlan . isEmpty {
165184 return EffectiveSnapshotCapturePlan (
@@ -205,12 +224,19 @@ extension RunnerTests {
205224 let effective = Self . effectiveSnapshotCapturePlan (
206225 plan ,
207226 xCTestChannelPenalized : xCTestChannelPenalized ,
208- availableBackends : Set ( SnapshotBackendKind . allCases . filter ( \. isAvailableOnCurrentPlatform ) )
227+ availableBackends : Set ( SnapshotBackendKind . allCases . filter ( \. isAvailableOnCurrentPlatform ) ) ,
228+ preferIndependentBackend : options . preferIndependentBackend
209229 )
210230 let effectivePlan = effective . plan
211231 switch effective . xCTestChannelState {
212232 case . normal :
213233 break
234+ case . preferredIndependentBackend :
235+ firstFailure = (
236+ " an independent accessibility backend was preferred to verify post-gesture freshness " ,
237+ " freshness "
238+ )
239+ NSLog ( " AGENT_DEVICE_RUNNER_SNAPSHOT_INDEPENDENT_BACKEND_PREFERRED bundle=%@ " , currentBundleId ?? " " )
214240 case . deferredToIndependentBackend :
215241 firstFailure = (
216242 " XCTest-backed snapshot tiers were deferred after recent slow accessibility work on this screen " ,
@@ -301,7 +327,10 @@ extension RunnerTests {
301327 continue
302328 }
303329
304- let recovered = kind != effectivePlan . first || effective . xCTestChannelState != . normal
330+ let recovered =
331+ kind != effectivePlan . first
332+ || effective . xCTestChannelState == . deferredToIndependentBackend
333+ || effective . xCTestChannelState == . boundedXCTestProbe
305334 if recovered {
306335 NSLog (
307336 " AGENT_DEVICE_RUNNER_SNAPSHOT_RECOVERED backend=%@ reason=%@ " ,
@@ -687,6 +716,28 @@ extension RunnerTests {
687716 )
688717 }
689718
719+ func testEffectiveSnapshotCapturePlanPrefersIndependentBackendForFreshnessProbe ( ) {
720+ let simulatorPlan = Self . effectiveSnapshotCapturePlan (
721+ Self . regularVisiblePlan ,
722+ xCTestChannelPenalized : false ,
723+ preferIndependentBackend : true
724+ )
725+
726+ XCTAssertEqual ( simulatorPlan . plan , [ . privateAX , . recursiveTree , . querySweep ] )
727+ XCTAssertEqual ( simulatorPlan . xCTestChannelState , . preferredIndependentBackend )
728+ XCTAssertNil ( simulatorPlan . treeCaptureSliceBudgetOverride )
729+
730+ let physicalDevicePlan = Self . effectiveSnapshotCapturePlan (
731+ Self . regularVisiblePlan ,
732+ xCTestChannelPenalized : false ,
733+ availableBackends : [ . recursiveTree , . querySweep ] ,
734+ preferIndependentBackend : true
735+ )
736+
737+ XCTAssertEqual ( physicalDevicePlan . plan , [ . recursiveTree , . querySweep ] )
738+ XCTAssertEqual ( physicalDevicePlan . xCTestChannelState , . normal )
739+ }
740+
690741 func testSnapshotXCTestChannelPenaltyMatchesBundleAndExpires ( ) {
691742 defer {
692743 snapshotXCTestChannelPenaltyBundleId = nil
0 commit comments