Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253import CoreGraphicsimport Darwinimport Foundation
public enum NativeHostPolicy { public static func isOptedIn(environment: [String: String]) -> Bool { guard environment["PARCEL_E2E_PREFLIGHT_ONLY"] != "1" else { return false } return ["PARCEL_NATIVE_HOST", "PARCEL_E2E", "PARCEL_BENCH", "PARCEL_BENCH_SMOKE"].contains { environment[$0] == "1" } }
public static func ownsLock(owner: String, ancestors: [Int32]) -> Bool { let fields = owner.trimmingCharacters(in: .newlines).split(separator: " ") guard fields.count == 2, let pid = Int32(fields[1]), pid > 1 else { return false } return ancestors.contains(pid) }}
public enum NativeHostAvailability { public static let unavailableReason: String? = { let environment = ProcessInfo.processInfo.environment guard NativeHostPolicy.isOptedIn(environment: environment) else { return "Native-host tests require PARCEL_NATIVE_HOST=1 and Scripts/screen-lock.sh. No windows or input hooks were opened." } do { let lock = environment["PARCEL_SCREEN_LOCK_PATH"] ?? "/tmp/parcel-screen.lock" let owner = try String(contentsOfFile: "\(lock)/owner", encoding: .utf8) var ancestors: [Int32] = [] var pid = getppid() while pid > 1, !ancestors.contains(pid) { ancestors.append(pid) // Higher ancestors may be protected system processes; the lock owner is sufficient. if NativeHostPolicy.ownsLock(owner: owner, ancestors: ancestors) { break } var info = proc_bsdinfo() let size = Int32(MemoryLayout<proc_bsdinfo>.size) guard proc_pidinfo(pid, PROC_PIDTBSDINFO, 0, &info, size) == size else { return "Native-host tests could not verify the screen-lock process ancestry." } pid = Int32(info.pbi_ppid) } guard NativeHostPolicy.ownsLock(owner: owner, ancestors: ancestors) else { return "Native-host tests must run under Scripts/screen-lock.sh; its owner is not an ancestor." } try E2EConsoleSession.requireUnlockedConsole() return nil } catch { return "Native-host tests are blocked: \(error)." } }()}