@@ -180,6 +180,7 @@ extension RunnerTests {
180180
181181 // MARK: - Target Activation
182182
183+ @ MainActor
183184 func ensureRunnerHostAppActive ( reason : String ) {
184185 NSLog (
185186 " AGENT_DEVICE_RUNNER_HOST_ACTIVATE state=%d reason=%@ " ,
@@ -191,9 +192,9 @@ extension RunnerTests {
191192 } else if app . state != . runningForeground {
192193 app . activate ( )
193194 }
194- currentApp = app
195- currentBundleId = nil
196- currentAppProcessIdentifier = nil
195+ mainOwned . app = app
196+ mainOwned . bundleId = nil
197+ mainOwned . processIdentifier = nil
197198 resetTargetBoundState ( )
198199 }
199200
@@ -207,16 +208,18 @@ extension RunnerTests {
207208 lastLoggedGesturePolicyLines . removeAll ( )
208209 }
209210
211+ @ MainActor
210212 func invalidateCachedTarget ( reason : String ) {
211- if currentApp != nil || currentBundleId != nil {
213+ if mainOwned . app != nil || mainOwned . bundleId != nil {
212214 NSLog ( " AGENT_DEVICE_RUNNER_TARGET_CACHE_INVALIDATE reason=%@ " , reason )
213215 }
214- currentApp = nil
215- currentBundleId = nil
216- currentAppProcessIdentifier = nil
216+ mainOwned . app = nil
217+ mainOwned . bundleId = nil
218+ mainOwned . processIdentifier = nil
217219 resetTargetBoundState ( )
218220 }
219221
222+ @ MainActor
220223 func resetTargetAfterExternalRelaunch ( ) -> Response {
221224 invalidateCachedTarget ( reason : " external_app_relaunch " )
222225 // The app process is replaced, but the retained runner survives. Clear
@@ -228,22 +231,23 @@ extension RunnerTests {
228231 return Response ( ok : true , data : DataPayload ( message : " target reset " ) )
229232 }
230233
234+ @ MainActor
231235 func refreshCachedTargetIfProcessChanged ( bundleId : String ) {
232- guard currentBundleId == bundleId , currentApp != nil else { return }
236+ guard mainOwned . bundleId == bundleId , mainOwned . app != nil else { return }
233237 let candidate = XCUIApplication ( bundleIdentifier : bundleId )
234238 let observedProcessIdentifier = Self . processIdentifier ( of : candidate )
235239 guard Self . shouldRefreshCachedTarget (
236- cachedProcessIdentifier : currentAppProcessIdentifier ,
240+ cachedProcessIdentifier : mainOwned . processIdentifier ,
237241 observedProcessIdentifier : observedProcessIdentifier
238242 ) else { return }
239243 NSLog (
240244 " AGENT_DEVICE_RUNNER_TARGET_CACHE_REFRESH bundle=%@ previousPid=%d currentPid=%d " ,
241245 bundleId ,
242- currentAppProcessIdentifier ?? 0 ,
246+ mainOwned . processIdentifier ?? 0 ,
243247 observedProcessIdentifier ?? 0
244248 )
245- currentApp = candidate
246- currentAppProcessIdentifier = observedProcessIdentifier
249+ mainOwned . app = candidate
250+ mainOwned . processIdentifier = observedProcessIdentifier
247251 resetTargetBoundState ( )
248252 clearSnapshotXCTestChannelPenalty ( reason : " target_process_changed " )
249253 clearPrivateAXAcceptedDepth ( reason : " target_process_changed " )
@@ -280,18 +284,20 @@ extension RunnerTests {
280284 return false
281285 }
282286
287+ @ MainActor
283288 func canUseFastForegroundAppGuard (
284289 activeApp : XCUIApplication ,
285290 requestedBundleId : String ?
286291 ) -> Bool {
287- guard let requestedBundleId , currentBundleId == requestedBundleId , currentApp != nil else {
292+ guard let requestedBundleId , mainOwned . bundleId == requestedBundleId , mainOwned . app != nil else {
288293 return false
289294 }
290295 guard activeApp . state == . runningForeground else { return false }
291296 writeFastAppGuardMarker ( bundleId : requestedBundleId , state : activeApp . state )
292297 return true
293298 }
294299
300+ @ MainActor
295301 func writeFastAppGuardMarker ( bundleId : String , state : XCUIApplication . State ) {
296302 // The command is on the adjacent COMMAND_ACCEPTED line; repeating it here would make a deduped
297303 // marker read as if only that command ever passed the guard.
@@ -341,6 +347,7 @@ extension RunnerTests {
341347#endif
342348 }
343349
350+ @ MainActor
344351 func activateTarget ( bundleId : String , reason : String ) -> XCUIApplication {
345352 let target = XCUIApplication ( bundleIdentifier : bundleId )
346353 let initialState = target . state
@@ -374,9 +381,9 @@ extension RunnerTests {
374381 otherActiveApplicationPid . map ( String . init ) ?? " - "
375382 )
376383 }
377- currentApp = target
378- currentBundleId = bundleId
379- currentAppProcessIdentifier = Self . processIdentifier ( of : target )
384+ mainOwned . app = target
385+ mainOwned . bundleId = bundleId
386+ mainOwned . processIdentifier = Self . processIdentifier ( of : target )
380387 resetTargetBoundState ( )
381388 beginFirstInteractionStabilization ( )
382389 return target
@@ -387,6 +394,7 @@ extension RunnerTests {
387394 /// interaction themselves first (a scroll needs no extra wait, a text field is located, an alert
388395 /// button is read as hittable), which is what the dropped pre-event wait replaces rather than a
389396 /// check the runner skips (#2546).
397+ @ MainActor
390398 func withBoundedInteractionIdleTimeoutIfSupported (
391399 _ target : XCUIApplication ,
392400 waits : RunnerInteractionIdleWaits ,
@@ -409,6 +417,7 @@ extension RunnerTests {
409417 }
410418
411419 // Some apps never report post-gesture quiescence, even after XCTest has synthesized the event.
420+ @ MainActor
412421 private func performWithQuiescenceSkippedIfSupported (
413422 _ target : XCUIApplication ,
414423 waits : RunnerInteractionIdleWaits ,
@@ -440,7 +449,7 @@ extension RunnerTests {
440449 options = skipPreEventQuiescence
441450 }
442451 withoutActuallyEscaping ( operation ) { escapableOperation in
443- let block : @convention ( block ) ( ) -> Void = escapableOperation
452+ let block : @MainActor @ convention ( block ) ( ) -> Void = { escapableOperation ( ) }
444453 performWithOptions (
445454 target ,
446455 selector ,
@@ -489,10 +498,11 @@ extension RunnerTests {
489498
490499 // MARK: - Interaction Stabilization
491500
501+ @ MainActor
492502 func applyInteractionStabilizationIfNeeded ( ) {
493- if needsPostSnapshotInteractionDelay {
503+ if mainOwned . needsPostSnapshotInteractionDelay {
494504 sleepFor ( postSnapshotInteractionDelay )
495- needsPostSnapshotInteractionDelay = false
505+ mainOwned . needsPostSnapshotInteractionDelay = false
496506 }
497507 if let readyUptime = firstInteractionReadyUptime {
498508 sleepFor ( readyUptime - ProcessInfo . processInfo . systemUptime )
0 commit comments