// The doors to the person's own stores on this device — their address book// today — and the rule that only the APP opens one.//// **Why the doors are installed, not built.** On a Mac, `swift test` runs the// package's tests in a process that is signed in to the owner's iCloud: a test// that built a `CNContactStore` reached the owner's real address book over XPC// (run 5653, 11 Oct 2026 — every write was refused and the run hung, but it// was one refusal away from writing invented cards into his contacts). So no// package source builds a store. The live implementations live in the phone// app target (`App/Cotton`), which installs them at launch; the Mac app reads// no address book and installs none. A test// bundle links the package and never the app, so it cannot name them — the// compile fails — and in a test process every door here is shut.// `LiveStoresSweepTests` holds both halves: no package or test source names a// live store (Contacts, Photos, Calendar, Mail), and nothing but an app// installs one.//// The CAMERA ROLL is the second door, write-only: the Camera tool saves a shot// there too while the person leaves that on. Calendar and Mail have no bridge// on this side today; the sweep is what makes the first one come through here.importFoundationimport os/// How much of each card a read asks for.publicenumAddressCardDepth: Sendable {/// Names and phone numbers (Comms' "Find people I know").case namesAndNumbers/// Everything People brings in: names, the platform's composed name, work, numbers, mail, cities, birthday.case whole}/// One card of the address book, as values. The package names no Contacts type: only the app's own book does/// (`App/Cotton/AddressBook+Contacts.swift`), so an app built without it carries no reference to the Contacts API/// and App Store processing asks it for no purpose string (ITMS-90683, 22 Nov 2026).publicstructAddressCard: Sendable, Equatable {publicvar id: String/// The platform's own composed full name (prefix, middle name, suffix, the locale's order), when it has one.publicvar composedName: String?publicvar givenName: Stringpublicvar familyName: Stringpublicvar organization: Stringpublicvar jobTitle: Stringpublicvar phones: [String]publicvar emails: [String]publicvar cities: [String]publicvar birthday: DateComponents?publicinit( id: String, composedName: String? = nil, givenName: String = "", familyName: String = "", organization: String = "", jobTitle: String = "", phones: [String] = [], emails: [String] = [], cities: [String] = [], birthday: DateComponents? = nil ) {self.id = idself.composedName = composedNameself.givenName = givenNameself.familyName = familyNameself.organization = organizationself.jobTitle = jobTitleself.phones = phonesself.emails = emailsself.cities = citiesself.birthday = birthday }}/// A device's address book, as the app opens it. Every call may reach the/// Contacts daemon, so callers make them off the main actor.publicprotocolAddressBook: Sendable {/// What the OS says about contacts now; `limited` is a yes.func access() -> CapabilityAccess/// The one prompt; true when the person said yes.func askAccess() async -> Bool/// Every card, one at a time, by given name.func enumerate(_ depth: AddressCardDepth, _ each: (AddressCard) -> Void) throws/// One card's picture, the full image before the thumbnail.func picture(_ identifier: String) throws -> Data?}/// A device's camera roll, as the app opens it: a shot's file added, never a/// read. The call reaches the Photos daemon, so it is made off the main actor.publicprotocolCameraRoll: Sendable {func save(file: URL, kind: CaptureMediaKind) asyncthrows}/// Why a store could not be reached: this process is not the app.publicstructLiveStoreUnreachable: Error, LocalizedError, Equatable {publiclet store: Stringpublicinit(store: String) {self.store = store }publicvar errorDescription: String? {"This process has no \(store): only the app opens one" }}/// The stores this process may reach — none until the app installs them.publicenumLiveStores {privatestaticlet held = OSAllocatedUnfairLock<(any AddressBook)?>(initialState: nil)/// The app's address book, or nil — always nil in a test process.publicstaticvar addressBook: (any AddressBook)? { held.withLock { $0 } }/// Whether the app has installed its stores. A permission prompt for one of/// them is raised only once it has: a test process is never asked about/// the person's contacts or photos.publicstaticvar installed: Bool { addressBook != nil }/// The address book, or the reason there is none.publicstaticfunc reachAddressBook() throws -> any AddressBook {guardlet book = addressBook else { throwLiveStoreUnreachable(store: "address book") }return book }/// Called by the app at launch, and by nothing else.publicstaticfunc install(addressBook: any AddressBook) { held.withLock { $0 = addressBook } }privatestaticlet roll = OSAllocatedUnfairLock<(any CameraRoll)?>(initialState: nil)/// The camera roll the app installed; nil in every other process.publicstaticvar cameraRoll: (any CameraRoll)? { roll.withLock { $0 } }publicstaticfunc install(cameraRoll: any CameraRoll) { roll.withLock { $0 = cameraRoll } }}/// The OS's answer for a capability whose API only an app links: the camera and the photo library. An app whose/// plist does not say why it would use one is built without its code (`COTTON_NO_CAMERA`, `COTTON_NO_PHOTOS`), so App/// Store processing finds no reference to ask a purpose string for (ITMS-90683, 22 Nov 2026), and here it is/// `unavailable`.publicprotocolAccessAsking: Sendable {func status() async -> CapabilityAccessfunc ask() async -> CapabilityAccess}extensionLiveStores {privatestaticlet asking = OSAllocatedUnfairLock<[DeviceCapability: any AccessAsking]>(initialState: [:])/// What the app installed for this capability; nil when it was built without it, and in every test process.publicstaticfunc access(for capability: DeviceCapability) -> (any AccessAsking)? { asking.withLock { $0[capability] } }publicstaticfunc install(access: any AccessAsking, for capability: DeviceCapability) { asking.withLock { $0[capability] = access } }}