Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245import AppKitimport CoreGraphicsimport Foundationimport ParcelConfigimport ParcelCoreimport ParcelEngineimport ParcelIPCimport ParcelPlatformimport ParcelTestSupportimport ParcelUIimport Testing
@testable import ParcelApp
@MainActorstruct NoticeLocalizationRegressionTests { @Test func interpolatedAppGuidanceUsesCatalogFormatKeys() { let detail = "Could not read shortcuts" #expect( AppText.localized("System shortcuts could not be checked: \(detail)") == "System shortcuts could not be checked: Could not read shortcuts") #expect( AppText.localized("App menu shortcuts could not be checked: \(detail)") == "App menu shortcuts could not be checked: Could not read shortcuts") }
@Test(arguments: AppNotices.Kind.allCases) func rawDescriptionsNeverReachNotices(kind: AppNotices.Kind) { let notices = AppNotices() let raw = "raw diagnostic: token=secret failed(-50)" let report = notices.report( NSError(domain: "NoticeTest", code: -50, userInfo: [NSLocalizedDescriptionKey: raw]), kind: kind) #expect(!report.message.isEmpty) #expect(!report.message.contains(raw)) }
@Test func voiceOverNoticeOffersTheAlternatePrefixAndStallsDoNotClaimLostAccess() { let notices = AppNotices() let first = notices.report(InputError.tapTimedOut, kind: .voiceOver) let repeated = notices.report(InputError.tapTimedOut, kind: .voiceOver) #expect(first.message == AppNotices.Kind.voiceOver.message) #expect(repeated.message == first.message && repeated.count == 2) #expect(repeated.actions == [.useAlternatePrefix]) #expect(notices.shortcutRepairActions == [.useAlternatePrefix]) #expect(NoticeAction.useAlternatePrefix.title == "Use ⌥⌘") notices.clear(.voiceOver) #expect(notices.shortcutRepairActions.isEmpty) let stalls = notices.report(InputError.tapTimedOut, kind: .tapStalls) #expect(stalls.message == AppNotices.Kind.tapStalls.message) #expect(stalls.actions.isEmpty) #expect(notices.shortcutRepairActions.isEmpty) #expect(!stalls.message.contains("Accessibility")) #expect(!stalls.message.contains("stopped")) }
@Test func startupFailureOffersRetryWithoutClaimingAccessibilityIsMissing() { let notices = AppNotices() let report = notices.report(TourSetupFailure.unavailable, kind: .startup) #expect(report.message == AppNotices.Kind.startup.message) #expect(report.actions == [.retryStartup]) #expect(notices.shortcutRepairActions == [.retryStartup]) #expect(NoticeAction.retryStartup.title == "Try again") #expect(!report.message.contains("Accessibility")) notices.clear(.startup) #expect(notices.shortcutRepairActions.isEmpty) }
@Test func ipcMessageIsNotTreatedAsHumanLocalizedCopy() { let notices = AppNotices() let report = notices.report( IPCError(code: "space_command_failed", message: "raw AX failure -25202"), kind: .internalFailure) #expect(report.message == AppNotices.Kind.internalFailure.message) }
@Test func typedEngineFailurePreservesHumanGuidanceWithoutRawConfigurationDetails() { let notices = AppNotices() let unavailable = notices.report(EngineError.settingsUnavailable, kind: .internalFailure) #expect(unavailable.message == EngineError.settingsUnavailable.localizedDescription) let invalid = notices.report(EngineError.invalidConfiguration("raw parser detail"), kind: .internalFailure) #expect(!invalid.message.contains("raw parser detail")) }
@Test func inputReportsRepeatAndChangeToTheRelevantPrivacyPane() { let notices = AppNotices() let first = notices.report(AppInputFailure.accessibility, kind: .input) let repeated = notices.report(AppInputFailure.accessibility, kind: .input) #expect(first.message == repeated.message) #expect(first.count == 1 && repeated.count == 2) #expect(notices.shortcutRepairActions == [.accessibilitySettings]) let updated = notices.report(AppInputFailure.inputMonitoring, kind: .input) #expect(updated.actions == [.inputMonitoringSettings]) #expect(notices.shortcutRepairActions == [.inputMonitoringSettings]) #expect(updated.message.contains("Input Monitoring")) notices.clear(.input) #expect(notices.shortcutRepairActions.isEmpty) }
@Test func transientFailuresDoNotReplacePersistentRepairActions() { let notices = AppNotices() notices.report(AppInputFailure.inputMonitoring, kind: .input) notices.report(AppFailure(message: "Focus a window first"), kind: .internalFailure) #expect(notices.shortcutRepairActions == [.inputMonitoringSettings]) #expect(notices.configurationReason == nil) }
@Test func configurationFailureKeepsTheLatestHumanReasonUntilResolved() { let notices = AppNotices() let first = notices.report(AppFailure(message: "First apply failure"), kind: .configuration) let latest = notices.report(AppFailure(message: "Latest apply failure"), kind: .configuration) #expect(first.count == 1 && latest.count == 2) #expect(notices.configurationReason == latest.message) notices.clear(.configuration) #expect(notices.configurationReason == nil) }
@Test func configurationWarningDoesNotBecomeAPersistentFailureOrHideOne() { let notices = AppNotices() let warning = ConfigDiagnostic(severity: .warning, message: "Use the current shortcut key") #expect(notices.report(warning).message == warning.description) #expect(notices.configurationReason == nil) notices.report(AppFailure(message: "Shortcuts could not be registered"), kind: .configuration) notices.report(warning) #expect(notices.configurationReason == "Shortcuts could not be registered") #expect(AppText.configurationNotice([warning]) == nil) }
@Test func inputFailureSelectsPrivacyPaneFromEvidenceNotCarbonStatus() { let error = InputError.tapFallbackFailed(carbonStatus: -9868, cause: .tapCreationFailed) #expect(AppInputFailure.classify(error, accessibility: false, inputMonitoring: false) == .accessibility) #expect(AppInputFailure.classify(error, accessibility: true, inputMonitoring: false) == .inputMonitoring) #expect(AppInputFailure.classify(error, accessibility: true, inputMonitoring: true) == .installation) #expect( AppInputFailure.classify(InputError.tapEnableFailed, accessibility: true, inputMonitoring: true)?.action == .accessibilitySettings) #expect( AppInputFailure.classify( InputError.carbon(operation: "register", status: -9868), accessibility: true, inputMonitoring: false) == nil) }
}
extension AppKitTestSuite { @Suite @MainActor struct NoticeLocalizationCaptureTests { @Test(.enabled(if: Self.captureEnabled(environment: ProcessInfo.processInfo.environment))) func capturesLocalizedAppNotices() throws { let environment = ProcessInfo.processInfo.environment let language = try #require(environment["PARCEL_LOCALIZATION_LANGUAGE"]) let path = try #require(environment["PARCEL_LOCALIZATION_SCREENSHOTS"]) try #require(path.hasPrefix("/"), "Screenshot output must be an absolute private directory.") try requireUnlockedConsole()
let manager = FileManager.default if !manager.fileExists(atPath: path) { try manager.createDirectory( at: URL(fileURLWithPath: path, isDirectory: true), withIntermediateDirectories: true, attributes: [.posixPermissions: 0o700]) } let attributes = try manager.attributesOfItem(atPath: path) let permissions = try #require(attributes[.posixPermissions] as? NSNumber) try #require(permissions.intValue & 0o077 == 0, "Screenshot directory must not be accessible to others.")
let notices = [ ("startup", AppNotices.Kind.startup.message, "Parcel could not start tiling. Try again."), ( "permission", AppNotices.Kind.permission.message, "Accessibility access was lost. Enable Parcel in System Settings." ), ( "voiceover", AppNotices.Kind.voiceOver.message, "VoiceOver is on. Parcel leaves Control Option shortcuts to VoiceOver. Use Option Command instead." ), ( "input-timeout", AppNotices.Kind.tapStalls.message, "Keyboard monitoring repeatedly timed out. Some shortcuts may have reached the active app. Restart Parcel if shortcuts remain unreliable." ), ] let originalAppearance = NSApplication.shared.appearance defer { NSApplication.shared.appearance = originalAppearance } for (name, message, english) in notices { #expect(message != english, "The \(language) notice lookup returned its English source: \(name)") let controller = FeedbackController( model: FeedbackModel(), announce: { _ in }, dismissDelay: .seconds(30), onFailure: { Issue.record($0) }) defer { controller.stop() } controller.update( state: ParcelCore.State(), configuration: MotionConfiguration(enabled: false, sound: false), active: true) controller.showTransientNotice(message) let panel = try #require( NSApplication.shared.windows.first { $0 is NSPanel && $0.isVisible && $0.title == message } as? NSPanel) let content = try #require(panel.contentView) try #require(content.bounds.height < 600, "Notice grew beyond a practical panel height: \(name)") for (scheme, appearanceName) in [(NSAppearance.Name.aqua, "light"), (.darkAqua, "dark")] { let appearance = try #require(NSAppearance(named: scheme)) NSApplication.shared.appearance = appearance panel.appearance = appearance content.layoutSubtreeIfNeeded() panel.displayIfNeeded() let image = try #require(content.bitmapImageRepForCachingDisplay(in: content.bounds)) content.cacheDisplay(in: content.bounds, to: image) try #require(image.pixelsWide > 100 && image.pixelsHigh > 100) let data = try #require(image.representation(using: .png, properties: [:])) let destination = URL(fileURLWithPath: path, isDirectory: true) .appendingPathComponent("notice-\(name)-\(appearanceName).png") try #require( !manager.fileExists(atPath: destination.path), "Refusing to overwrite an existing capture.") try data.write(to: destination, options: .atomic) try manager.setAttributes([.posixPermissions: 0o600], ofItemAtPath: destination.path) } } }
nonisolated private static func captureEnabled(environment: [String: String]) -> Bool { let supported = Set(["es", "fr", "de", "ja", "zh-Hans", "ko", "pt-BR"]) guard let language = environment["PARCEL_LOCALIZATION_LANGUAGE"], supported.contains(language), let path = environment["PARCEL_LOCALIZATION_SCREENSHOTS"], !path.isEmpty else { return false } return true }
private struct ConsoleState: Decodable { let onConsole: Bool let loginDone: Bool let screenLocked: Bool?
private enum CodingKeys: String, CodingKey { case onConsole = "kCGSSessionOnConsoleKey" case loginDone = "kCGSessionLoginDoneKey" case screenLocked = "CGSSessionScreenIsLocked" } }
private func requireUnlockedConsole() throws { try #require(NativeHostAvailability.unavailableReason == nil) let session = try #require(CGSessionCopyCurrentDictionary()) let data = try PropertyListSerialization.data(fromPropertyList: session, format: .binary, options: 0) let state = try PropertyListDecoder().decode(ConsoleState.self, from: data) try #require(state.onConsole && state.loginDone && state.screenLocked != true) } }}