@@ -78,6 +78,7 @@ final class RunnerTests: XCTestCase {
7878 static let defaultRecordingFps : Int32 = 15
7979 var listener : NWListener ?
8080 var listenerToken : RunnerListenerToken ?
81+ var acceptsForwardedConnections = false
8182 var doneExpectation : XCTestExpectation ?
8283 var transportConnections : [ ObjectIdentifier : NWConnection ] = [ : ]
8384 let shutdownResponseWrites = DispatchGroup ( )
@@ -339,13 +340,14 @@ final class RunnerTests: XCTestCase {
339340 NSLog ( " AGENT_DEVICE_RUNNER_HEADLESS_STARTUP=1 " )
340341 guard let configuration = RunnerListenerConfiguration . fromEnvironment ( ) else {
341342 NSLog ( " AGENT_DEVICE_RUNNER_LISTENER_CONFIGURATION_MISSING " )
342- XCTFail ( " runner listener port or token is missing; refusing to listen " )
343+ XCTFail ( " runner listener port, token, or bind address is missing or invalid ; refusing to listen " )
343344 return
344345 }
345346 listenerToken = configuration . token
347+ acceptsForwardedConnections = configuration . bindAddress != nil
346348 NSLog ( " AGENT_DEVICE_RUNNER_AUTH=required " )
347349 NSLog ( " AGENT_DEVICE_RUNNER_DESIRED_PORT=%d " , configuration . port . rawValue )
348- listener = try Self . makeRunnerListener ( port : configuration . port )
350+ listener = try Self . makeRunnerListener ( port : configuration . port , bindAddress : configuration . bindAddress )
349351 // Reads the OS prompt strings off the alert path, so the first accept/dismiss deadline does not pay for it.
350352 DispatchQueue . global ( qos : . utility ) . async { _ = RunnerAlertLabelVocabulary . system }
351353 listener ? . stateUpdateHandler = { [ weak self ] state in
@@ -393,9 +395,14 @@ final class RunnerTests: XCTestCase {
393395 }
394396 }
395397
396- /// Simulators and macOS bind loopback: the host reaches them only through 127.0.0.1. A physical
397- /// device listens on every interface because the CoreDevice tunnel arrives on a network address.
398- static func makeRunnerListener ( port : NWEndpoint . Port ) throws -> NWListener {
398+ /// Cloud simulators bind their assigned address; local simulators keep the loopback listener.
399+ /// Physical devices accept CoreDevice tunnel connections on their network interface.
400+ static func makeRunnerListener ( port : NWEndpoint . Port , bindAddress : IPv4Address ? = nil ) throws -> NWListener {
401+ if let bindAddress {
402+ let parameters = NWParameters . tcp
403+ parameters . requiredLocalEndpoint = . hostPort ( host : . ipv4 ( bindAddress ) , port : port )
404+ return try NWListener ( using : parameters )
405+ }
399406 #if targetEnvironment( simulator ) || os( macOS )
400407 let parameters = NWParameters . tcp
401408 parameters . requiredLocalEndpoint = . hostPort ( host : . ipv4 ( . loopback ) , port : port )
0 commit comments