@@ -337,55 +337,12 @@ struct LowCoverageHelperTests {
337337 #expect ( siblingPlan . reap . isEmpty )
338338 }
339339
340- @ Test func `port guardian classifies a real orphaned tunnel process for reaping` ( ) async throws {
341- // Real ssh that hangs safely: ProxyCommand replaces the TCP transport, so no
342- // network traffic happens and the -L port is never bound (forwards only bind
343- // after auth). Spawned through sh so the parent exits and ssh reparents to
344- // launchd — the exact orphan shape the reaper must detect.
345- let port = 45871
346- // Detach the child's stdio: the pipe must reach EOF when sh exits, not when ssh dies.
347- let script = " /usr/bin/ssh -o BatchMode=yes -o ProxyCommand='sleep 60' " +
348- " -N -L \( port ) :127.0.0.1: \( port ) orphan-reap-test-host >/dev/null 2>&1 & echo $! "
349- let spawn = Process ( )
350- spawn . executableURL = URL ( fileURLWithPath : " /bin/sh " )
351- spawn . arguments = [ " -c " , script ]
352- let out = Pipe ( )
353- spawn . standardOutput = out
354- try spawn . run ( )
355- spawn . waitUntilExit ( )
356- let pidText = String ( data : out . fileHandleForReading . readDataToEndOfFile ( ) , encoding : . utf8 ) ?? " "
357- let pid = try #require ( Int32 ( pidText . trimmingCharacters ( in : . whitespacesAndNewlines ) ) )
358- defer { kill ( pid , SIGKILL ) }
359-
360- // Reparenting to launchd is immediate once sh exits, but give ps/sysctl a beat.
361- var info : PortGuardian . TunnelProcessInfo ?
362- for _ in 0 ..< 40 {
363- info = PortGuardian . _testTunnelProcessInfo ( pid : pid )
364- if info ? . parentPid == 1 , info ? . fullCommand ? . isEmpty == false { break }
365- try await Task . sleep ( nanoseconds : 50_000_000 )
366- }
367- let orphan = try #require ( info )
368- #expect ( orphan . parentPid == 1 )
369- // Kernel start time must be sane so the pid-reuse gate can rely on it.
370- #expect ( abs ( orphan . startedAt - Date ( ) . timeIntervalSince1970 ) < 60 )
371- let recordedAt = Date ( ) . timeIntervalSince1970
372- let record = PortGuardian . Record (
373- port : port , pid : pid , command : " /usr/bin/ssh " , mode : " remote " , timestamp : recordedAt )
374- #expect ( PortGuardian . classifyTunnelRecord ( record , process : orphan ) == . reap )
340+ @ Test func `port guardian reads current process metadata without spawning children` ( ) throws {
341+ let info = try #require ( PortGuardian . _testTunnelProcessInfo ( pid : getpid ( ) ) )
375342
376- // Same process under a different recorded port must never be reap-eligible.
377- let mismatched = PortGuardian . Record (
378- port : port + 1 , pid : pid , command : " /usr/bin/ssh " , mode : " remote " , timestamp : recordedAt )
379- #expect ( PortGuardian . classifyTunnelRecord ( mismatched , process : orphan ) == . drop )
380-
381- // A record predating this process (reused pid) must drop, not reap.
382- let predates = PortGuardian . Record (
383- port : port ,
384- pid : pid ,
385- command : " /usr/bin/ssh " ,
386- mode : " remote " ,
387- timestamp : orphan . startedAt - 3600 )
388- #expect ( PortGuardian . classifyTunnelRecord ( predates , process : orphan ) == . drop )
343+ #expect ( info . parentPid > 0 )
344+ #expect ( abs ( info . startedAt - Date ( ) . timeIntervalSince1970 ) < 60 )
345+ #expect ( info . fullCommand ? . isEmpty == false )
389346 }
390347
391348 @ Test @ MainActor func `canvas scheme handler resolves files and errors` ( ) throws {
0 commit comments