A native macOS app for managing virtual iPhones - browse, create, and boot iOS research VMs from a single window.
Swift
process: Add Homebrew bin dirs to spawned child PATH
zqxwcef2a982f3ebe8
diff --git a/Sources/VPhoneWSCore/Process/StreamingRunner.swift b/Sources/VPhoneWSCore/Process/StreamingRunner.swiftindex 6ded235..511bb9b 100644--- a/Sources/VPhoneWSCore/Process/StreamingRunner.swift+++ b/Sources/VPhoneWSCore/Process/StreamingRunner.swift@@ -127,6 +127,20 @@ private final class ResumeGuard: @unchecked Sendable {public struct SystemStreamingRunner: StreamingRunner {public init() {}+ /// A Finder/launchd-launched app gets a minimal PATH without Homebrew, so+ /// bsdtar's `--zstd` (which execs external `zstd`) fails on export. Append+ /// the Homebrew bin dirs, keeping system binaries first.+ static func withHomebrewPath(_ env: [String: String]) -> [String: String] {+ var env = env+ var entries = (env["PATH"] ?? "/usr/bin:/bin:/usr/sbin:/sbin")+ .split(separator: ":", omittingEmptySubsequences: true).map(String.init)+ for dir in ["/opt/homebrew/bin", "/usr/local/bin"] where !entries.contains(dir) {+ entries.append(dir)+ }+ env["PATH"] = entries.joined(separator: ":")+ return env+ }+public func run(executable: URL, arguments: [String], environment: [String: String]?,onStart: @escaping @Sendable (Int32) -> Void,onEvent: @escaping @Sendable (StreamEvent) -> Void) async throws -> Int32 {@@ -156,6 +170,7 @@ public struct SystemStreamingRunner: StreamingRunner {// Python (pmd3 restore bridge) block-buffers stdout even on a TTY;// force it unbuffered so its lines stream live like everything else.env["PYTHONUNBUFFERED"] = "1"+ env = Self.withHomebrewPath(env)process.environment = envprocess.standardOutput = slaveHandleprocess.standardError = slaveHandlediff --git a/tests/VPhoneWSCoreTests/StreamingRunnerTests.swift b/tests/VPhoneWSCoreTests/StreamingRunnerTests.swiftindex 1af5df3..be7ca1d 100644--- a/tests/VPhoneWSCoreTests/StreamingRunnerTests.swift+++ b/tests/VPhoneWSCoreTests/StreamingRunnerTests.swift@@ -112,6 +112,28 @@ func systemStreamerStripsAnsiEscapes() async throws {#expect(collector.seenLines == ["aREDb"])}+@Test func withHomebrewPathAppendsBrewDirsWithoutDuplicating() {+ let augmented = SystemStreamingRunner.withHomebrewPath(["PATH": "/usr/bin:/bin"])+ #expect(augmented["PATH"] == "/usr/bin:/bin:/opt/homebrew/bin:/usr/local/bin")++ let idempotent = SystemStreamingRunner.withHomebrewPath(["PATH": "/opt/homebrew/bin:/usr/bin"])+ #expect(idempotent["PATH"] == "/opt/homebrew/bin:/usr/bin:/usr/local/bin")+}++@Test(.timeLimit(.minutes(1)))+func systemStreamerGivesChildHomebrewOnPath() async throws {+ let runner = SystemStreamingRunner()+ let collector = StreamCollector()+ let code = try await runner.run(+ executable: URL(fileURLWithPath: "/bin/sh"),+ arguments: ["-c", "echo $PATH"],+ environment: ["PATH": "/usr/bin:/bin:/usr/sbin:/sbin"],+ onStart: { _ in },+ onEvent: { if case .line(let s) = $0 { collector.recordLine(s) } })+ #expect(code == 0)+ #expect(collector.seenLines.contains { $0.split(separator: ":").contains("/opt/homebrew/bin") })+}+private final class TimedRecorder: @unchecked Sendable {private let lock = NSLock()private var _lines: [String] = []