@@ -81,6 +81,7 @@ final class RunnerTests: XCTestCase {
8181 static let defaultRecordingFps : Int32 = 15
8282 var listener : NWListener ?
8383 var listenerToken : RunnerListenerToken ?
84+ var acceptsForwardedConnections = false
8485 var doneExpectation : XCTestExpectation ?
8586 var transportConnections : [ ObjectIdentifier : NWConnection ] = [ : ]
8687 let shutdownResponseWrites = DispatchGroup ( )
@@ -342,13 +343,14 @@ final class RunnerTests: XCTestCase {
342343 NSLog ( " AGENT_DEVICE_RUNNER_HEADLESS_STARTUP=1 " )
343344 guard let configuration = RunnerListenerConfiguration . fromEnvironment ( ) else {
344345 NSLog ( " AGENT_DEVICE_RUNNER_LISTENER_CONFIGURATION_MISSING " )
345- XCTFail ( " runner listener port or token is missing; refusing to listen " )
346+ XCTFail ( " runner listener port, token, or bind address is missing or invalid ; refusing to listen " )
346347 return
347348 }
348349 listenerToken = configuration . token
350+ acceptsForwardedConnections = configuration . bindAddress != nil
349351 NSLog ( " AGENT_DEVICE_RUNNER_AUTH=required " )
350352 NSLog ( " AGENT_DEVICE_RUNNER_DESIRED_PORT=%d " , configuration . port . rawValue )
351- listener = try Self . makeRunnerListener ( port : configuration . port )
353+ listener = try Self . makeRunnerListener ( port : configuration . port , bindAddress : configuration . bindAddress )
352354 // Reads the OS prompt strings off the alert path, so the first accept/dismiss deadline does not pay for it.
353355 DispatchQueue . global ( qos : . utility ) . async { _ = RunnerAlertLabelVocabulary . system }
354356 DispatchQueue . global ( qos : . utility ) . async { _ = RunnerLaunchConfirmationPrompt . system }
@@ -397,9 +399,14 @@ final class RunnerTests: XCTestCase {
397399 }
398400 }
399401
400- /// Simulators and macOS bind loopback: the host reaches them only through 127.0.0.1. A physical
401- /// device listens on every interface because the CoreDevice tunnel arrives on a network address.
402- static func makeRunnerListener ( port : NWEndpoint . Port ) throws -> NWListener {
402+ /// Cloud simulators bind their assigned address; local simulators keep the loopback listener.
403+ /// Physical devices accept CoreDevice tunnel connections on their network interface.
404+ static func makeRunnerListener ( port : NWEndpoint . Port , bindAddress : IPv4Address ? = nil ) throws -> NWListener {
405+ if let bindAddress {
406+ let parameters = NWParameters . tcp
407+ parameters . requiredLocalEndpoint = . hostPort ( host : . ipv4 ( bindAddress ) , port : port )
408+ return try NWListener ( using : parameters )
409+ }
403410 #if targetEnvironment( simulator ) || os( macOS )
404411 let parameters = NWParameters . tcp
405412 parameters . requiredLocalEndpoint = . hostPort ( host : . ipv4 ( . loopback ) , port : port )
0 commit comments