diff --git a/Sources/ParcelApp/AppNotices.swift b/Sources/ParcelApp/AppNotices.swift index 5fec1612..04be0593 100644 --- a/Sources/ParcelApp/AppNotices.swift +++ b/Sources/ParcelApp/AppNotices.swift @@ -70,11 +70,13 @@ final class AppNotices { func recordDiagnosticIfNeeded(_ error: any Error, kind: Kind) -> Bool { guard !Self.shouldPresent(error, kind: kind) else { return false } - logger.error("\(kind.rawValue, privacy: .public) diagnostic: \(String(describing: error), privacy: .public)") + logger.error("\(kind.rawValue, privacy: .public) diagnostic: \(String(reflecting: error), privacy: .private)") return true } static func shouldPresent(_ error: any Error, kind: Kind) -> Bool { + if error is CancellationError { return false } + if kind == .internalFailure { return Self.kind(for: error) != nil } guard kind == .restoration else { return true } if let restoration = error as? AppRestorationFailure { return !restoration.harmfulWindows.isEmpty } if let accessibility = error as? AXPlatformError { return accessibility != .timedOut } @@ -96,7 +98,8 @@ final class AppNotices { @discardableResult func report(_ error: any Error, kind: Kind) -> Report { - logger.error("\(kind.rawValue, privacy: .public): \(String(describing: error), privacy: .public)") + let kind = kind == .internalFailure ? Self.kind(for: error) ?? kind : kind + logger.error("\(kind.rawValue, privacy: .public): \(String(describing: error), privacy: .private)") counts[kind, default: 0] += 1 let message: String let actions: [NoticeAction] @@ -160,12 +163,22 @@ final class AppNotices { } private static func kind(for error: any Error) -> Kind? { + if error is CancellationError || error is TourSetupFailure { return nil } if let accessibility = error as? AXPlatformError { return accessibility == .notPermitted ? .permission : nil } + if let input = error as? InputError { + switch input { + case .accessibilityRequired, .accessibility(_, _, .notPermitted): return .permission + default: return nil + } + } if let write = error as? FrameWriteFailure { return kind(for: write.writeError) ?? kind(for: write.restoreError) } + if let batch = error as? AppThreadWriteBatchFailure { + return batch.errors.compactMap { kind(for: $0) }.first + } if let failure = error as? EnginePlatformFailure { return kind(for: .platform(failure)) } - return .internalFailure + return AppText.humanFailure(error) == nil ? nil : .internalFailure } static func kind(for diagnostic: EngineDiagnostic) -> Kind? { diff --git a/Sources/ParcelUI/Resources/TourSetup.xcstrings b/Sources/ParcelUI/Resources/TourSetup.xcstrings index 0fd541cf..280636a7 100644 --- a/Sources/ParcelUI/Resources/TourSetup.xcstrings +++ b/Sources/ParcelUI/Resources/TourSetup.xcstrings @@ -17,7 +17,10 @@ "Keep Control Option": {"comment": "Spoken label for retaining the default prefix.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Keep Control Option"}}, "es": {"stringUnit": {"state": "translated", "value": "Mantener Control-Opción"}}, "fr":{"stringUnit":{"state":"translated","value":"Conserver Contrôle Option"}}, "de": {"stringUnit":{"state":"translated","value":"Control-Option beibehalten"}}, "ja": {"stringUnit":{"state":"translated","value":"Control Optionを維持"}}, "zh-Hans":{"stringUnit":{"state":"translated","value":"保留 Control Option"}}, "ko": {"stringUnit":{"state":"translated","value":"Control Option 유지"}}, "pt-BR": {"stringUnit":{"state":"translated","value":"Manter Control Option"}}}}, "Border on active window": {"comment": "Highlight only the focused window.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Border on active window"}}, "es": {"stringUnit": {"state": "translated", "value": "Borde en la ventana activa"}}, "fr":{"stringUnit":{"state":"translated","value":"Bordure : fenêtre active"}}, "de": {"stringUnit":{"state":"translated","value":"Rahmen um aktives Fenster"}}, "ja": {"stringUnit":{"state":"translated","value":"選択中に枠線"}}, "zh-Hans":{"stringUnit":{"state":"translated","value":"活动窗口边框"}}, "ko": {"stringUnit":{"state":"translated","value":"활성 윈도우 테두리"}}, "pt-BR": {"stringUnit":{"state":"translated","value":"Contorno na janela ativa"}}}}, "Allow Accessibility before tidying your windows.": {"comment": "Skip Tidy routes to the Allow screen when permission is missing.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Allow Accessibility before tidying your windows."}}, "es": {"stringUnit": {"state": "translated", "value": "Activa Accesibilidad antes de ordenar tus ventanas."}}, "fr":{"stringUnit":{"state":"translated","value":"Accordez à Parcel l’autorisation Accessibilité avant de réorganiser vos fenêtres."}}, "de": {"stringUnit":{"state":"translated","value":"Erteilen Sie Parcel vor dem Anordnen Ihrer Fenster die Berechtigung für Bedienungshilfen."}}, "ja": {"stringUnit":{"state":"translated","value":"ウインドウを整える前に、アクセシビリティを許可してください。"}}, "zh-Hans":{"stringUnit":{"state":"translated","value":"允许无障碍权限后,再整理窗口。"}}, "ko": {"stringUnit":{"state":"translated","value":"윈도우를 정리하려면 먼저 손쉬운 사용 권한을 허용하세요."}}, "pt-BR": {"stringUnit":{"state":"translated","value":"Permita o acesso à Acessibilidade antes de organizar as janelas."}}}}, - "Reopen the tour to try setup again.": {"comment": "Recover from unavailable tour services.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Reopen the tour to try setup again."}}, "es": {"stringUnit": {"state": "translated", "value": "Vuelve a abrir el recorrido para probar la configuración otra vez."}}, "fr":{"stringUnit":{"state":"translated","value":"Rouvrez le parcours pour réessayer la configuration."}}, "de": {"stringUnit":{"state":"translated","value":"Öffnen Sie die Tour erneut, um die Einrichtung noch einmal zu versuchen."}}, "ja": {"stringUnit":{"state":"translated","value":"ツアーをもう一度開いて、設定をやり直してください。"}}, "zh-Hans":{"stringUnit":{"state":"translated","value":"重新打开导览,再试一次设置。"}}, "ko": {"stringUnit":{"state":"translated","value":"투어를 다시 열어 설정을 다시 시도하세요."}}, "pt-BR": {"stringUnit":{"state":"translated","value":"Abra o tour novamente para refazer a configuração."}}}}, + "Setup is unavailable right now. Try again or continue anyway.": {"comment": "Inline recovery when a setup service is unavailable; continuing does not certify the failed check.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Setup is unavailable right now. Try again or continue anyway."}}, "es": {"stringUnit": {"state": "translated", "value": "La configuración no está disponible ahora. Inténtalo de nuevo o continúa de todos modos."}}, "fr":{"stringUnit":{"state":"translated","value":"La configuration est indisponible pour le moment. Réessayez ou continuez quand même."}}, "de": {"stringUnit":{"state":"translated","value":"Die Einrichtung ist gerade nicht verfügbar. Versuchen Sie es erneut oder fahren Sie trotzdem fort."}}, "ja": {"stringUnit":{"state":"translated","value":"現在、設定を利用できません。もう一度試すか、そのまま続けてください。"}}, "zh-Hans":{"stringUnit":{"state":"translated","value":"设置暂时不可用。请重试,或仍然继续。"}}, "ko": {"stringUnit":{"state":"translated","value":"지금은 설정을 진행할 수 없습니다. 다시 시도하거나 그대로 계속하세요."}}, "pt-BR": {"stringUnit":{"state":"translated","value":"A configuração está indisponível no momento. Tente novamente ou continue mesmo assim."}}}}, + "Try Again": {"comment": "Retry just the failed setup check or login change.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Try Again"}}, "es": {"stringUnit": {"state": "translated", "value": "Intentar de nuevo"}}, "fr":{"stringUnit":{"state":"translated","value":"Réessayer"}}, "de": {"stringUnit":{"state":"translated","value":"Erneut versuchen"}}, "ja": {"stringUnit":{"state":"translated","value":"もう一度試す"}}, "zh-Hans":{"stringUnit":{"state":"translated","value":"重试"}}, "ko": {"stringUnit":{"state":"translated","value":"다시 시도"}}, "pt-BR": {"stringUnit":{"state":"translated","value":"Tentar novamente"}}}}, + "Continue anyway": {"comment": "Continue the tour without requiring successful setup checks; a failed login draft is discarded.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Continue anyway"}}, "es": {"stringUnit": {"state": "translated", "value": "Continuar de todos modos"}}, "fr":{"stringUnit":{"state":"translated","value":"Continuer quand même"}}, "de": {"stringUnit":{"state":"translated","value":"Trotzdem fortfahren"}}, "ja": {"stringUnit":{"state":"translated","value":"そのまま続ける"}}, "zh-Hans":{"stringUnit":{"state":"translated","value":"仍然继续"}}, "ko": {"stringUnit":{"state":"translated","value":"그대로 계속"}}, "pt-BR": {"stringUnit":{"state":"translated","value":"Continuar mesmo assim"}}}}, + "No conflicts in checked shortcuts": {"comment": "Only the readable shortcut sources were checked; separate secondary lines identify unavailable sources.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "No conflicts in checked shortcuts"}}, "es": {"stringUnit": {"state": "translated", "value": "Sin conflictos en los atajos comprobados"}}, "fr":{"stringUnit":{"state":"translated","value":"Aucun conflit dans les raccourcis vérifiés"}}, "de": {"stringUnit":{"state":"translated","value":"Keine Konflikte bei den geprüften Kurzbefehlen"}}, "ja": {"stringUnit":{"state":"translated","value":"確認できたショートカットに競合はありません"}}, "zh-Hans":{"stringUnit":{"state":"translated","value":"已检查的快捷键没有冲突"}}, "ko": {"stringUnit":{"state":"translated","value":"확인한 단축키에는 충돌이 없습니다"}}, "pt-BR": {"stringUnit":{"state":"translated","value":"Sem conflitos nos atalhos verificados"}}}}, "Restart setup to choose an available screen or Space.": {"comment": "The selected display or native Space disappeared.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Restart setup to choose an available screen or Space."}}, "es": {"stringUnit": {"state": "translated", "value": "Reinicia la configuración para elegir una pantalla o un espacio disponible."}}, "fr":{"stringUnit":{"state":"translated","value":"Redémarrez la configuration pour choisir un écran ou un espace disponible."}}, "de": {"stringUnit":{"state":"translated","value":"Starten Sie die Einrichtung neu, um einen verfügbaren Bildschirm oder Space auszuwählen."}}, "ja": {"stringUnit":{"state":"translated","value":"設定をやり直して、利用可能な画面または操作スペースを選択してください。"}}, "zh-Hans":{"stringUnit":{"state":"translated","value":"重新开始设置,选择可用的屏幕或空间。"}}, "ko": {"stringUnit":{"state":"translated","value":"설정을 다시 시작하고 사용할 수 있는 화면 또는 Spaces를 선택하세요."}}, "pt-BR": {"stringUnit":{"state":"translated","value":"Reinicie a configuração e escolha uma tela ou space disponível."}}}}, "Review Settings before applying your choices again.": {"comment": "Configuration application failed.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Review Settings before applying your choices again."}}, "es": {"stringUnit": {"state": "translated", "value": "Revisa Ajustes antes de volver a aplicar tus opciones."}}, "fr":{"stringUnit":{"state":"translated","value":"Vérifiez les Réglages avant de réappliquer vos choix."}}, "de": {"stringUnit":{"state":"translated","value":"Prüfen Sie die Einstellungen, bevor Sie Ihre Auswahl erneut anwenden."}}, "ja": {"stringUnit":{"state":"translated","value":"選択内容をもう一度適用する前に、Parcelの設定を確認してください。"}}, "zh-Hans":{"stringUnit":{"state":"translated","value":"再次应用选择前,请先检查设置。"}}, "ko": {"stringUnit":{"state":"translated","value":"선택 항목을 다시 적용하기 전에 Parcel 설정을 확인하세요."}}, "pt-BR": {"stringUnit":{"state":"translated","value":"Confira os Ajustes do Parcel antes de aplicar suas escolhas novamente."}}}}, "Review Parcel’s notice before tidying again.": {"comment": "Real-window arrangement failed.", "localizations": {"en": {"stringUnit": {"state": "translated", "value": "Review Parcel’s notice before tidying again."}}, "es": {"stringUnit": {"state": "translated", "value": "Revisa el aviso de Parcel antes de volver a ordenar."}}, "fr":{"stringUnit":{"state":"translated","value":"Consultez l’avis de Parcel avant de réorganiser à nouveau."}}, "de": {"stringUnit":{"state":"translated","value":"Prüfen Sie die Parcel-Mitteilung, bevor Sie die Fenster erneut anordnen."}}, "ja": {"stringUnit":{"state":"translated","value":"もう一度ウインドウを整える前に、Parcelのお知らせを確認してください。"}}, "zh-Hans":{"stringUnit":{"state":"translated","value":"再次整理前,请查看 Parcel 的通知。"}}, "ko": {"stringUnit":{"state":"translated","value":"다시 정리하기 전에 Parcel 알림을 확인하세요."}}, "pt-BR": {"stringUnit":{"state":"translated","value":"Confira o aviso do Parcel antes de organizar as janelas novamente."}}}}, diff --git a/Sources/ParcelUI/Tour/TourAllowView.swift b/Sources/ParcelUI/Tour/TourAllowView.swift index 944077c3..6eb555db 100644 --- a/Sources/ParcelUI/Tour/TourAllowView.swift +++ b/Sources/ParcelUI/Tour/TourAllowView.swift @@ -18,19 +18,25 @@ struct TourAllowView: View { title: "Accessibility", status: accessibilityStatus, ready: setup.permission == .granted, known: setup.permission != .checking, - fix: "Open Settings", action: openAccessibility) + fix: "Open Settings", action: openAccessibility, + error: setup.checkErrors[.permission], retry: { retry(.permission) }, + retryIdentifier: "tour.retry.permission", isChecking: setup.checkingChecks.contains(.permission)) TourCheckRow( title: "Stage Manager and tiling", status: systemStatus, ready: setup.system?.isClear == true, known: setup.system != nil, - fix: "Turn Off…", action: openSystem) + fix: "Turn Off…", action: openSystem, + error: setup.checkErrors[.system], retry: { retry(.system) }, + retryIdentifier: "tour.retry.system", isChecking: setup.checkingChecks.contains(.system)) TourCheckRow( title: "Shortcuts", status: shortcutStatus, - ready: setup.shortcuts != nil && !setup.hasShortcutClash - && setup.shortcuts?.limitations.isEmpty == true, + ready: setup.shortcuts != nil && !setup.hasShortcutClash, known: setup.shortcuts != nil, fix: setup.hasShortcutClash ? "Choose Another Prefix" : nil, action: openShortcuts, statusAccessibilityLabel: shortcutAccessibilityStatus, - statusShortcut: setup.shortcuts?.warnings.first?.chord) + statusShortcut: setup.shortcuts?.warnings.first?.chord, + error: setup.checkErrors[.shortcuts], secondary: setup.shortcuts?.limitations ?? [], + retry: { retry(.shortcuts) }, retryIdentifier: "tour.retry.shortcuts", + isChecking: setup.checkingChecks.contains(.shortcuts)) if setup.showsVoiceOverChoice { VStack(alignment: .leading, spacing: 8) { Text(TourText.text("⌃⌥ is also VoiceOver’s key. Use ⌥⌘ instead?")) @@ -50,6 +56,12 @@ struct TourAllowView: View { Toggle(TourText.text("Open at Login"), isOn: $setup.openAtLogin) .disabled(setup.isBusy) .accessibilityIdentifier("tour.login") + if let error = setup.checkErrors[.login] { + TourCheckRow( + title: "Open at Login", status: error, ready: false, known: true, + error: error, retry: { retry(.login) }, retryIdentifier: "tour.retry.login", + isChecking: setup.checkingChecks.contains(.login)) + } if setup.needsLoginApproval { Button(TourText.text("Approve in Login Items"), action: openLogin) } @@ -75,8 +87,7 @@ struct TourAllowView: View { return warning.messages.first ?? TourText.text("Needs attention") } if let notice = shortcuts.modeNotices.first { return notice } - if let limitation = shortcuts.limitations.first { return limitation } - return TourText.text("No conflicts") + return TourText.text(shortcuts.limitations.isEmpty ? "No conflicts" : "No conflicts in checked shortcuts") } private var shortcutAccessibilityStatus: String { @@ -87,6 +98,10 @@ struct TourAllowView: View { return shortcutStatus } + private func retry(_ check: TourSetupCheck) { + controller.runSetup { try await setup.retryCheck(check) } + } + private func choosePrefix(_ alternate: Bool) { controller.runSetup { try await setup.chooseVoiceOverPrefix(useAlternate: alternate) } } diff --git a/Sources/ParcelUI/Tour/TourCheckRow.swift b/Sources/ParcelUI/Tour/TourCheckRow.swift index dbbb9f69..e79ce563 100644 --- a/Sources/ParcelUI/Tour/TourCheckRow.swift +++ b/Sources/ParcelUI/Tour/TourCheckRow.swift @@ -10,6 +10,11 @@ struct TourCheckRow: View { var action: () -> Void = {} var statusAccessibilityLabel: String? var statusShortcut: KeyChord? + var error: String? + var secondary: [String] = [] + var retry: (() -> Void)? + var retryIdentifier = "tour.retry" + var isChecking = false var body: some View { ViewThatFits(in: .horizontal) { @@ -29,31 +34,48 @@ struct TourCheckRow: View { @ViewBuilder private var fixButton: some View { - if let fix, known && !ready { + if let retry, error != nil { + Button(TourText.text("Try Again"), action: retry) + .disabled(isChecking) + .accessibilityLabel( + String(format: TourText.text("%1$@ · %2$@"), TourText.text("Try Again"), TourText.text(title)) + ) + .accessibilityIdentifier(retryIdentifier) + } else if let fix, known && !ready { Button(TourText.text(fix), action: action) } } private var stateText: some View { VStack(alignment: .leading, spacing: 4) { - if let statusShortcut { + if error == nil, let statusShortcut { ShortcutLabel(chord: statusShortcut) } - Text(status) + Text(error ?? status) .foregroundStyle(.secondary) .fixedSize(horizontal: false, vertical: true) + ForEach(secondary, id: \.self) { detail in + Text(detail) + .font(.callout) + .foregroundStyle(.secondary) + .fixedSize(horizontal: false, vertical: true) + } } .accessibilityElement(children: .ignore) - .accessibilityLabel(statusAccessibilityLabel ?? status) + .accessibilityLabel(([error ?? statusAccessibilityLabel ?? status] + secondary).joined(separator: "\n")) } private var label: some View { Label { Text(TourText.text(title)) } icon: { - Image(systemName: ready ? "checkmark.circle.fill" : known ? "exclamationmark.triangle.fill" : "clock") - .foregroundStyle(ready ? Color.green : known ? Color.orange : Color.secondary) - .accessibilityHidden(true) + Image( + systemName: error != nil + ? "exclamationmark.triangle.fill" + : ready ? "checkmark.circle.fill" : known ? "exclamationmark.triangle.fill" : "clock" + ) + .foregroundStyle(error != nil ? Color.orange : ready ? Color.green : known ? Color.orange : Color.secondary) + .accessibilityHidden(true) } } } diff --git a/Sources/ParcelUI/Tour/TourSetup.swift b/Sources/ParcelUI/Tour/TourSetup.swift index 7af24416..68c296bc 100644 --- a/Sources/ParcelUI/Tour/TourSetup.swift +++ b/Sources/ParcelUI/Tour/TourSetup.swift @@ -24,6 +24,10 @@ public enum TourLoginStatus: Equatable, Sendable { case disabled, enabled, requiresApproval } +public enum TourSetupCheck: String, CaseIterable, Sendable { + case permission, system, shortcuts, login +} + public struct TourSystemCheck: Equatable, Sendable { public let stageManager: Bool? public let nativeTiling: Bool? @@ -180,6 +184,10 @@ public final class TourSetupController { private var loginDraftPending = false private var isRefreshingAllow = false public var showsVoiceOverChoice: Bool { voiceOverEnabled && !voiceOverChoiceMade } + public private(set) var checkErrors: [TourSetupCheck: String] = [:] + public private(set) var checkingChecks: Set = [] + private var loginWriteFailed = false + private var checkRevision: UInt64 = 0 public private(set) var shortcuts: TourShortcutCheck? public private(set) var system: TourSystemCheck? public private(set) var login: TourLoginStatus? @@ -206,6 +214,9 @@ public final class TourSetupController { self.track = track startsAtWelcome = firstRun step = firstRun ? .welcome : .basics + checkRevision += 1 + checkErrors.removeAll() + loginWriteFailed = false shortcuts = nil system = nil login = nil @@ -268,6 +279,9 @@ public final class TourSetupController { public func restart() async throws { guard !isBusy else { throw TourSetupFailure.busy } step = startsAtWelcome ? .welcome : .basics + checkRevision += 1 + checkErrors.removeAll() + loginWriteFailed = false shortcuts = nil system = nil login = nil @@ -292,9 +306,8 @@ public final class TourSetupController { guard !isBusy else { return false } switch step { case .welcome, .basics, .powerMoves: return true - case .allow: - return permission == .granted && login != nil && system != nil && shortcuts != nil && errorMessage == nil - case .personalize: return draft?.isValid == true + case .allow: return true + case .personalize: return draft?.isValid == true || (draft == nil && errorMessage != nil) case .tidy, .complete: return false } } @@ -304,66 +317,105 @@ public final class TourSetupController { case .allow: try await refreshAllowChecks() case .personalize: if draft == nil { - var values = try requireActions().personalization() - values.windowCount = min(5, max(1, values.windowCount)) - draftEditor = TourPersonalizationEditor(values) + do { + try Task.checkCancellation() + var values = try requireActions().personalization() + values.windowCount = min(5, max(1, values.windowCount)) + draftEditor = TourPersonalizationEditor(values) + errorMessage = nil + } catch is CancellationError { + throw CancellationError() + } catch { + errorMessage = error.localizedDescription + } } case .welcome, .basics, .powerMoves, .tidy, .complete: break } } public func refreshAllowChecks() async throws { - guard isPresented, step == .allow, !isRefreshingAllow else { return } + guard isPresented, step == .allow, !isRefreshingAllow, !isBusy else { return } isRefreshingAllow = true defer { isRefreshingAllow = false } + let revision = checkRevision + for check in TourSetupCheck.allCases { + guard isPresented, step == .allow, revision == checkRevision else { return } + try await runCheck(check) + } + guard revision == checkRevision else { return } + if shouldAdvanceAllow { try await leaveAllow() } + } + + public func retryCheck(_ check: TourSetupCheck) async throws { + guard isPresented, step == .allow, !isRefreshingAllow, !isBusy, checkingChecks.isEmpty else { return } + if check == .login, loginWriteFailed { + checkingChecks.insert(check) + defer { checkingChecks.remove(check) } + try await applyLoginDraft() + } else { + try await runCheck(check) + } + } + + private var shouldAdvanceAllow: Bool { + isPresented && step == .allow && permission == .granted && autoAdvancePermission + && !isBusy && !showsVoiceOverChoice && checkErrors.isEmpty && checkingChecks.isEmpty + && system != nil && shortcuts != nil && login != nil + } + + private func runCheck(_ check: TourSetupCheck) async throws { + let revision = checkRevision + checkingChecks.insert(check) + defer { checkingChecks.remove(check) } do { - let actions = try requireActions() - let permission = await actions.permissionStatus() try Task.checkCancellation() - guard isPresented, step == .allow else { return } - self.permission = permission - let system = try await actions.checkSystem() - try Task.checkCancellation() - guard isPresented, step == .allow else { return } - self.system = system - let shortcuts = try await actions.checkShortcuts() - try Task.checkCancellation() - guard isPresented, step == .allow else { return } - self.shortcuts = shortcuts - login = try actions.loginStatus() - if !loginDraftPending { - loginSelection = login != .disabled - if login != .disabled { enableLoginByDefault = false } - if enableLoginByDefault && !hasAppliedLoginDefault && login == .disabled { - loginSelection = true - loginDraftPending = true + let actions = try requireActions() + switch check { + case .permission: + let value = await actions.permissionStatus() + try Task.checkCancellation() + guard isPresented, step == .allow, revision == checkRevision else { return } + permission = value + case .system: + let value = try await actions.checkSystem() + try Task.checkCancellation() + guard isPresented, step == .allow, revision == checkRevision else { return } + system = value + case .shortcuts: + let value = try await actions.checkShortcuts() + try Task.checkCancellation() + guard isPresented, step == .allow, revision == checkRevision else { return } + shortcuts = value + case .login: + login = try actions.loginStatus() + if !loginDraftPending { + loginSelection = login != .disabled + if login != .disabled { enableLoginByDefault = false } + if enableLoginByDefault && !hasAppliedLoginDefault && login == .disabled { + loginSelection = true + loginDraftPending = true + } } + if loginWriteFailed { return } } - errorMessage = nil - if self.permission == .granted && autoAdvancePermission && !isBusy && !showsVoiceOverChoice { - try await leaveAllow() - } + checkErrors.removeValue(forKey: check) } catch is CancellationError { throw CancellationError() } catch { - errorMessage = error.localizedDescription - throw error + guard isPresented, step == .allow, revision == checkRevision else { return } + checkErrors[check] = error.localizedDescription } } public func refreshPermission() async throws { - guard isPresented, step == .allow else { return } - let permission = try await requireActions().permissionStatus() - try Task.checkCancellation() - guard isPresented, step == .allow else { return } - let newlyGranted = self.permission != .granted && permission == .granted - self.permission = permission + guard isPresented, step == .allow, !checkingChecks.contains(.permission) else { return } + let previous = permission + try await runCheck(.permission) + let newlyGranted = previous != .granted && permission == .granted if newlyGranted, errorMessage == TourSetupFailure.accessibilityRequired.localizedDescription { errorMessage = nil } - if newlyGranted && autoAdvancePermission && canContinue && !showsVoiceOverChoice { - try await leaveAllow() - } + if newlyGranted && shouldAdvanceAllow { try await leaveAllow() } } public func updateVoiceOver(_ enabled: Bool) { voiceOverEnabled = enabled } @@ -380,11 +432,40 @@ public final class TourSetupController { } private func leaveAllow() async throws { - try await perform { try await commitLoginDraft() } + if checkErrors[.login] != nil { + loginDraftPending = false + loginRequest = nil + loginSelection = login == .enabled || login == .requiresApproval + loginWriteFailed = false + } else { + try await applyLoginDraft() + guard checkErrors[.login] == nil else { return } + } guard isPresented, step == .allow else { return } + errorMessage = nil step = .basics } + private func applyLoginDraft() async throws { + guard !isBusy else { throw TourSetupFailure.busy } + isBusy = true + defer { isBusy = false } + let revision = checkRevision + do { + try Task.checkCancellation() + try await commitLoginDraft() + guard isPresented, step == .allow, revision == checkRevision else { return } + loginWriteFailed = false + checkErrors.removeValue(forKey: .login) + } catch is CancellationError { + throw CancellationError() + } catch { + guard isPresented, step == .allow, revision == checkRevision else { return } + loginWriteFailed = true + checkErrors[.login] = error.localizedDescription + } + } + private func commitLoginDraft() async throws { guard loginDraftPending else { return } login = try await requireActions().setOpenAtLogin(openAtLogin) @@ -415,6 +496,11 @@ public final class TourSetupController { throw TourSetupFailure.notReady } if step == .allow { try await leaveAllow(); return } + if step == .personalize, draft == nil { + confirmedSkipChoice = false + try await resolveSkip(tidyNow: false) + return + } step = TourSetupStep.allCases[index + 1] if step == .allow { autoAdvancePermission = true } try await checkCurrentStep() @@ -442,6 +528,8 @@ public final class TourSetupController { guard step == .tidy, let draft, draft.isValid else { throw TourSetupFailure.notReady } try await perform { let actions = try requireActions() + permission = await actions.permissionStatus() + guard permission == .granted else { throw TourSetupFailure.accessibilityRequired } system = try await actions.checkSystem() guard system?.isClear == true else { throw TourSetupFailure.systemConflict } try await commitLoginDraft() @@ -498,7 +586,7 @@ public enum TourSetupFailure: LocalizedError { public var errorDescription: String? { switch self { - case .unavailable: TourText.text("Reopen the tour to try setup again.") + case .unavailable: TourText.text("Setup is unavailable right now. Try again or continue anyway.") case .accessibilityRequired: TourText.text("Allow Accessibility before tidying your windows.") case .notReady: TourText.text("Complete this step before continuing.") case .invalidDraft: TourText.text("Choose a valid window count and a highlight width between 2 and 6 points.") diff --git a/Sources/ParcelUI/Tour/TourSetupView.swift b/Sources/ParcelUI/Tour/TourSetupView.swift index cdb26450..bd1e3cb4 100644 --- a/Sources/ParcelUI/Tour/TourSetupView.swift +++ b/Sources/ParcelUI/Tour/TourSetupView.swift @@ -82,6 +82,13 @@ struct TourSetupView: View { Label(error, systemImage: "exclamationmark.triangle") .fixedSize(horizontal: false, vertical: true) .accessibilityIdentifier("tour.error") + if setup.step == .personalize { + Button(TourText.text("Try Again")) { + controller.runSetup { try await setup.checkCurrentStep() } + } + .disabled(setup.isBusy) + .accessibilityIdentifier("tour.retry.personalize") + } } } .frame(maxWidth: .infinity, alignment: .leading) @@ -127,6 +134,14 @@ struct TourSetupView: View { if setup.isBusy { ProgressView().controlSize(.small).accessibilityLabel(TourText.text("Working…")) } + if setup.step == .allow, setup.permission != .granted { + Button(TourText.text("Continue anyway")) { + controller.runSetup { try await setup.next() } + } + .fixedSize() + .disabled(!setup.canContinue) + .accessibilityIdentifier("tour.continueAnyway") + } Button(primaryTitle, action: primary) .buttonStyle(.borderedProminent) .fixedSize() @@ -136,8 +151,13 @@ struct TourSetupView: View { } private var primaryTitle: String { - setup.step == .allow && setup.permission == .granted - ? TourText.text("Continue") : TourText.text(setup.step.primaryTitle) + if setup.step == .allow, setup.permission == .granted { + return TourText.text(setup.checkErrors.isEmpty ? "Continue" : "Continue anyway") + } + if setup.step == .personalize, setup.draft == nil, setup.errorMessage != nil { + return TourText.text("Continue anyway") + } + return TourText.text(setup.step.primaryTitle) } private var primaryEnabled: Bool { diff --git a/Tests/ParcelAppTests/AppRuntimeRegressionTests.swift b/Tests/ParcelAppTests/AppRuntimeRegressionTests.swift index 41047bfb..e6c124cb 100644 --- a/Tests/ParcelAppTests/AppRuntimeRegressionTests.swift +++ b/Tests/ParcelAppTests/AppRuntimeRegressionTests.swift @@ -351,6 +351,29 @@ struct AppRuntimeRegressionTests { #expect(kinds == [.permission, .configuration, .internalFailure]) } + @Test func engineDiagnosticNoticesPreserveActionableErrorsInsteadOfGenericCopy() { + let log = AppEngineLog() + let notices = AppNotices() + var reports: [AppNotices.Report] = [] + log.failure = { error, kind in + guard !notices.recordDiagnosticIfNeeded(error, kind: kind) else { return } + reports.append(notices.report(error, kind: kind)) + } + log.record(.internalFailure(NSError(domain: "FirstLaunch", code: -1))) + log.record(.internalFailure(TourSetupFailure.unavailable)) + log.record( + .platform( + .unexpected(EngineUnexpectedFailure(cause: AXPlatformError.unavailable("fixture menu unavailable"))))) + #expect(reports.isEmpty) + log.record(.internalFailure(EngineError.settingsUnavailable)) + log.record(.platform(.unexpected(EngineUnexpectedFailure(cause: EngineError.stopped)))) + #expect( + reports.map(\.message) == [ + EngineError.settingsUnavailable.localizedDescription, EngineError.stopped.localizedDescription, + ]) + #expect(reports.allSatisfy { $0.message != AppNotices.Kind.internalFailure.message }) + } + @Test func snapshotsPublishOnlyChangedTopics() { var changes = AppSnapshotChanges() var state = State() diff --git a/Tests/ParcelAppTests/CompositionTests.swift b/Tests/ParcelAppTests/CompositionTests.swift index 3771fe53..41466bab 100644 --- a/Tests/ParcelAppTests/CompositionTests.swift +++ b/Tests/ParcelAppTests/CompositionTests.swift @@ -213,7 +213,36 @@ struct CompositionTests { #expect(context.runtime.notices == [AppNotices.Kind.restoration.message]) #expect(context.app.notices.counts == [.restoration: 1]) context.app.report(AXPlatformError.timedOut, kind: .internalFailure) - #expect(context.app.notices.counts[.internalFailure] == 1) + #expect(context.app.notices.counts[.internalFailure] == nil) + #expect(context.runtime.notices == [AppNotices.Kind.restoration.message]) + await context.app.stop() + } + + @Test func setupAndUnreadableMenuFailuresStayInlineOrDiagnosticWithoutNotices() async throws { + let context = await Context.make() + try await context.app.start() + context.app.report(TourSetupFailure.unavailable) + context.app.report( + InputError.accessibility(pid: 629, attribute: "AXChildren", cause: .unavailable("fixture menu unavailable")) + ) + context.app.report(EngineMenuShortcutError.applicationChanged) + context.app.report(CancellationError()) + context.app.report(NSError(domain: "FirstLaunch", code: -1)) + #expect(context.runtime.notices.isEmpty) + #expect(context.runtime.noticeReports.isEmpty) + #expect(context.app.notices.counts.isEmpty) + #expect(context.runtime.problems.isEmpty) + await context.app.stop() + } + + @Test func permissionFailureReportedInternallyOffersTheCorrectRepairAction() async throws { + let context = await Context.make() + try await context.app.start() + context.app.report(InputError.accessibility(pid: 629, attribute: "AXChildren", cause: .notPermitted)) + #expect(context.runtime.notices == [AppNotices.Kind.permission.message]) + #expect(context.runtime.noticeReports.first?.kind == .permission) + #expect(context.runtime.noticeReports.first?.actions == [.accessibilitySettings]) + #expect(context.app.notices.counts == [.permission: 1]) await context.app.stop() } diff --git a/Tests/ParcelAppTests/RuleFailureNoticeTests.swift b/Tests/ParcelAppTests/RuleFailureNoticeTests.swift index 5c60e056..79dc3be1 100644 --- a/Tests/ParcelAppTests/RuleFailureNoticeTests.swift +++ b/Tests/ParcelAppTests/RuleFailureNoticeTests.swift @@ -1,12 +1,72 @@ import Foundation +import ParcelCore import ParcelEngine import ParcelIPC +import ParcelPlatform +import ParcelUI import Testing @testable import ParcelApp @MainActor struct RuleFailureNoticeTests { + @Test(arguments: AppNotices.Kind.allCases) + func cancellationNeverPresentsANotice(kind: AppNotices.Kind) { + #expect(!AppNotices.shouldPresent(CancellationError(), kind: kind)) + } + + @Test func genericInternalFailuresAreLoggedWithoutCreatingNoticeState() { + let notices = AppNotices() + let errors: [any Error] = [ + UnlocalizedFailure(), TourSetupFailure.unavailable, + IPCError(code: "space_command_failed", message: "raw AX failure"), + InputError.accessibility( + pid: 629, attribute: "AXChildren", cause: .unavailable("fixture menu unavailable")), + AXPlatformError.timedOut, EngineMenuShortcutError.applicationChanged, + ] + for error in errors { + #expect(!AppNotices.shouldPresent(error, kind: .internalFailure)) + #expect(notices.recordDiagnosticIfNeeded(error, kind: .internalFailure)) + #expect(AppNotices.kind(for: .internalFailure(error)) == nil) + } + #expect(notices.counts.isEmpty) + #expect(notices.shortcutRepairActions.isEmpty) + } + + @Test func permissionErrorsRetainActionableClassificationThroughInternalDiagnostics() { + let app = AppID(pid: 629, bundleID: "com.apple.finder") + let errors: [any Error] = [ + AXPlatformError.notPermitted, InputError.accessibilityRequired, + InputError.accessibility(pid: 629, attribute: "AXChildren", cause: .notPermitted), + EnginePlatformFailure.accessibility(app, window: nil, cause: .notPermitted), + EnginePlatformFailure.unexpected(EngineUnexpectedFailure(cause: AXPlatformError.notPermitted)), + ] + for error in errors { + let notices = AppNotices() + #expect(AppNotices.shouldPresent(error, kind: .internalFailure)) + #expect(!notices.recordDiagnosticIfNeeded(error, kind: .internalFailure)) + #expect(AppNotices.kind(for: .internalFailure(error)) == .permission) + let report = notices.report(error, kind: .internalFailure) + #expect(report.kind == .permission) + #expect(report.message == AppNotices.Kind.permission.message) + #expect(report.actions == [.accessibilitySettings]) + #expect(notices.counts == [.permission: 1]) + } + } + + @Test func meaningfulActionFailuresStillPresentIndependently() { + let notices = AppNotices() + let failure = AppFailure(message: "Focus a window on this display first.") + #expect(AppNotices.shouldPresent(failure, kind: .internalFailure)) + #expect(!notices.recordDiagnosticIfNeeded(failure, kind: .internalFailure)) + #expect(AppNotices.kind(for: .internalFailure(failure)) == .internalFailure) + let first = notices.report(failure, kind: .internalFailure) + let second = notices.report(failure, kind: .internalFailure) + #expect(first.message == failure.message) + #expect(second.message == first.message) + #expect(first.count == 1 && second.count == 2) + } + @Test func settingsUnavailableProvidesAnActionableNotice() { let notices = AppNotices() let failure = EngineError.settingsUnavailable diff --git a/Tests/ParcelUITests/Tour/TourSetupTests.swift b/Tests/ParcelUITests/Tour/TourSetupTests.swift index 489e38d3..176d448d 100644 --- a/Tests/ParcelUITests/Tour/TourSetupTests.swift +++ b/Tests/ParcelUITests/Tour/TourSetupTests.swift @@ -107,7 +107,7 @@ struct TourSetupTests { } @Test(arguments: [PermissionStatus.checking, .missing]) - func ungrantedPermissionCannotAdvanceButStillChecksAllowServices(permission: PermissionStatus) async throws { + func ungrantedPermissionCanContinueWithoutMovingWindows(permission: PermissionStatus) async throws { let fixture = TourSetupFixture() fixture.permission = permission let setup = fixture.controller @@ -115,7 +115,7 @@ struct TourSetupTests { try await setup.next() #expect(setup.step == .allow) #expect(setup.permission == permission) - #expect(!setup.canContinue) + #expect(setup.canContinue) #expect(setup.system == fixture.system) #expect(setup.shortcuts == fixture.shortcuts) #expect(setup.login == .disabled) @@ -125,8 +125,12 @@ struct TourSetupTests { #expect(fixture.shortcutChecks == 1) #expect(fixture.loginChecks == 1) #expect(fixture.loginWrites.isEmpty) - await #expect(throws: TourSetupFailure.self) { try await setup.next() } + try await setup.next() + #expect(setup.step == .basics) + try await fixture.reachPersonalization() + try await setup.next() await #expect(throws: TourSetupFailure.self) { try await setup.tidyWorkspace() } + #expect(setup.errorMessage == TourSetupFailure.accessibilityRequired.localizedDescription) #expect(fixture.tidyAttempts.isEmpty) } @@ -188,7 +192,7 @@ struct TourSetupTests { try await setup.next() #expect(setup.system == check) #expect(setup.system?.isClear == false) - #expect(!setup.canContinue) + #expect(setup.canContinue) fixture.permission = .granted try await setup.refreshPermission() #expect(setup.step == .basics) @@ -221,17 +225,18 @@ struct TourSetupTests { try await setup.next() #expect(setup.system?.isClear == true) fixture.failSystem = true - await #expect(throws: TourSetupFailure.self) { try await setup.checkCurrentStep() } + try await setup.checkCurrentStep() #expect(setup.system == fixture.system) #expect(setup.step == .allow) - #expect(!setup.canContinue) + #expect(setup.canContinue) #expect(!setup.isBusy) - #expect(setup.errorMessage != nil) + #expect(setup.checkErrors[.system] != nil) + #expect(setup.errorMessage == nil) #expect(fixture.tidyAttempts.isEmpty) fixture.failSystem = false - try await setup.checkCurrentStep() + try await setup.retryCheck(.system) #expect(setup.system == fixture.system) - #expect(setup.errorMessage == nil) + #expect(setup.checkErrors[.system] == nil) #expect(fixture.loginWrites.isEmpty) } @@ -250,14 +255,178 @@ struct TourSetupTests { #expect(setup.shortcuts?.limitations == ["Menu access unavailable"]) #expect(setup.hasShortcutClash) fixture.failChecks = true - await #expect(throws: TourSetupFailure.self) { try await setup.checkCurrentStep() } + try await setup.checkCurrentStep() #expect(setup.shortcuts == fixture.shortcuts) #expect(setup.hasShortcutClash) - #expect(!setup.canContinue) + #expect(setup.canContinue) + #expect(setup.checkErrors[.shortcuts] != nil) + #expect(setup.errorMessage == nil) + #expect(fixture.tidyAttempts.isEmpty) + } + + @Test(arguments: [TourSetupCheck.system, .shortcuts, .login]) + func failedChecksDoNotStopOtherChecksAndRetryOnlyTheSelectedCheck(check: TourSetupCheck) async throws { + let fixture = TourSetupFixture() + let setup = fixture.controller + fixture.failSystem = check == .system + fixture.failChecks = check == .shortcuts + fixture.failLoginStatus = check == .login + setup.begin(.keyboard, firstRun: true, defaultOpenAtLogin: true) + try await setup.next() + #expect(setup.step == .allow) + #expect(Set(setup.checkErrors.keys) == [check]) + #expect(setup.canContinue) + #expect(setup.errorMessage == nil) + #expect(setup.checkingChecks.isEmpty) + #expect(fixture.permissionChecks == 1) + #expect(fixture.systemChecks == 1) + #expect(fixture.shortcutChecks == 1) + #expect(fixture.loginChecks == 1) + #expect(fixture.loginWrites.isEmpty) + try await setup.retryCheck(check) + #expect(setup.checkErrors[check] != nil) + fixture.failSystem = false + fixture.failChecks = false + fixture.failLoginStatus = false + try await setup.retryCheck(check) + #expect(setup.checkErrors.isEmpty) + #expect(setup.step == .allow) + #expect(fixture.permissionChecks == 1) + #expect(fixture.systemChecks == (check == .system ? 3 : 1)) + #expect(fixture.shortcutChecks == (check == .shortcuts ? 3 : 1)) + #expect(fixture.loginChecks == (check == .login ? 3 : 1)) + #expect(fixture.loginWrites.isEmpty) + try await setup.next() + #expect(setup.step == .basics) + #expect(fixture.tidyAttempts.isEmpty) + } + + @Test func everyFailedAllowCheckStillPermitsExplicitContinuation() async throws { + let fixture = TourSetupFixture() + fixture.failSystem = true + fixture.failChecks = true + fixture.failLoginStatus = true + fixture.permission = .missing + let setup = fixture.controller + setup.begin(.keyboard, firstRun: true, defaultOpenAtLogin: true) + try await setup.next() + #expect(Set(setup.checkErrors.keys) == [.system, .shortcuts, .login]) + #expect(setup.permission == .missing) + #expect(setup.canContinue) + try await setup.next() + #expect(setup.step == .basics) + #expect(setup.login == nil) + #expect(setup.loginRequest == nil) + #expect(fixture.loginWrites.isEmpty) + #expect(fixture.tidyAttempts.isEmpty) + } + + @Test func permissionRetryDoesNotRepeatOtherChecks() async throws { + let fixture = TourSetupFixture() + let setup = fixture.controller + let actions = setup.actions + setup.actions = nil + setup.begin(.keyboard, firstRun: true) + try await setup.next() + #expect(setup.checkErrors[.permission] != nil) + setup.actions = actions + try await setup.retryCheck(.permission) + #expect(setup.permission == .granted) + #expect(setup.checkErrors[.permission] == nil) + #expect(Set(setup.checkErrors.keys) == [.system, .shortcuts, .login]) + #expect(fixture.permissionChecks == 1) + #expect(fixture.systemChecks == 0) + #expect(fixture.shortcutChecks == 0) + #expect(fixture.loginChecks == 0) + } + + @Test(arguments: [TourSetupCheck.system, .shortcuts]) + func cancelledCheckDoesNotBecomeARetryableFailure(check: TourSetupCheck) async throws { + let fixture = TourSetupFixture() + fixture.permission = .missing + let setup = fixture.controller + setup.begin(.keyboard, firstRun: true) + try await setup.next() + var actions = try #require(setup.actions) + if check == .system { actions.checkSystem = { throw CancellationError() } } + if check == .shortcuts { actions.checkShortcuts = { throw CancellationError() } } + setup.actions = actions + await #expect(throws: CancellationError.self) { try await setup.retryCheck(check) } + #expect(setup.checkErrors[check] == nil) + #expect(setup.checkingChecks.isEmpty) + #expect(setup.system == fixture.system) + #expect(setup.shortcuts == fixture.shortcuts) + #expect(setup.canContinue) + } + + @Test func continuingAfterLoginWriteFailureDiscardsTheDraftWithoutRetrying() async throws { + let fixture = TourSetupFixture() + fixture.failLogin = true + let setup = fixture.controller + setup.begin(.keyboard, firstRun: true, defaultOpenAtLogin: true) + try await setup.next() + #expect(setup.step == .allow) + #expect(setup.checkErrors[.login] != nil) + #expect(fixture.loginWrites == [true]) + let systemChecks = fixture.systemChecks + let shortcutChecks = fixture.shortcutChecks + let loginChecks = fixture.loginChecks + try await setup.retryCheck(.login) + #expect(fixture.loginWrites == [true, true]) + #expect(fixture.systemChecks == systemChecks) + #expect(fixture.shortcutChecks == shortcutChecks) + #expect(fixture.loginChecks == loginChecks) + try await setup.next() + #expect(setup.step == .basics) + #expect(setup.login == .disabled) + #expect(!setup.openAtLogin) + #expect(setup.loginRequest == nil) + fixture.failLogin = false + try await fixture.reachPersonalization() + try await setup.next() + try await setup.tidyWorkspace() + #expect(fixture.loginWrites == [true, true]) + #expect(setup.didTidy) + } + + @Test func failedPersonalizationCanRetryWithoutRepeatingAllowChecks() async throws { + let fixture = TourSetupFixture() + fixture.failPersonalization = true + let setup = fixture.controller + setup.begin(.keyboard) + try await fixture.reachPersonalization() + #expect(setup.draft == nil) #expect(setup.errorMessage != nil) + #expect(setup.canContinue) + fixture.failPersonalization = false + try await setup.checkCurrentStep() + #expect(setup.draft != nil) + #expect(setup.errorMessage == nil) + #expect(fixture.personalizationReads == 2) + #expect(fixture.permissionChecks == 0) + #expect(fixture.systemChecks == 0) + #expect(fixture.shortcutChecks == 0) + #expect(fixture.loginChecks == 0) #expect(fixture.tidyAttempts.isEmpty) } + @Test func continuingAfterPersonalizationFailureCompletesWithoutTidy() async throws { + let fixture = TourSetupFixture() + fixture.failPersonalization = true + let setup = fixture.controller + setup.begin(.keyboard) + try await fixture.reachPersonalization() + #expect(setup.canContinue) + try await setup.next() + #expect(setup.step == .complete) + #expect(!setup.didTidy) + #expect(setup.draft == nil) + #expect(setup.errorMessage == nil) + #expect(fixture.skipCalls == [false]) + #expect(fixture.tidyAttempts.isEmpty) + #expect(fixture.loginWrites.isEmpty) + } + @Test func otherAppMenuClashesReachTheTourShortcutCheck() throws { let chord = try #require(ParcelConfiguration.defaults.keybindings[.swapLeft]) let menu = MenuShortcut( @@ -386,17 +555,21 @@ struct TourSetupTests { fixture.failLogin = true let setup = fixture.controller setup.begin(.keyboard, firstRun: true, defaultOpenAtLogin: true) - await #expect(throws: TourSetupFailure.self) { try await setup.next() } + try await setup.next() #expect(setup.step == .allow) #expect(setup.login == .disabled) - #expect(setup.errorMessage != nil) + #expect(setup.checkErrors[.login] != nil) + #expect(setup.canContinue) #expect(!setup.isBusy) #expect(fixture.loginWrites == [true]) fixture.failLogin = false fixture.loginResult = .requiresApproval - try await setup.checkCurrentStep() - #expect(setup.step == .basics) + try await setup.retryCheck(.login) + #expect(setup.step == .allow) #expect(setup.login == .requiresApproval) + #expect(setup.checkErrors[.login] == nil) + try await setup.next() + #expect(setup.step == .basics) #expect(setup.errorMessage == nil) #expect(fixture.loginWrites == [true, true]) #expect(fixture.tidyAttempts.isEmpty) @@ -416,14 +589,16 @@ struct TourSetupTests { #expect(fixture.loginWrites.isEmpty) #expect(setup.login == .requiresApproval) fixture.permission = .granted - await #expect(throws: TourSetupFailure.self) { try await setup.refreshPermission() } + try await setup.refreshPermission() #expect(setup.login == .requiresApproval) - #expect(setup.errorMessage != nil) + #expect(setup.checkErrors[.login] != nil) + #expect(setup.canContinue) #expect(!setup.isBusy) fixture.failLogin = false fixture.loginResult = .disabled - try await setup.checkCurrentStep() + try await setup.retryCheck(.login) #expect(setup.login == .disabled) + #expect(setup.checkErrors[.login] == nil) #expect(setup.errorMessage == nil) #expect(fixture.loginWrites == [false, false]) #expect(fixture.tidyAttempts.isEmpty) @@ -435,16 +610,17 @@ struct TourSetupTests { fixture.failLoginStatus = true let setup = fixture.controller setup.begin(.keyboard, firstRun: true, defaultOpenAtLogin: true) - await #expect(throws: TourSetupFailure.self) { try await setup.next() } + try await setup.next() #expect(setup.login == nil) - #expect(!setup.canContinue) - #expect(setup.errorMessage != nil) + #expect(setup.canContinue) + #expect(setup.checkErrors[.login] != nil) + #expect(setup.errorMessage == nil) #expect(fixture.loginWrites.isEmpty) fixture.failLoginStatus = false - try await setup.checkCurrentStep() + try await setup.retryCheck(.login) #expect(setup.login == .disabled) #expect(setup.openAtLogin) - #expect(setup.errorMessage == nil) + #expect(setup.checkErrors[.login] == nil) #expect(fixture.loginWrites.isEmpty) } @@ -879,19 +1055,20 @@ struct TourSetupTests { #expect(fixture.skipCalls.isEmpty) } - @Test func missingIntegrationSurfacesAnErrorAtAllow() async { + @Test func missingIntegrationSurfacesIndividualErrorsWithoutBlockingAllow() async throws { let setup = TourSetupController() setup.begin(.keyboard, firstRun: true, defaultOpenAtLogin: true) - await #expect(throws: TourSetupFailure.self) { try await setup.next() } + try await setup.next() #expect(setup.step == .allow) - #expect(setup.errorMessage != nil) - #expect(!setup.canContinue) + #expect(Set(setup.checkErrors.keys) == Set(TourSetupCheck.allCases)) + #expect(setup.errorMessage == nil) + #expect(setup.canContinue) #expect(!setup.isBusy) #expect(throws: TourSetupFailure.self) { try setup.openAccessibilitySettings() } - setup.requestSkip() - await #expect(throws: TourSetupFailure.self) { try await setup.resolveSkip(tidyNow: false) } - #expect(setup.step == .allow) - #expect(setup.isSkipConfirmationPresented) + try await setup.next() + #expect(setup.step == .basics) + #expect(setup.loginRequest == nil) + #expect(setup.permission == .checking) } @Test func widthValueUsesPointsWithSingularPluralAndFractionalValues() { @@ -1171,6 +1348,7 @@ struct TourSetupTests { var failSystem = false var failLoginStatus = false var failLogin = false + var failPersonalization = false var failTidy = false var failUndo = false var failSkip = false @@ -1201,6 +1379,7 @@ struct TourSetupTests { }, personalization: { [unowned self] in personalizationReads += 1 + if failPersonalization { throw TourSetupFailure.workspaceUnavailable } return personalization }, tidy: { [unowned self] draft in