From 3b35b762cbd4e91c95622b0f93bc146a0a3059ca Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 14 Dec 2025 02:54:22 +0000 Subject: [PATCH] fix(macos): avoid health polling in tests --- apps/macos/Sources/Clawdis/HealthStore.swift | 5 ++++- apps/macos/Sources/Clawdis/Utilities.swift | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/apps/macos/Sources/Clawdis/HealthStore.swift b/apps/macos/Sources/Clawdis/HealthStore.swift index ce4d0b69e..bced307fa 100644 --- a/apps/macos/Sources/Clawdis/HealthStore.swift +++ b/apps/macos/Sources/Clawdis/HealthStore.swift @@ -67,7 +67,10 @@ final class HealthStore: ObservableObject { private let refreshInterval: TimeInterval = 60 private init() { - self.start() + // Avoid background health polling in SwiftUI previews and tests. + if !ProcessInfo.processInfo.isPreview, !ProcessInfo.processInfo.isRunningTests { + self.start() + } } func start() { diff --git a/apps/macos/Sources/Clawdis/Utilities.swift b/apps/macos/Sources/Clawdis/Utilities.swift index ab724b9f8..f277df620 100644 --- a/apps/macos/Sources/Clawdis/Utilities.swift +++ b/apps/macos/Sources/Clawdis/Utilities.swift @@ -5,6 +5,15 @@ extension ProcessInfo { var isPreview: Bool { self.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1" } + + var isRunningTests: Bool { + // SwiftPM test bundles are typically loaded from a `.xctest` bundle. + // We also check common XCTest env vars because some runners still set them. + if Bundle.main.bundleURL.pathExtension == "xctest" { return true } + return self.environment["XCTestConfigurationFilePath"] != nil + || self.environment["XCTestBundlePath"] != nil + || self.environment["XCTestSessionIdentifier"] != nil + } } enum LaunchdManager {