@@ -50,6 +50,7 @@ extension RunnerTests {
5050
5151 /// The session app's `XCUIApplication.State` by name. A lifecycle read: the activation preflight
5252 /// is skipped, so `runningBackground` after `home` is reported rather than repaired away.
53+ @ MainActor
5354 func executeAppState ( command : Command ) -> Response {
5455 guard let bundleId = command . appBundleId ? . trimmedNonEmpty else {
5556 return Response (
@@ -165,7 +166,7 @@ extension RunnerTests {
165166 return try runMainThreadWork (
166167 " command_execution " ,
167168 timeout : max ( 0.001 , deadline . timeIntervalSinceNow ) ,
168- timeoutError : mainThreadExecutionTimeoutError
169+ timeoutError : Self . mainThreadExecutionTimeoutError
169170 ) {
170171 try self . executeOnMainSafely (
171172 command : command ,
@@ -177,14 +178,15 @@ extension RunnerTests {
177178 return try runMainThreadWork (
178179 " command_execution " ,
179180 timeout : mainThreadExecutionTimeout ,
180- timeoutError : mainThreadExecutionTimeoutError
181+ timeoutError : Self . mainThreadExecutionTimeoutError
181182 ) {
182183 try self . executeOnMainSafely ( command : command , routeToSpringboard : routeToSpringboard )
183184 }
184185 }
185186
186187 // MARK: - Command Handling
187188
189+ @ MainActor
188190 private func executeOnMainSafely (
189191 command : Command ,
190192 alertDeadline : Date ? = nil ,
@@ -280,7 +282,7 @@ extension RunnerTests {
280282 let failureCountBefore = try runMainThreadWork (
281283 " recorded_failure_count " ,
282284 timeout : mainThreadExecutionTimeout ,
283- timeoutError : mainThreadExecutionTimeoutError
285+ timeoutError : Self . mainThreadExecutionTimeoutError
284286 ) {
285287 self . currentXCTestFailureCount ( )
286288 }
@@ -297,7 +299,7 @@ extension RunnerTests {
297299 let recordedFailureResponse = try runMainThreadWork (
298300 " recorded_failure_count " ,
299301 timeout : mainThreadExecutionTimeout ,
300- timeoutError : mainThreadExecutionTimeoutError
302+ timeoutError : Self . mainThreadExecutionTimeoutError
301303 ) {
302304 self . didRecordXCTestFailure ( since : failureCountBefore )
303305 ? self . xctestRecordedFailureResponse ( command : command , response : response )
@@ -307,7 +309,7 @@ extension RunnerTests {
307309 try runMainThreadWork (
308310 " target_invalidation " ,
309311 timeout : mainThreadExecutionTimeout ,
310- timeoutError : mainThreadExecutionTimeoutError
312+ timeoutError : Self . mainThreadExecutionTimeoutError
311313 ) {
312314 self . invalidateCachedTarget ( reason : " xctest_recorded_failure " )
313315 }
@@ -322,7 +324,7 @@ extension RunnerTests {
322324 try runMainThreadWork (
323325 " target_invalidation " ,
324326 timeout : mainThreadExecutionTimeout ,
325- timeoutError : mainThreadExecutionTimeoutError
327+ timeoutError : Self . mainThreadExecutionTimeoutError
326328 ) {
327329 self . invalidateCachedTarget ( reason : " response_unavailable " )
328330 self . sleepFor ( self . retryCooldown )
@@ -333,6 +335,7 @@ extension RunnerTests {
333335 }
334336 }
335337
338+ @ MainActor
336339 private func executeOnMain (
337340 command : Command ,
338341 alertDeadline : Date ? ,
@@ -438,7 +441,7 @@ extension RunnerTests {
438441 return Response ( ok : false , error : ErrorPayload ( message : " terminate requires appBundleId " ) )
439442 }
440443 XCUIApplication ( bundleIdentifier : bundleId ) . terminate ( )
441- if currentBundleId == bundleId {
444+ if mainOwned . bundleId == bundleId {
442445 invalidateCachedTarget ( reason : " target_terminated " )
443446 }
444447 return Response ( ok : true , data : DataPayload ( message : " app terminated " ) )
@@ -455,6 +458,7 @@ extension RunnerTests {
455458 /// The target this command runs against, decided by its `launchPolicy` (#2890). Exhaustive over the
456459 /// policy so a new case is a compile error here rather than a fall-through that quietly launches or
457460 /// quietly refuses.
461+ @ MainActor
458462 func prepareActiveCommandContext (
459463 command : Command ,
460464 routeToSpringboard : Bool = false
@@ -494,6 +498,7 @@ extension RunnerTests {
494498 /// place, and otherwise the requested session app is resolved and activated. What happens to a
495499 /// stopped app is the caller's `launchPolicy`; the `.existingApp` refusal belongs to
496500 /// `notRunningRefusal` because it is only meaningful once nothing is presented (#2890).
501+ @ MainActor
497502 private func prepareActivatedTarget ( command : Command ) -> ActiveCommandPreparation {
498503 if let presented = presentedSystemSurfaceHost ( ) {
499504 // Serve and drive the presented surface IN PLACE: never activate it (that cancels what it
@@ -514,7 +519,7 @@ extension RunnerTests {
514519 return . response ( notRunning )
515520 }
516521 if let bundleId = requestedBundleId {
517- if currentBundleId != bundleId || currentApp == nil {
522+ if mainOwned . bundleId != bundleId || mainOwned . app == nil {
518523 _ = activateTarget ( bundleId : bundleId , reason : " bundle_changed " )
519524 } else {
520525 refreshCachedTargetIfProcessChanged ( bundleId : bundleId )
@@ -525,7 +530,7 @@ extension RunnerTests {
525530 }
526531
527532 // Read back after the bundle resolution above, which is what may have just bound a target.
528- var activeApp = currentApp ?? app
533+ var activeApp = mainOwned . app ?? app
529534 if let bundleId = requestedBundleId , targetNeedsActivation ( activeApp ) {
530535 activeApp = activateTarget ( bundleId : bundleId , reason : " stale_target " )
531536 } else if requestedBundleId == nil , targetNeedsActivation ( activeApp ) {
@@ -616,6 +621,7 @@ extension RunnerTests {
616621 /// The one activation bypass that depends on the request rather than on the command: a tap that
617622 /// needs nothing the preflight would bring forward. Commands whose own classification answers
618623 /// without the session app's foreground state are handled by their `launchPolicy` (#2890).
624+ @ MainActor
619625 func shouldSkipAppActivationPreflight ( _ command : Command ) -> Bool {
620626#if os( iOS )
621627 // Coordinate-only synthesized taps can run after an AX-fatal foreground screen because they do not
@@ -664,25 +670,27 @@ extension RunnerTests {
664670 && command . y != nil
665671 }
666672
673+ @ MainActor
667674 private func hasCachedTargetForActivationSkip ( command : Command ) -> Bool {
668- guard let currentApp , currentApp . state == . runningForeground else { return false }
675+ guard let boundApp = mainOwned . app , boundApp . state == . runningForeground else { return false }
669676 guard let bundleId = command . appBundleId ? . trimmingCharacters ( in : . whitespacesAndNewlines ) ,
670677 ! bundleId . isEmpty
671678 else {
672679 return true
673680 }
674- return currentBundleId == bundleId
681+ return mainOwned . bundleId == bundleId
675682 }
676683
684+ @ MainActor
677685 func resolveAppWithoutActivation ( command : Command ) -> XCUIApplication {
678686 guard let bundleId = command . appBundleId ?
679687 . trimmingCharacters ( in : . whitespacesAndNewlines ) ,
680688 ! bundleId . isEmpty
681689 else {
682- return currentApp ?? app
690+ return mainOwned . app ?? app
683691 }
684- if currentBundleId == bundleId , let currentApp {
685- return currentApp
692+ if mainOwned . bundleId == bundleId , let boundApp = mainOwned . app {
693+ return boundApp
686694 }
687695 return XCUIApplication ( bundleIdentifier : bundleId )
688696 }
0 commit comments