usesuper::*;usecrate::sync::SchemaStanding;const MINUTE: i64 = 60 * 1000;/// RULE: The sync page counts incoming receipts the server still owes, independently of unsent local writes and the cap's silence; failures never turn an unknown or waiting backlog into zero.#[test]fn copy_facts_keep_incoming_receipts_separate_from_outgoing_changes() {letmut line = HomeLine::default(); assert_eq!(line.facts().remaining, None); line.answered(Answered { unsent: 91, ..behind(20, 3, 7) }, MINUTE); assert_eq!(line.facts().remaining, Some(7)); assert_eq!(line.facts().answered_at, Some(MINUTE)); line.unanswered(None, 2 * MINUTE); assert_eq!(line.facts().remaining, Some(7)); assert_eq!(line.facts().silent_since, Some(2 * MINUTE)); line.answered(level(), 3 * MINUTE); assert_eq!(line.facts().remaining, Some(0)); assert_eq!(line.facts().synced_at, Some(3 * MINUTE)); line.answered(behind(0, 1, 2), 4 * MINUTE); assert_eq!(line.facts().synced_at, Some(3 * MINUTE));let dir = tempfile::tempdir().unwrap();let path = dir.path().join("lines.json"); store(&path, &BTreeMap::from([("synthetic".into(), line)])); assert_eq!(stored(&path)["synthetic"].facts().synced_at, Some(3 * MINUTE));}/// RULE: "Not reachable since" is the FIRST unanswered pass since the last answer — later failures and a relaunch never move it, and an answer clears it (walker pass 4 offline, row 2: the stamp moved with every attempt).#[test]fn silence_dates_from_the_first_failure_across_retries_and_a_relaunch() {letmut line = HomeLine::default(); line.answered(level(), MINUTE); line.unanswered(None, 2 * MINUTE);let was = line.clone(); line.unanswered(None, 3 * MINUTE); assert_eq!(line.facts().silent_since, Some(2 * MINUTE)); assert!(!was.same_place(&HomeLine { silent_since: None, ..was.clone() }), "the silence beginning is written");let dir = tempfile::tempdir().unwrap();let path = dir.path().join("lines.json"); store(&path, &BTreeMap::from([("synthetic".into(), line)]));letmut relaunched = stored(&path).remove("synthetic").unwrap(); relaunched.unanswered(None, 9 * MINUTE); assert_eq!(relaunched.facts().silent_since, Some(2 * MINUTE)); relaunched.answered(level(), 10 * MINUTE); assert_eq!(relaunched.facts().silent_since, None);}/// A pass that answered while still behind: `received` rows in, `sent` out,/// the Mac counting `remaining` left.fn behind(sent: u64, received: u64, remaining: u64) -> Answered {Answered { sent, received, remaining: Some(remaining), behind: true, ..Answered::default() }}fn level() -> Answered {Answered { remaining: Some(0), ..Answered::default() }}/// Is `words` a line sync may put under a cap — empty (the people line), or/// one of its four?fn a_line_sync_may_say(words: &str) -> bool {if words.is_empty() || words == OFFLINE || words == UPDATE_APP {returntrue; }ifletSome(percent) = words.strip_prefix("syncing \u{00B7} ").and_then(|rest| rest.strip_suffix('%')) {return !percent.is_empty() && percent.bytes().all(|byte| byte.is_ascii_digit()) && percent.parse::<u8>().is_ok_and(|percent| percent < 100); } words .strip_prefix("copying \u{00B7} ") .and_then(|rest| rest.strip_suffix(" to go")) .is_some_and(|left| left.ends_with(" MB") || left.ends_with(" GB"))}/// RULE: Under a cap, sync says exactly one of "syncing · N%", "copying · N MB to go", "offline", "update app" — or nothing, and the people line stands; the words "catching up", "up to date" and any count of changes never appear there (sync programme, lane A, 12 Oct 2026).#[test]fn the_line_under_a_cap_is_one_of_four_or_the_people_line() {letmut line = HomeLine::default();letmut now = 0;letmut said = vec![line.words(now)];letmut say = |line: &HomeLine, now: i64| said.push(line.words(now));// A small catch-up, a big one at every count a Mac can say, blips, a// long silence, a refusal of this build, a copy, and level again. line.answered(behind(3, 40, 600), now); say(&line, now); line.answered(level(), now); say(&line, now);for remaining in [10_000, 10_000, 9_999, 1_234, 1] { now += MINUTE; line.answered(Answered { owed_at_start: Some(250_000), ..behind(14, 5_000, remaining) }, now, ); say(&line, now); line.unanswered(None, now); say(&line, now); } say(&line, now + OFFLINE_AFTER_MS); line.unanswered(Some(SchemaStanding::PhoneBehind), now); say(&line, now); line.answered(behind(0, 0, 1), now); line.copying(Some(400_000_000)); say(&line, now); line.copying(Some(2_300_000_000)); say(&line, now); line.copying(None); line.answered(level(), now); say(&line, now);for words in &said { assert!(a_line_sync_may_say(words), "not a line sync may say: {words:?} in {said:?}");for retired in ["catching up", "up to date", "change", "so far", "received", "sending"] { assert!(!words.contains(retired), "{retired:?} is said under a cap: {words:?}"); } }for each in ["", OFFLINE, UPDATE_APP, "copying \u{00B7} 400 MB to go", "copying \u{00B7} 2.3 GB to go"] { assert!(said.iter().any(|words| words == each), "{each:?} was never said: {said:?}"); } assert!(said.iter().any(|words| words.starts_with(SYNCING)), "{said:?}");}/// RULE: A catch-up that began owing 2,000 changes or fewer is never said in words — the people line stands and only the cap turns — because it is over before a percent could be read; one that began owing more is said until it is level, however few are left.#[test]fn fewer_than_two_thousand_changes_move_without_a_word() {letmut line = HomeLine::default(); line.answered(behind(0, 500, 1_500), 0); assert_eq!(line.standing(0).state, State::Moving, "2,000 owed: the cap turns"); assert_eq!(line.words(0), ""); assert_eq!(line.standing(0).page, "", "and the page's slot stays empty"); line.answered(level(), 0); assert_eq!(line.standing(0).state, State::Current);letmut line = HomeLine::default(); line.answered(behind(0, 500, 1_501), 0); assert_eq!(line.words(0), "syncing \u{00B7} 24%", "2,001 owed is said");// Three changes from the end it is still said: a line that fell silent// near the end would read as done. line.answered(behind(0, 1_498, 3), 0); assert_eq!(line.words(0), "syncing \u{00B7} 99%"); line.answered(level(), 0); assert_eq!(line.words(0), "");}/// RULE: The percent is (sent + received) over (outbox + owed), both directions, in changes (bytes never count), with the whole measured ONCE at the start of the pass that found the device behind — so it only moves forward within a catch-up, whatever arrives at the Mac meanwhile, and it resets when the device is level.#[test]fn the_percent_is_sent_plus_received_over_outbox_plus_owed_measured_once() {letmut line = HomeLine::default();// The pass that found it behind: 1,000 of an outbox of 4,000 went, 3,000// of the 36,000 the Mac counted at the start came.let first = Answered { sent: 1_000, received: 3_000, unsent: 3_000, owed_at_start: Some(36_000), remaining: Some(10_000), behind: true, }; line.answered(first, 0); assert_eq!(line.words(0), "syncing \u{00B7} 10%", "4,000 of 4,000 + 36,000"); assert_eq!(line.standing(0).to_go, Some(36_000));// The rest of the outbox and a page: 4,000 + 12,000 of 40,000. line.answered(Answered { sent: 3_000, received: 9_000, unsent: 0, ..first }, 0); assert_eq!(line.words(0), "syncing \u{00B7} 40%");// The Mac counts a different start later (it must not, and a second// count changes nothing): the whole was measured once. line.answered(Answered { sent: 0, received: 4_000, unsent: 0, owed_at_start: Some(900_000), ..first },0, ); assert_eq!(line.words(0), "syncing \u{00B7} 50%");// A pass that moved nothing, and one that did not answer, keep the place. line.answered(Answered { sent: 0, received: 0, unsent: 0, ..first }, 0); line.unanswered(None, 0); assert_eq!(line.words(0), "syncing \u{00B7} 50%");// More arrived at the Mac than the whole: never 100 while behind, never// nothing to go. line.answered(Answered { sent: 0, received: 30_000, unsent: 0, ..first }, 0); assert_eq!(line.words(0), "syncing \u{00B7} 99%"); assert_eq!(line.standing(0).to_go, Some(10_000), "what the Mac says still waits");// Level. line.answered(level(), 0); assert_eq!(line.words(0), "");// The next catch-up is measured against its own whole. line.answered(Answered { received: 1_000, owed_at_start: Some(4_000), ..behind(0, 0, 3_000) }, 0); assert_eq!(line.words(0), "syncing \u{00B7} 25%");}/// RULE: Every term of the percent is a count of CHANGES (receipts), and what the serving Mac says is left — once that count is under its cap, so exact — is a floor under what has moved: the whole less what still waits on either side. So a catch-up whose pages left changes out (a phone's keep rules, a Mac a build behind that does not say what it passed) is never stuck short of its end.#[test]fn what_the_mac_says_is_left_is_a_floor_under_what_has_moved() {letmut line = HomeLine::default();let first = Answered { sent: 0, received: 20_000, unsent: 0, owed_at_start: Some(100_000), remaining: Some(COUNTED_UP_TO), behind: true, }; line.answered(first, 0); assert_eq!(line.words(0), "syncing \u{00B7} 20%");// Pages that this device counted little of — most of what they passed// was left out — while the Mac's count of what waits is still capped:// nothing is guessed from a capped count. line.answered(Answered { received: 1_000, ..first }, 0); assert_eq!(line.words(0), "syncing \u{00B7} 21%");// The Mac's count comes under its cap: 4,000 wait there and 1,000 here,// so 95,000 of the 100,000 have moved, whatever this device counted. line.answered(Answered { received: 500, unsent: 1_000, remaining: Some(4_000), ..first }, 0); assert_eq!(line.words(0), "syncing \u{00B7} 95%"); assert_eq!(line.standing(0).to_go, Some(5_000));// More arrives at the Mac meanwhile: the floor falls, the percent does not. line.answered(Answered { received: 0, remaining: Some(9_000), ..first }, 0); assert_eq!(line.words(0), "syncing \u{00B7} 95%"); line.answered(level(), 0); assert_eq!(line.words(0), "");}/// RULE: Until the serving Mac has counted what a catch-up owed at its start, the percent stays where it is rather than being guessed from a capped count — and a Mac that never counts the start still gets a whole, from the first count small enough to be exact.#[test]fn a_whole_not_yet_counted_is_never_guessed_from_a_capped_count() {letmut line = HomeLine::default();// "At least 10,000" is not a whole. line.answered(behind(0, 2_000, COUNTED_UP_TO), 0); assert_eq!(line.words(0), "syncing \u{00B7} 0%"); assert_eq!(line.standing(0).to_go, None); assert_eq!(line.standing(0).page, "Syncing \u{00B7} 0%");// The Mac's count of the start arrives with the next pass, and what has// already moved counts. line.answered(Answered { owed_at_start: Some(40_000), ..behind(0, 2_000, COUNTED_UP_TO) },0, ); assert_eq!(line.words(0), "syncing \u{00B7} 10%");// A Mac that never counts the start: 12,000 came before its count fell// under the cap at 4,000 — a whole of 16,000.letmut line = HomeLine::default(); line.answered(behind(0, 6_000, COUNTED_UP_TO), 0); line.answered(behind(0, 6_000, 4_000), 0); assert_eq!(line.words(0), "syncing \u{00B7} 75%"); assert_eq!(line.standing(0).to_go, Some(4_000));// And one that says nothing at all moves without a word.letmut line = HomeLine::default(); line.answered(Answered { received: 9_000, behind: true, ..Answered::default() }, 0); assert_eq!(line.standing(0).state, State::Moving); line.answered(Answered::default(), 0); assert_eq!(line.standing(0).state, State::Current);}/// RULE: "offline" is said only when no Mac has answered for fifteen minutes — a missed pass is a blip and says nothing — and the first answer takes it back; "update app" is said at once, because no retry changes it.#[test]fn offline_is_fifteen_minutes_without_an_answer_and_update_app_does_not_wait() {letmut line = HomeLine::default(); line.answered(level(), 0); line.unanswered(None, MINUTE); line.unanswered(None, 2 * MINUTE); assert_eq!(line.words(OFFLINE_AFTER_MS - 1), "", "fourteen minutes of misses say nothing");// Measured from the last ANSWER, not from the first miss.let offline = line.standing(OFFLINE_AFTER_MS); assert_eq!(offline.state, State::Offline); assert_eq!(offline.words, OFFLINE); assert_eq!(offline.since, Some(0), "the page says since when"); line.answered(level(), 16 * MINUTE); assert_eq!(line.words(16 * MINUTE), "");// A device no Mac has ever answered counts from its first miss.letmut line = HomeLine::default(); line.unanswered(None, 100 * MINUTE); assert_eq!(line.words(114 * MINUTE), ""); assert_eq!(line.standing(115 * MINUTE).state, State::Offline); assert_eq!(line.standing(115 * MINUTE).since, None);// The Mac refuses this build: said at once, and it never decays into// "offline".letmut line = HomeLine::default(); line.unanswered(Some(SchemaStanding::PhoneBehind), 0); assert_eq!(line.words(0), UPDATE_APP); line.unanswered(Some(SchemaStanding::PhoneBehind), 60 * MINUTE); assert_eq!(line.words(60 * MINUTE), UPDATE_APP); line.answered(level(), 61 * MINUTE); assert_eq!(line.words(61 * MINUTE), "");}/// RULE: A device AHEAD of its serving Mac (the Mac's file on an older schema) says "update your Mac" at once, never decays into "offline", and goes back to the people line at the first pass that answers — the Mac was updated and what was held went with that pass (architect, 12 Oct 2026).#[test]fn a_mac_behind_this_build_says_update_your_mac_until_it_answers() {letmut line = HomeLine::default(); line.answered(level(), 0); line.unanswered(Some(SchemaStanding::ServerBehind), MINUTE);let behind = line.standing(MINUTE); assert_eq!(behind.state, State::MacBehind); assert_eq!(behind.words, UPDATE_MAC); assert_eq!(behind.page, "", "the page names the Mac, which only the app knows"); line.unanswered(Some(SchemaStanding::ServerBehind), 60 * MINUTE); assert_eq!(line.standing(60 * MINUTE).state, State::MacBehind, "never offline"); line.answered(level(), 61 * MINUTE); assert_eq!(line.standing(61 * MINUTE).state, State::Current);}/// RULE: A file copy is said in what is left of it — "copying · 400 MB to go", counting down — and bytes never enter the percent: when the copy is over the catch-up is where its rows left it.#[test]fn a_copy_is_said_in_megabytes_to_go_and_never_moves_the_percent() {letmut line = HomeLine::default(); line.answered(Answered { owed_at_start: Some(40_000), ..behind(0, 4_000, COUNTED_UP_TO) }, 0); assert_eq!(line.words(0), "syncing \u{00B7} 10%"); line.copying(Some(400_000_000));let copying = line.standing(0); assert_eq!(copying.state, State::Copying); assert_eq!(copying.words, "copying \u{00B7} 400 MB to go"); assert_eq!(copying.page, "Copying your database \u{00B7} 400 MB to go"); assert_eq!(copying.bytes_to_go, Some(400_000_000)); assert_eq!(copying.percent, Some(0), "the page's bar is the copy's own share, not the rows'"); line.copying(Some(100_000_000)); assert_eq!(line.words(0), "copying \u{00B7} 100 MB to go"); assert_eq!(line.standing(0).percent, Some(75)); line.copying(Some(1)); assert_eq!(line.words(0), "copying \u{00B7} 1 MB to go", "never 0 MB while a byte is left"); assert_eq!(line.standing(0).percent, Some(99)); line.copying(None); line.copying(Some(1_200_000_000)); assert_eq!(line.words(0), "copying \u{00B7} 1.2 GB to go"); line.copying(None); assert_eq!(line.words(0), "syncing \u{00B7} 10%");}/// RULE: The database page's top says the catch-up as a sentence with what is left — "Syncing · 62% · 41,000 changes to go" — in the same words and from the same numbers as the cap's line.#[test]fn the_page_says_the_same_catch_up_with_what_is_left() {letmut line = HomeLine::default(); line.answered(Answered { owed_at_start: Some(108_000), ..behind(0, 67_000, COUNTED_UP_TO) },0, );let standing = line.standing(0); assert_eq!(standing.words, "syncing \u{00B7} 62%"); assert_eq!(standing.page, "Syncing \u{00B7} 62% \u{00B7} 41,000 changes to go"); assert_eq!((standing.percent, standing.to_go), (Some(62), Some(41_000))); line.answered(behind(0, 40_999, 1), 0); assert_eq!(line.standing(0).page, "Syncing \u{00B7} 99% \u{00B7} 1 change to go"); line.unanswered(Some(SchemaStanding::PhoneBehind), 0); assert_eq!(line.standing(0).page, "Update the app to sync again");}/// RULE: What is coming is said by TOOL, in rows that have come of the rows the serving Mac counted were owed at the start — "Email · 41,000 of 58,900" — most still to come first; a tool with nothing left, and every table no tool's card stands for, collapse into one line, "Everything else · up to date"; and with no catch-up there is one line, "Everything · up to date".#[test]fn what_is_coming_is_said_by_tool_and_the_rest_in_one_line() {let tables = |pairs: &[(&str, u64)]| -> BTreeMap<String, u64> { pairs.iter().map(|(table, rows)| (table.to_string(), *rows)).collect() };let rows = |pairs: &[(&str, usize)]| -> BTreeMap<String, usize> { pairs.iter().map(|(table, rows)| (table.to_string(), *rows)).collect() };letmut line = HomeLine::default(); assert_eq!(line.standing(0).coming, ["Everything \u{00B7} up to date"]);// The pass that found it behind, before the Mac has counted anything. line.answered(behind(0, 3_000, COUNTED_UP_TO), 0); line.came(&rows(&[("cotton_emails", 2_000), ("cotton_todos", 1_000)]), None); assert_eq!(line.standing(0).coming, ["Everything \u{00B7} counting"]);// The Mac's count: 58,900 of mail in three tables, 1,200 todos, 400// photos, and 5,000 rows of a table no card stands for.let owed = tables(&[ ("cotton_emails", 30_000), ("cotton_email_threads", 20_000), ("cotton_email_participants", 8_900), ("cotton_todos", 1_200), ("cotton_photos", 400), ("cotton_zz_plumbing", 5_000), ]); line.answered(Answered { owed_at_start: Some(65_500), ..behind(0, 39_400, COUNTED_UP_TO) }, 0); line.came( &rows(&[ ("cotton_emails", 28_000), ("cotton_email_threads", 11_000), ("cotton_todos", 200), ("cotton_photos", 200), ]),Some(&owed), );// Mail's three tables are one tool; the todos are all here, so they are// in the rest with the table nobody names. assert_eq!( line.standing(0).coming, ["Email \u{00B7} 41,000 of 58,900","Photos \u{00B7} 200 of 400","Everything else \u{00B7} 1,200 of 6,200", ] );// A second count changes nothing (measured once), rows past what was// owed never say more than the whole, and with every counted row here// while the Mac still says more waits, it is finishing — not up to date. line.answered(behind(0, 30_000, 2_000), 0); line.came( &rows(&[ ("cotton_emails", 9_000), ("cotton_email_threads", 9_000), ("cotton_email_participants", 8_900), ("cotton_photos", 900), ("cotton_zz_plumbing", 5_000), ]),Some(&tables(&[("cotton_emails", 1)])), ); assert_eq!(line.standing(0).coming, ["Everything \u{00B7} finishing"]);// Level: nothing is coming, and the next catch-up starts from nothing. line.answered(level(), 0); assert_eq!(line.standing(0).coming, ["Everything \u{00B7} up to date"]); line.answered(behind(0, 10, 5_000), 0); line.came(&rows(&[("cotton_todos", 10)]), None); assert_eq!(line.standing(0).coming, ["Everything \u{00B7} 10 of 5,010"]);}/// RULE: A catch-up's place survives a relaunch — the catch-ups in flight and when a Mac last answered are kept in this device's own file — because a phone catching up over hours is relaunched many times, and a line that started again from 0% each time would move backwards.#[test]fn a_catch_up_keeps_its_place_across_a_relaunch() {let dir = tempfile::tempdir().expect("a temp dir");let path = dir.path().join("client").join("home-lines.json"); assert!(stored(&path).is_empty(), "no file is nothing in flight");letmut lines: BTreeMap<String, HomeLine> = BTreeMap::new(); lines .entry("behind".to_string()) .or_default() .answered(Answered { owed_at_start: Some(8_000), ..behind(0, 6_000, 2_000) }, 7 * MINUTE); lines.entry("level".to_string()).or_default().answered(level(), 7 * MINUTE); lines.entry("silent".to_string()).or_default().unanswered(None, 7 * MINUTE); store(&path, &lines);// The next run of the app.letmut lines = stored(&path);// A database no Mac has answered keeps only when its silence began, so// "not reachable since" is still the first failure after the relaunch. assert_eq!(lines.len(), 3, "{lines:?}"); assert_eq!(lines["silent"].facts().silent_since, Some(7 * MINUTE)); assert_eq!(lines["silent"].facts().answered_at, None);let line = lines.get_mut("behind").expect("the catch-up"); assert_eq!(line.words(8 * MINUTE), "syncing \u{00B7} 75%");// Its first pass brings 1,000 more: measured against the SAME whole. line.answered(behind(0, 1_000, 1_000), 8 * MINUTE); assert_eq!(line.words(8 * MINUTE), "syncing \u{00B7} 87%"); line.answered(level(), 8 * MINUTE);// A level database kept when its Mac last answered: offline is said the// moment a relaunched app's first pass fails long after it.let line = lines.get_mut("level").expect("the last answer"); line.unanswered(None, 7 * MINUTE + OFFLINE_AFTER_MS);let standing = line.standing(7 * MINUTE + OFFLINE_AFTER_MS); assert_eq!((standing.state, standing.since), (State::Offline, Some(7 * MINUTE))); std::fs::write(&path, "not json").expect("written"); assert!(stored(&path).is_empty(), "an unreadable file is nothing in flight");}/// RULE: This device's file of lines is written when a catch-up begins, moves a percent or ends, and at most every five minutes for the time a Mac last answered — never once a pass.#[test]fn the_file_of_lines_is_not_written_once_a_pass() {letmut line = HomeLine::default(); line.answered(Answered { owed_at_start: Some(100_000), ..behind(0, 5_000, COUNTED_UP_TO) }, 0);let was = line.clone();// 400 more rows a minute later: the same percent, the same five minutes. line.answered(behind(0, 400, COUNTED_UP_TO), MINUTE); assert!(line.same_place(&was)); line.answered(behind(0, 1_000, COUNTED_UP_TO), 2 * MINUTE); assert!(!line.same_place(&was), "a percent on");let was = line.clone(); line.answered(behind(0, 0, COUNTED_UP_TO), 5 * MINUTE); assert!(!line.same_place(&was), "five minutes on");let was = line.clone(); line.answered(level(), 5 * MINUTE); assert!(!line.same_place(&was), "level");}/// RULE: While a catch-up is in flight and pages keep arriving, the page line is "Syncing · N% · M changes to go" and never "not reachable" — however long the catch-up runs and however many passes fail between the pages; "offline" (the page's "Not synced since … · not reachable") is said only when no Mac has answered at all for fifteen minutes, and then since the LAST answer, never an older finished pass (13 Oct 2026: the phone's catch-up after the 136 move read "Not synced since 03:22" while rows were arriving).#[test]fn a_catch_up_with_pages_arriving_is_syncing_and_never_not_reachable() {// A relaunched app: the last pass that finished was hours ago.letmut line = HomeLine { answered_at: Some(0), ..HomeLine::default() };let start = 7 * 60 * MINUTE; line.answered(Answered { owed_at_start: Some(448_000), ..behind(0, 1_000, COUNTED_UP_TO) }, start, );// Two hours of passes: every other one fails after folding nothing, the// rest fold a page — a slow catch-up, not a silent Mac.for minute in1..=120 {let now = start + minute * MINUTE;if minute % 2 == 0 { line.answered(behind(0, 1_000, COUNTED_UP_TO), now); } else { line.unanswered(None, now); }let standing = line.standing(now); assert_eq!(standing.state, State::Syncing, "minute {minute}: {standing:?}"); assert!( standing.page.starts_with("Syncing \u{00B7} ") && standing.page.ends_with(" changes to go"),"minute {minute}: {}", standing.page ); }// Then the Mac goes silent: fourteen minutes say nothing new, fifteen// say offline since the last page, not since the night before.let last = start + 120 * MINUTE; line.unanswered(None, last + MINUTE); assert_eq!(line.standing(last + OFFLINE_AFTER_MS - 1).state, State::Syncing);let offline = line.standing(last + OFFLINE_AFTER_MS); assert_eq!((offline.state, offline.since), (State::Offline, Some(last)));}/// RULE: the serving Mac's contact is ONE fact per Mac, read the same from/// every database it serves (295 rule 16 — another database's Me said "Up to/// date · synced 6 min ago" and Copies "heard just now" while Personal's said/// the Mac was not heard, the relay unreachable): heard at the latest answer/// any of them had, and not heard from the first failure after it — a pass/// that failed every section, or a failure reported for only one of them./// A section refused in the same pass that answered the rest is that/// database's own and leaves the Mac heard.#[test]fn a_macs_contact_is_one_fact_across_every_database_it_serves() {let (mut personal, mut kitchen) = (HomeLine::default(), HomeLine::default()); personal.answered(level(), MINUTE); kitchen.answered(level(), MINUTE + 3); assert_eq!(mac_contact([&personal, &kitchen]), (Some(MINUTE + 3), None));// A section refused in the pass that answered the other: still heard.letmut answered = personal.clone(); answered.answered(level(), 2 * MINUTE);letmut refused = kitchen.clone(); refused.unanswered(None, 2 * MINUTE + 4); assert_eq!(mac_contact([&answered, &refused]), (Some(2 * MINUTE), None));// Only Personal's line saw the failure: the kitchen's reads it too. personal.unanswered(None, 3 * MINUTE); assert_eq!(mac_contact([&personal, &kitchen]), (Some(MINUTE + 3), Some(3 * MINUTE))); assert_eq!(mac_contact([&kitchen, &personal]), mac_contact([&personal, &kitchen]), "the order of the lines says nothing");// A pass that reached nobody fails every section; the first failure after// the last answer is when the Mac went unheard, a later one never moves it. kitchen.unanswered(None, 4 * MINUTE); assert_eq!(mac_contact([&personal, &kitchen]), (Some(MINUTE + 3), Some(3 * MINUTE)));// Never answered at all: not heard since the first failure.letmut never = HomeLine::default(); never.unanswered(None, 5 * MINUTE); assert_eq!(mac_contact([&never]), (None, Some(5 * MINUTE))); assert_eq!(mac_contact([&HomeLine::default()]), (None, None));}