Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.
Rust apple-notesapple-reminderscloudkitcrdtdesktop-appicloudicloud-calendaricloud-driveicloud-notesicloud-photosiphonelinuxlinux-desktoplocal-firstoffline-firstprivacyrusttauritauri-appwindows
Accounts never mix: strict ownership, owner kept through salvage, folders released on a switch
Yashwanth Kamireddi1502c2e2a8a1
diff --git a/SECURITY.md b/SECURITY.mdindex 48f00f1..5fababb 100644--- a/SECURITY.md+++ b/SECURITY.md@@ -88,10 +88,14 @@ on Windows.and Photos listings — and caches of pictures and files you opened. These are not encryptedby Skykeep; use full-disk encryption, as you would for the same data on a Mac.-Signing out asks whether to keep a copy on this computer. Removing it deletes the library,-its caches and Skykeep's file-manager thumbnails. Another Apple Account signing in never sees-the last one's data: each account's library is set aside whole and brought back only for-that account.+Signing out asks whether to keep a copy on this computer. Removing it deletes the library's+files themselves — `library.db`, its `-wal` and `-shm`, and any damaged copy Skykeep set aside+beside them (`library.corrupt-*`) — not only the rows in them, so nothing of the account is+left in the file's free space; then its caches and Skykeep's file-manager thumbnails. Another+Apple Account signing in never sees the last one's data: each account's library is set aside+whole and brought back only for that account, the iCloud Drive and Photos folders are let go+of before it is, and a library that holds records but cannot say whose is set aside too,+never handed to the account signing in.## What runs on this computerdiff --git a/crates/quince-core/src/lib.rs b/crates/quince-core/src/lib.rsindex bc8022d..abc910e 100644--- a/crates/quince-core/src/lib.rs+++ b/crates/quince-core/src/lib.rs@@ -85,9 +85,20 @@ impl Error {pub type Result<T> = std::result::Result<T, Error>;-/// The `app_state` keys that are this computer's, not an account's.+/// The `app_state` keys that are this computer's, not an account's. The photo cache's size is+/// chosen for this computer's disk, in Settings, as the others are.const COMPUTER_KEYS: &str = "key LIKE 'settings.%' OR key IN \- ('drive_folder_on', 'drive_folder_path', 'photos_folder_on', 'photos_folder_path')";+ ('drive_folder_on', 'drive_folder_path', 'photos_folder_on', 'photos_folder_path', \+ 'photos.cacheCap')";++/// Which account a library holds (the app's `ACCOUNT_KEY`): carried over with what waits to be+/// sent when a damaged library is made again, so those changes stay that account's alone.+const ACCOUNT_KEY: &str = "account";++/// `app_state` keys a library makes for itself the moment it opens, whoever it is for: the+/// id this installation signs note edits with (the app's `documents.writer`). Not a sign that+/// any account's records are here.+const MADE_ON_OPEN: &str = "key IN ('documents.writer')";/// Every table holding what an account brought: all but `app_state`, which is sorted key by key,/// and the search index's, which are not rows to delete one by one (`forget_account` empties it).@@ -253,7 +264,10 @@ impl Library {let Ok(old) = Connection::open_with_flags(from, OpenFlags::SQLITE_OPEN_READ_ONLY) else {return 0;};- let computer = format!("SELECT * FROM app_state WHERE {COMPUTER_KEYS}");+ // The account's name goes with its changes: without it, a library holding one+ // account's changes named no owner, and was given to whoever signed in next.+ let computer =+ format!("SELECT * FROM app_state WHERE {COMPUTER_KEYS} OR key = '{ACCOUNT_KEY}'");let mut moved = 0;for (table, select) in [("outbox", "SELECT * FROM outbox ORDER BY id".to_string()),@@ -573,7 +587,10 @@ impl Library {}}Ok(self.conn.query_row(- &format!("SELECT EXISTS (SELECT 1 FROM app_state WHERE NOT ({COMPUTER_KEYS}))"),+ &format!(+ "SELECT EXISTS (SELECT 1 FROM app_state \+ WHERE NOT ({COMPUTER_KEYS}) AND NOT ({MADE_ON_OPEN}))"+ ),[],|r| r.get(0),)?)@@ -646,16 +663,20 @@ mod tests {.unwrap();}let mut fresh = Library::in_memory().unwrap();- assert_eq!(fresh.salvage(&old), 2, "the change waiting and the setting");+ assert_eq!(+ fresh.salvage(&old),+ 3,+ "the change waiting, the setting and whose they are"+ );assert_eq!(fresh.outbox_count().unwrap(), 1);assert_eq!(fresh.state("settings.alerts").unwrap().as_deref(),Some("on"));assert_eq!(- fresh.state("account").unwrap(),- None,- "the account's own is not"+ fresh.state("account").unwrap().as_deref(),+ Some("someone"),+ "the change stays the account's that made it");}@@ -759,6 +780,13 @@ mod tests {);lib.forget_account().unwrap();assert!(!lib.holds_account().unwrap(), "nothing left to set aside");+ // The id a library makes for itself as it opens is no account's records.+ lib.set_state("documents.writer", "W").unwrap();+ lib.set_state("photos.cacheCap", "1073741824").unwrap();+ assert!(+ !lib.holds_account().unwrap(),+ "a fresh library is not taken for one"+ );assert!(lib.drive_children("root").unwrap().is_empty(),"the files gone"diff --git a/src-tauri/src/drive_watch.rs b/src-tauri/src/drive_watch.rsindex 9ff16db..6e1cec3 100644--- a/src-tauri/src/drive_watch.rs+++ b/src-tauri/src/drive_watch.rs@@ -191,6 +191,12 @@ async fn read_zones(|id| id == quince_core::drive::ROOT || library.drive_item(id).ok().flatten().is_some(),)};+ // What this account's session read goes only into this account's library: another+ // account signing in while the feed was read swapped the library under it.+ let account = crate::account_tag(dsid);+ let mine = |library: &quince_core::Library| {+ crate::owned_by(library, Some(&account)).map_err(Error::Refused)+ };let mut listed = Vec::new();for folder in folders {let pass = crate::drive_pass(&folder);@@ -198,11 +204,13 @@ async fn read_zones(match quince_icloud::drive::fetch_folder(http, drivews, params.to_vec(), &folder).await {Ok(items) => {let mut library = data.0.lock().await;+ mine(&library)?;quince_icloud::drive::store_folder(&mut library, &folder, &items)?;}// Gone since: forgotten here too, as when the window finds it gone.Err(Error::NotFound) => {let mut library = data.0.lock().await;+ mine(&library)?;library.forget_drive_folder(&folder)?;}Err(e) => return Err(e),@@ -210,7 +218,9 @@ async fn read_zones(listed.push(folder);}if let Ok(json) = serde_json::to_string(&positions) {- let _ = data.0.lock().await.set_state(POSITION, &json);+ let mut library = data.0.lock().await;+ mine(&library)?;+ let _ = library.set_state(POSITION, &json);}if !listed.is_empty() {quiet!("drive watch: {} folder(s) changed", listed.len());diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rsindex b2c8fac..d042af3 100644--- a/src-tauri/src/main.rs+++ b/src-tauri/src/main.rs@@ -1408,7 +1408,9 @@ pub fn account_tag(dsid: &str) -> String {/// Someone else's library here — a sign-out kept a copy, then another Apple ID signed in — is/// set aside whole under `accounts/`, never deleted and never mixed, and this account's own,/// if it was set aside before, comes back where it was: its records, its caches, what it had-/// still to send. A library from before accounts were told apart is simply claimed.+/// still to send. A library that names no owner but holds an account's records — whose they+/// are, nothing here can say — is set aside the same way, as unclaimed, rather than handed to+/// whoever signs in next; only an empty one is simply claimed.async fn claim_library(app: &tauri::AppHandle, client: &Client) -> Result<(), String> {let Some(dsid) = client.session().dsid.as_deref() else {return Ok(());@@ -1422,9 +1424,14 @@ async fn claim_library(app: &tauri::AppHandle, client: &Client) -> Result<(), St}let dir = state_dir(app);let home = dir.join(SET_ASIDE).join(&tag);- if known.is_some() || home.exists() {+ if must_set_aside(&library, known.as_deref(), home.exists())? {let now = jiff::Timestamp::now().as_second();let away = known.unwrap_or_else(|| format!("unclaimed-{now}"));+ // The folders the last account's session served go before its library does: left+ // mounted, they went on answering from the next account's library and session.+ tauri::async_runtime::spawn_blocking(|| mount::release_within(Duration::from_secs(3)))+ .await+ .map_err(|e| e.to_string())?;// The screens' readers let go of the file before it moves.data.0.forget_readers();switch_library(&mut library, &dir, &away, &home)?;@@ -1435,6 +1442,17 @@ async fn claim_library(app: &tauri::AppHandle, client: &Client) -> Result<(), St.map_err(|e| e.to_string())}+/// Whether the library here must be set aside before `account` takes it: it is another+/// account's, `account`'s own is waiting to come back, or it names no owner but holds records+/// all the same (a library whose owner was lost) — never given to an account it may not be.+fn must_set_aside(+ library: &Library,+ owner: Option<&str>,+ home_waits: bool,+) -> Result<bool, String> {+ Ok(owner.is_some() || home_waits || library.holds_account().map_err(|e| e.to_string())?)+}+/// One account's library and caches set aside under `away`, and the ones at `home` (if any)/// brought back in their place. The library is let go of while its files move and opened/// again after, whatever happened; this computer's settings stay with the computer.@@ -1590,17 +1608,19 @@ fn asked_as(params: &[(String, String)]) -> Option<String> {.map(|(_, dsid)| account_tag(dsid))}-/// Whether what was read with one account's session may be stored in this library: never in a-/// library another account owns. A pass after a write read with the session the write was+/// Whether what was read with one account's session may be stored in this library: only in+/// the library that account owns. A pass after a write read with the session the write was/// sent with; another Apple ID signing in meanwhile swapped the library under it, and that-/// pass stored the first account's notes, reminders and sync position in the second's.+/// pass stored the first account's notes, reminders and sync position in the second's. A+/// library that names no owner (signed out with nothing kept, or not yet claimed) is no+/// account's to fill, and a request that names no account is no account's to store.fn owned_by(library: &quince_core::Library, asked_for: Option<&str>) -> Result<(), String> {let owner = library.state(ACCOUNT_KEY).ok().flatten();match (owner.as_deref(), asked_for) {- (Some(owner), Some(asked)) if owner != asked => Err(+ (Some(owner), Some(asked)) if owner == asked => Ok(()),+ _ => Err("Signed in to another account while this was on its way, so nothing was stored.".into(),),- _ => Ok(()),}}@@ -1620,9 +1640,35 @@ mod account_write_tests {owned_by(&lib, b.as_deref()).is_err(),"the other account's read is refused");- // A library from before accounts were told apart, and a request with no account, pass.- assert!(owned_by(&Library::in_memory().unwrap(), b.as_deref()).is_ok());- assert!(owned_by(&lib, None).is_ok());+ // A library that names no owner is no account's to fill, and a request that names no+ // account stores nothing.+ assert!(owned_by(&Library::in_memory().unwrap(), b.as_deref()).is_err());+ assert!(owned_by(&lib, None).is_err());+ }++ /// A library is handed to the account signing in only when it is that account's or holds+ /// nothing. One that names no owner but holds records — its owner lost — is set aside as+ /// unclaimed, never given to whoever signs in next; an empty one (a Remove Copy, a first+ /// run), only the id it made for itself as it opened, is simply claimed.+ #[test]+ fn a_library_with_no_owner_but_records_is_set_aside() {+ let mut lib = Library::in_memory().unwrap();+ lib.set_state("documents.writer", "W").unwrap();+ lib.set_state("settings.alerts.events", "0").unwrap();+ assert!(+ !must_set_aside(&lib, None, false).unwrap(),+ "empty: claimed"+ );+ assert!(+ must_set_aside(&lib, None, true).unwrap(),+ "the account's own waits to come back"+ );+ assert!(must_set_aside(&lib, Some("other"), false).unwrap());+ lib.outbox_push("reminders", "R1", "done", "{}").unwrap();+ assert!(+ must_set_aside(&lib, None, false).unwrap(),+ "a change waiting, whose nobody can say"+ );}}diff --git a/src-tauri/src/mount.rs b/src-tauri/src/mount.rsindex 8ec4ab1..200dbe9 100644--- a/src-tauri/src/mount.rs+++ b/src-tauri/src/mount.rs@@ -58,14 +58,17 @@ impl Remote for AppRemote {let (app, folder) = (self.app.clone(), folder.to_string());Box::pin(async move {let (http, root, params) = context(&app, "drivews").await?;+ let asked_for = crate::asked_as(¶ms);let pass = crate::drive_pass(&folder);let _one = pass.lock().await;let items = quince_icloud::drive::fetch_folder(&http, &root, params, &folder).await.map_err(|e| e.to_string())?;- // Kept, so the window's Drive knows it too and the next look needs no network.+ // Kept, so the window's Drive knows it too and the next look needs no network —+ // only in the library of the account whose session read it.let data = app.state::<Data>();let mut library = data.0.lock().await;+ crate::owned_by(&library, asked_for.as_deref())?;quince_icloud::drive::store_folder(&mut library, &folder, &items).map_err(|e| e.to_string())?;Ok(items)diff --git a/src-tauri/src/outbox.rs b/src-tauri/src/outbox.rsindex 1d349e1..54584f6 100644--- a/src-tauri/src/outbox.rs+++ b/src-tauri/src/outbox.rs@@ -1239,14 +1239,49 @@ struct Report {refused: Vec<(String, String)>,}-/// Send what is waiting for `service`, oldest first, with `send`. Stops at the first change-/// Apple can't be reached for, leaving it and everything after it queued, in order.+/// [`drain_as`] without asking whose the library is: the tests' pretend Apple.+#[cfg(test)]async fn drain<F, Fut>(library: &crate::library_lock::LibraryLock,service: &str,pass: &Mutex<()>,send: F,) -> Report+where+ F: Fn(Pending) -> Fut,+ Fut: std::future::Future<Output = Result<(), Error>>,+{+ drain_checked(library, service, pass, None, send).await+}++/// Send `service`'s queue with the session of `account` (as the library names accounts), for+/// as long as the library is still that account's: asked as each change is taken, under the+/// same lock, so a sign-in of another account while the queue was going — which swaps the+/// library under it — never has its changes sent with the session captured before.+async fn drain_as<F, Fut>(+ library: &crate::library_lock::LibraryLock,+ service: &str,+ pass: &Mutex<()>,+ account: &str,+ send: F,+) -> Report+where+ F: Fn(Pending) -> Fut,+ Fut: std::future::Future<Output = Result<(), Error>>,+{+ drain_checked(library, service, pass, Some(account), send).await+}++/// Send what is waiting for `service`, oldest first, with `send`. Stops at the first change+/// Apple can't be reached for, leaving it and everything after it queued, in order — and,+/// given an `account`, at the first change taken once the library is no longer its.+async fn drain_checked<F, Fut>(+ library: &crate::library_lock::LibraryLock,+ service: &str,+ pass: &Mutex<()>,+ account: Option<&str>,+ send: F,+) -> ReportwhereF: Fn(Pending) -> Fut,Fut: std::future::Future<Output = Result<(), Error>>,@@ -1261,7 +1296,18 @@ where// the write and stored just after would put the old state back with nothing waiting// to lay over it.let _pass = pass.lock().await;- let next = library.lock().await.outbox_take(service);+ let next = {+ let mut l = library.lock().await;+ let theirs = account+ .is_none_or(|a| l.state(crate::ACCOUNT_KEY).ok().flatten().as_deref() == Some(a));+ if theirs {+ l.outbox_take(service)+ } else {+ // Another account's library now: what is left waits for its own session.+ report.outcome = Outcome::Later;+ return report;+ }+ };let p = match next {Ok(Some(p)) => p,Ok(None) => break,@@ -1290,6 +1336,22 @@ wherereport}+/// A queued change's record missing from the library: gone — deleted here, or on another+/// device, and a pass has said so — once the library has had a pass of `service`. Before its+/// first (a library made again after damage, its records not yet brought back) the record is+/// not known yet, not gone: the change waits for that pass, rather than being dropped as done+/// or refused as deleted elsewhere.+async fn known_gone(+ library: &crate::library_lock::LibraryLock,+ service: &str,+) -> Result<(), Error> {+ if library.lock().await.last_synced(service)?.is_some() {+ Ok(())+ } else {+ Err(Error::Busy)+ }+}+fn unreadable(e: &serde_json::Error) -> Error {Error::Refused(format!("A queued change could not be read: {e}"))}@@ -1338,7 +1400,10 @@ async fn drain_reminders(app: &AppHandle) -> Outcome {// Not signed in, or the session is being renewed: nothing can go yet.return Outcome::Later;};- let report = drain(&data.0, REMINDERS, &crate::REMINDERS_PASS, |p| {+ let Some(account) = crate::asked_as(¶ms) else {+ return Outcome::Later;+ };+ let report = drain_as(&data.0, REMINDERS, &crate::REMINDERS_PASS, &account, |p| {send_reminder(&data.0, &http, &root, params.clone(), p)}).await;@@ -1373,7 +1438,7 @@ async fn send_reminder(let d: Done = serde_json::from_str(&p.payload).map_err(|e| unreadable(&e))?;// Gone from the library (deleted here or elsewhere): nothing left to tick.let Some(reminder) = stored else {- return Ok(());+ return known_gone(library, REMINDERS).await;};// A change made on another device after this one was queued wins; the pass after// sending reads Apple's version back.@@ -1418,7 +1483,7 @@ async fn send_reminder(let a: Advance = serde_json::from_str(&p.payload).map_err(|e| unreadable(&e))?;// Gone from the library (deleted here or elsewhere): nothing left to tick.let Some(reminder) = stored else {- return Ok(());+ return known_gone(library, REMINDERS).await;};// Moved on at Apple already — by an earlier send of this tick, or on another// device since — it is not moved on again.@@ -1427,6 +1492,7 @@ async fn send_reminder("edit" => {let e: Edit = serde_json::from_str(&p.payload).map_err(|e| unreadable(&e))?;let Some(mut reminder) = stored else {+ known_gone(library, REMINDERS).await?;return Err(Error::Refused("This reminder was deleted on another device, so the change wasn’t saved.".into(),@@ -1504,7 +1570,10 @@ async fn drain_notes(app: &AppHandle) -> Outcome {let Ok((http, root, params)) = session else {return Outcome::Later;};- let report = drain(&data.0, NOTES, &crate::NOTES_PASS, |p| {+ let Some(account) = crate::asked_as(¶ms) else {+ return Outcome::Later;+ };+ let report = drain_as(&data.0, NOTES, &crate::NOTES_PASS, &account, |p| {send_note(&data.0, &http, &root, params.clone(), p)}).await;@@ -1544,6 +1613,7 @@ async fn send_note("move" => {let m: NoteMove = serde_json::from_str(&p.payload).map_err(|e| unreadable(&e))?;let Some(note) = library.lock().await.note(&p.record)? else {+ known_gone(library, NOTES).await?;return Err(Error::Refused("This note was deleted on another device, so it wasn’t moved.".into(),));@@ -1574,7 +1644,7 @@ async fn send_note(let x: NotePin = serde_json::from_str(&p.payload).map_err(|e| unreadable(&e))?;// Gone since: nothing left to pin.let Some(note) = library.lock().await.note(&p.record)? else {- return Ok(());+ return known_gone(library, NOTES).await;};n::pin_cloudkit(http, root, params, ¬e, x.pinned).await}@@ -1593,6 +1663,7 @@ async fn send_note_save() -> Result<(), Error> {let s: NoteSave = serde_json::from_str(&p.payload).map_err(|e| unreadable(&e))?;let Some(note) = library.lock().await.note(&p.record)? else {+ known_gone(library, NOTES).await?;return Err(Error::Refused("This note was deleted on another device, so the edit wasn’t saved.".into(),));@@ -1651,7 +1722,10 @@ async fn drain_contacts(app: &AppHandle) -> Outcome {});return Outcome::Clear;}- let report = drain(&data.0, CONTACTS, &crate::CONTACTS_PASS, |p| {+ let Some(account) = crate::asked_as(¶ms) else {+ return Outcome::Later;+ };+ let report = drain_as(&data.0, CONTACTS, &crate::CONTACTS_PASS, &account, |p| {send_contact(&data.0, &http, &root, params.clone(), p)}).await;@@ -1756,7 +1830,10 @@ async fn drain_calendar(app: &AppHandle) -> Outcome {let Ok((http, root, params)) = session else {return Outcome::Later;};- let report = drain(&data.0, CALENDAR, &crate::CALENDAR_PASS, |p| {+ let Some(account) = crate::asked_as(¶ms) else {+ return Outcome::Later;+ };+ let report = drain_as(&data.0, CALENDAR, &crate::CALENDAR_PASS, &account, |p| {send_event(&data.0, &http, &root, params.clone(), p)}).await;@@ -3409,6 +3486,108 @@ mod tests {assert_eq!(back, e);}+ /// A tick, a pin or a move for a record the library does not hold is dropped (ticks, pins)+ /// or refused (moves) only once a pass has said what the library holds: in a library made+ /// again after damage, before its first pass, the record is not known yet, and the change+ /// waits — never quietly "sent" and lost.+ #[tokio::test]+ async fn a_change_for_a_record_not_known_yet_waits_for_a_pass() {+ let lib = crate::library_lock::LibraryLock::new(Library::in_memory().unwrap(), None);+ let http = reqwest::Client::new();+ // Nothing listens here: any request at all fails as a network error, not Busy.+ let nowhere = "http://127.0.0.1:9";+ let pending = |service: &str, kind: &str, payload: String| Pending {+ id: 1,+ service: service.into(),+ record: "GONE".into(),+ kind: kind.into(),+ payload,+ tries: 0,+ };+ let tick = || {+ let d = Done {+ done: true,+ at: 1,+ base: Default::default(),+ };+ pending(REMINDERS, "done", serde_json::to_string(&d).unwrap())+ };+ let pin = || pending(NOTES, "pin", r#"{"pinned":true}"#.into());+ let moved = || pending(NOTES, "move", r#"{"folder_guid":null}"#.into());++ let waits = |r: Result<(), Error>| matches!(r, Err(e) if transient(&e, 99));+ assert!(waits(+ send_reminder(&lib, &http, nowhere, Vec::new(), tick()).await+ ));+ assert!(waits(+ send_note(&lib, &http, nowhere, Vec::new(), pin()).await+ ));+ assert!(waits(+ send_note(&lib, &http, nowhere, Vec::new(), moved()).await+ ));++ // A pass in: the record is gone, so a tick or a pin has nothing left to do, and a move+ // says why it did not happen.+ {+ let l = lib.lock().await;+ l.mark_synced(REMINDERS, Some("t")).unwrap();+ l.mark_synced(NOTES, Some("t")).unwrap();+ }+ assert!(send_reminder(&lib, &http, nowhere, Vec::new(), tick())+ .await+ .is_ok());+ assert!(send_note(&lib, &http, nowhere, Vec::new(), pin())+ .await+ .is_ok());+ assert!(matches!(+ send_note(&lib, &http, nowhere, Vec::new(), moved()).await,+ Err(Error::Refused(_))+ ));+ }++ /// The sender sends a library's changes only while the library is the account's whose+ /// session it holds: asked as each change is taken. Another account's library — swapped in+ /// by a sign-in while the queue was going — keeps every change, unsent.+ #[tokio::test]+ async fn changes_go_only_with_their_own_accounts_session() {+ let mut l = library();+ queue(&mut l, "R1", true);+ queue(&mut l, "R2", true);+ l.set_state(crate::ACCOUNT_KEY, "b").unwrap();+ let lib = crate::library_lock::LibraryLock::new(l, None);+ let sent = std::sync::Arc::new(std::sync::atomic::AtomicUsize::new(0));+ let pass = Mutex::new(());+ let count = std::sync::Arc::clone(&sent);+ let report = drain_as(&lib, REMINDERS, &pass, "a", move |_p| {+ let count = std::sync::Arc::clone(&count);+ async move {+ count.fetch_add(1, std::sync::atomic::Ordering::SeqCst);+ Ok(())+ }+ })+ .await;+ assert!(matches!(report.outcome, Outcome::Later));+ assert_eq!(sent.load(std::sync::atomic::Ordering::SeqCst), 0);+ assert_eq!(lib.lock().await.outbox_pending(REMINDERS).unwrap().len(), 2);++ // Swapped part way: the first goes with its own account, the rest wait.+ lib.lock().await.set_state(crate::ACCOUNT_KEY, "a").unwrap();+ let lib = std::sync::Arc::new(lib);+ let (inner, count) = (std::sync::Arc::clone(&lib), std::sync::Arc::clone(&sent));+ let report = drain_as(&lib, REMINDERS, &pass, "a", move |_p| {+ let (lib, count) = (std::sync::Arc::clone(&inner), std::sync::Arc::clone(&count));+ async move {+ count.fetch_add(1, std::sync::atomic::Ordering::SeqCst);+ lib.lock().await.set_state(crate::ACCOUNT_KEY, "b").unwrap();+ Ok(())+ }+ })+ .await;+ assert!(matches!(report.outcome, Outcome::Later));+ assert_eq!(sent.load(std::sync::atomic::Ordering::SeqCst), 1);+ assert_eq!(lib.lock().await.outbox_pending(REMINDERS).unwrap().len(), 1);+ }+/// A pretend Apple that holds one event: a save sent with its current tag is taken, one sent/// with any other is answered "changed since" (412), as Apple's calendar does.mod apple_calendar {