// The three seams a notification test drives, doubled.//// Everything below stands in for something only a device has — the notification// centre's pending queue, the OS permission, and the vendor identifier. They// live in one file because all three test files use all three, and a double// declared twice is a double that eventually disagrees with itself.importCottonKitimportFoundation/// The notification centre, remembering what it was told.////// `@MainActor` rather than a lock: `NSLock` is unavailable from an async/// context, every test in this family already runs on the main actor, and a/// main-actor class is `Sendable` — which is what the protocol asks for. The/// pass hops to reach it, exactly as it would hop to reach `UNUserNotification/// Center` on a real device.@MainActorfinalclassRecordingCentre: ReminderCentre {privatevar pending: [String]private(set) var cancelled: [[String]] = []private(set) var scheduled: [[DesiredReminder]] = []/// Identifiers `schedule` refuses, so a test can prove one failure does not/// stop the rest.var refuses: Set<String> = []/// Every call, in order — the assertion for "cancel before schedule".private(set) var order: [String] = []init(pending: [String] = []) {self.pending = pending }func heldIdentifiers() async -> [String] { order.append("held")return pending }func cancel(_ identifiers: [String]) async { order.append("cancel") cancelled.append(identifiers) pending.removeAll { identifiers.contains($0) } }func schedule(_ reminders: [DesiredReminder]) async -> Int { order.append("schedule") scheduled.append(reminders)var landed = 0for reminder in reminders where !refuses.contains(reminder.identifier) { pending.append(reminder.identifier) landed += 1 }return landed }var held: [String] { pending }}/// The OS permission, scripted. `@MainActor` for `RecordingCentre`'s reason.@MainActorfinalclassScriptedAuthority: NotificationAuthority {privatevar state: NotificationPermission/// What `ask()` answers. Defaults to whatever `read()` says, so a test that/// does not care need not name one.privatevar answers: NotificationPermission?private(set) var asked = 0private(set) var registeredForRemote = 0init(state: NotificationPermission, answers: NotificationPermission? = nil) {self.state = stateself.answers = answers }func read() async -> NotificationPermission { state }func ask() async -> NotificationPermission { asked += 1iflet answers { state = answers }return state }func registerForRemoteNotifications() async { registeredForRemote += 1 }}/// What the phone knows about itself, named.////// `@MainActor` with the protocol — see `DeviceFactsSource`; the vendor/// identifier is UIKit's and its only caller is a `@MainActor` model.@MainActorstructScriptedFacts: DeviceFactsSource {var facts: DeviceFacts? = DeviceFacts( deviceId: "vendor-1", bundleId: AppFlavor.current.phoneAppID, appVersion: "1.0.0", build: "200", locale: "en_GB", timezone: "Asia/Kolkata" )func read() -> DeviceFacts? { facts }}