import Foundation @main struct ReleaseUpdateChecks { @MainActor static func main() { let app = Bundle(path: CommandLine.arguments[1])! precondition(app.object(forInfoDictionaryKey: "SUScheduledCheckInterval") as? Int == 6 * 60 * 60) precondition(app.object(forInfoDictionaryKey: "SUEnableAutomaticChecks") as? Bool == true) precondition(app.object(forInfoDictionaryKey: "SURequireSignedFeed") as? Bool == true) precondition(app.object(forInfoDictionaryKey: "SUVerifyUpdateBeforeExtraction") as? Bool == true) let suite = "KymoReleaseUpdateChecks." + UUID().uuidString let defaults = UserDefaults(suiteName: suite)! defer { defaults.removePersistentDomain(forName: suite) } let updates = ReleaseUpdates(defaults: defaults) let release = ReleaseUpdates.Version(display: "1.5", build: "17", infoURL: nil) var checks = 0, downloads = 0, restarts = 0 updates.beginCheck = { checks += 1 updates.transition(to: .checking) } updates.beginDownload = { version in precondition(version == release) downloads += 1 updates.transition(to: .downloading) } precondition(updates.automatic) var changes = [Bool]() updates.changeAutomatic = { changes.append($0) } updates.automatic = false precondition(changes == [false] && !ReleaseUpdates(defaults: defaults).automatic) updates.check() updates.check() precondition(checks == 1 && updates.phase == .checking) updates.found(release) updates.performAction() updates.performAction() precondition(downloads == 1) updates.transition(to: .failed, error: "offline") updates.performAction() precondition(checks == 2 && updates.errorMessage == nil) updates.found(release) updates.performAction() updates.transition(to: .extracting, fraction: 0.5) updates.check() precondition(checks == 2 && updates.fraction == 0.5) updates.ready { restarts += 1 } precondition(restarts == 0 && updates.phase == .ready) updates.performAction() updates.performAction() precondition(restarts == 1 && downloads == 2 && updates.phase == .restarting) updates.transition(to: .current) precondition(updates.version == nil) print("PASS: preserved preference, manual check, shared download/restart actions, busy state, retry and current version") } }