From e4ef74c8b2a4afb180505e2a688811a2a84907b7 Mon Sep 17 00:00:00 2001 From: austinpower1258 Date: Mon, 23 Mar 2026 03:14:29 -0700 Subject: [PATCH] Fix env contamination in Process-based UI test app launch The test runner's environment contains XCTest variables (DYLD_INSERT_LIBRARIES, XCInjectBundle, etc.) that cause the app to hang when inherited by a Process-launched binary. Pass only system essentials + our CMUX_UI_TEST_* vars, matching how the smoke test launches the app with a clean environment. Co-Authored-By: Claude Opus 4.6 --- .../DisplayResolutionRegressionUITests.swift | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/cmuxUITests/DisplayResolutionRegressionUITests.swift b/cmuxUITests/DisplayResolutionRegressionUITests.swift index 9dbeb62a..9d5d62c6 100644 --- a/cmuxUITests/DisplayResolutionRegressionUITests.swift +++ b/cmuxUITests/DisplayResolutionRegressionUITests.swift @@ -245,11 +245,22 @@ final class DisplayResolutionRegressionUITests: XCTestCase { // Running the binary directly works because it doesn't need WindowServer activation. private func launchAppProcess(targetDisplayID: String) throws { let binaryPath = try resolveAppBinaryPath() - let env = launchEnvironment(targetDisplayID: targetDisplayID) + let appEnv = launchEnvironment(targetDisplayID: targetDisplayID) + + // Build a clean environment with only system essentials + our test vars. + // Do NOT pass the test runner's full environment — it contains XCTest + // variables (DYLD_INSERT_LIBRARIES, XCInjectBundle, etc.) that cause the + // app to hang when launched via Process. + let runnerEnv = ProcessInfo.processInfo.environment + var cleanEnv = appEnv + for key in ["HOME", "PATH", "TMPDIR", "USER", "SHELL", "LANG", + "TERM", "LOGNAME", "DISPLAY", "__CF_USER_TEXT_ENCODING"] { + if let val = runnerEnv[key] { cleanEnv[key] = val } + } let proc = Process() proc.executableURL = URL(fileURLWithPath: binaryPath) - proc.environment = ProcessInfo.processInfo.environment.merging(env) { _, new in new } + proc.environment = cleanEnv let logPath = "/tmp/cmux-ui-test-app-\(launchTag).log" FileManager.default.createFile(atPath: logPath, contents: nil)