From a9a93acd805713ec888edf48ba9860f4c46b066a Mon Sep 17 00:00:00 2001 From: Valentine Silvansky Date: Mon, 29 Dec 2025 17:34:55 +0300 Subject: [PATCH 1/2] Always show debug information. Introduce shouldShowDebugInformation flag with default value that preserves original behaviour --- Sources/ApplePlatformChecks/CertificateCheck.swift | 2 +- Sources/NetTesterLib/CheckProtocol.swift | 5 +++++ Sources/NetTesterLib/ThrowableCheck.swift | 2 +- Sources/NetTesterUIKit/NetworkCheckCell.swift | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Sources/ApplePlatformChecks/CertificateCheck.swift b/Sources/ApplePlatformChecks/CertificateCheck.swift index 80d1990..304c0a0 100644 --- a/Sources/ApplePlatformChecks/CertificateCheck.swift +++ b/Sources/ApplePlatformChecks/CertificateCheck.swift @@ -2,7 +2,7 @@ import Foundation import NetTesterLib final public class CertificateCheck: NSObject, CheckProtocol { - public var debugInformation: String { debugBreadcrumbs.joined(separator: "\n")} + public var debugInformation: String { shouldShowDebugInformation ? debugBreadcrumbs.joined(separator: "\n") : "" } private var debugBreadcrumbs: [String] = [] public var name: String? public private(set) var status: CheckStatus = .notLaunchedYet diff --git a/Sources/NetTesterLib/CheckProtocol.swift b/Sources/NetTesterLib/CheckProtocol.swift index 09aa1aa..c6bc6c0 100644 --- a/Sources/NetTesterLib/CheckProtocol.swift +++ b/Sources/NetTesterLib/CheckProtocol.swift @@ -12,6 +12,7 @@ public enum CheckStatus: Sendable { public protocol CheckProtocol: AnyObject, Sendable { var status: CheckStatus { get } var debugInformation: String { get } + var shouldShowDebugInformation: Bool { get } var name: String? { get set } @discardableResult @@ -19,6 +20,10 @@ public protocol CheckProtocol: AnyObject, Sendable { } extension CheckProtocol { + public var shouldShowDebugInformation: Bool { + [.failed, .warning].contains(status) + } + public func named(_ name: String) -> Self { self.name = name return self diff --git a/Sources/NetTesterLib/ThrowableCheck.swift b/Sources/NetTesterLib/ThrowableCheck.swift index afa23e3..3caa27f 100644 --- a/Sources/NetTesterLib/ThrowableCheck.swift +++ b/Sources/NetTesterLib/ThrowableCheck.swift @@ -1,6 +1,6 @@ open class ThrowableCheck: CheckProtocol { open var status: CheckStatus = .notLaunchedYet - public var debugInformation: String { debugBreadcrumbs.joined(separator: "\n")} + public var debugInformation: String { shouldShowDebugInformation ? debugBreadcrumbs.joined(separator: "\n") : "" } open var debugBreadcrumbs: [String] = [] open var name: String? diff --git a/Sources/NetTesterUIKit/NetworkCheckCell.swift b/Sources/NetTesterUIKit/NetworkCheckCell.swift index 20f4c6b..779bcf7 100644 --- a/Sources/NetTesterUIKit/NetworkCheckCell.swift +++ b/Sources/NetTesterUIKit/NetworkCheckCell.swift @@ -19,7 +19,7 @@ class NetworkCheckCell: UITableViewCell { textLabel?.text = check.name ?? "\(type(of: check))" imageView?.image = check.status.cellImage imageView?.tintColor = check.status.cellImageTint - detailTextLabel?.text = [.failed, .warning].contains(check.status) ? check.debugInformation : nil + detailTextLabel?.text = check.debugInformation } } } From b607154c6b6b393d6d88499860f5dfbc9c8be015 Mon Sep 17 00:00:00 2001 From: Valentine Silvansky Date: Mon, 29 Dec 2025 18:07:45 +0300 Subject: [PATCH 2/2] Restore TUI and CLI apps behaviour --- Sources/ApplePlatformChecks/CertificateCheck.swift | 2 +- Sources/NetTesterLib/CheckProtocol.swift | 1 + Sources/network-tester-cli/main.swift | 5 ++--- Sources/network-tester-tui/App.swift | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/ApplePlatformChecks/CertificateCheck.swift b/Sources/ApplePlatformChecks/CertificateCheck.swift index 304c0a0..1aea5cc 100644 --- a/Sources/ApplePlatformChecks/CertificateCheck.swift +++ b/Sources/ApplePlatformChecks/CertificateCheck.swift @@ -3,7 +3,7 @@ import NetTesterLib final public class CertificateCheck: NSObject, CheckProtocol { public var debugInformation: String { shouldShowDebugInformation ? debugBreadcrumbs.joined(separator: "\n") : "" } - private var debugBreadcrumbs: [String] = [] + public private(set) var debugBreadcrumbs: [String] = [] public var name: String? public private(set) var status: CheckStatus = .notLaunchedYet private var session: URLSession? diff --git a/Sources/NetTesterLib/CheckProtocol.swift b/Sources/NetTesterLib/CheckProtocol.swift index c6bc6c0..59f6de3 100644 --- a/Sources/NetTesterLib/CheckProtocol.swift +++ b/Sources/NetTesterLib/CheckProtocol.swift @@ -11,6 +11,7 @@ public enum CheckStatus: Sendable { /// Strictly speaking, it is not sendable, but I only send it once mutations are done.. public protocol CheckProtocol: AnyObject, Sendable { var status: CheckStatus { get } + var debugBreadcrumbs: [String] { get } var debugInformation: String { get } var shouldShowDebugInformation: Bool { get } var name: String? { get set } diff --git a/Sources/network-tester-cli/main.swift b/Sources/network-tester-cli/main.swift index 29d141d..295a3dd 100644 --- a/Sources/network-tester-cli/main.swift +++ b/Sources/network-tester-cli/main.swift @@ -16,12 +16,11 @@ checks.append(CertificateCheck(url: URL(string: "https://google.com")!, expected let runner = CheckRunner() runner.didUpdate = { check in - if check.debugInformation.isEmpty { + if check.debugBreadcrumbs.isEmpty { print("check \(check) finished") - } else { print("check \(check) finished:") - print(check.debugInformation) + print(check.debugBreadcrumbs.joined(separator: "\n")) } print() } diff --git a/Sources/network-tester-tui/App.swift b/Sources/network-tester-tui/App.swift index 1b29779..fd067fb 100644 --- a/Sources/network-tester-tui/App.swift +++ b/Sources/network-tester-tui/App.swift @@ -62,7 +62,7 @@ struct CheckView: View { } if [.warning, .failed].contains(check.status) { Text("") - ForEach(Array(check.debugInformation.split(separator: "\n").map {" \($0)"}.enumerated()), id: \.offset) { + ForEach(Array(check.debugBreadcrumbs.map { " \($0)" }.enumerated()), id: \.offset) { Text($0.element) } Text("")