test: the local backup and the open/close tests name the set folder by its new name; words, record and sync tests for the server and the host
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
573dcb0531
commit
535f4fed40
4 files changed
+147
-2
No files matched your search
@@ -1713,7 +1713,7 @@ fn backed_up_to_folder(home: &Home, w: &mut Wire, id: &str) -> PathBuf {
|
||||
Response::BackedUp { targets, .. } => assert!(targets[0].problem.is_none(), "{targets:?}"),
|
||||
other => panic!("{other:?}"),
|
||||
}
|
||||
disk.join(id)
|
||||
disk.join(format!("wanderbooks-{id}"))
|
||||
}
|
||||
|
||||
/// A restore over an open book lets go of it as a close does: what is
|
||||
|
||||
@@ -4433,6 +4433,70 @@ mod tests {
|
||||
};
|
||||
let say = |s: &admin::BackupStanding| backup_words(s).join(" | ");
|
||||
assert_eq!(say(&base), "Not backed up: no backup folder is chosen yet.");
|
||||
// The new states, each in words: books ahead of the folder, a key
|
||||
// lost, a newest backup that is damaged, files found damaged, a
|
||||
// synced folder.
|
||||
let there = admin::BackupStanding {
|
||||
folder: Some("/media/disk".into()),
|
||||
last_ok_at: Some("2026-11-21T10:00:00Z".into()),
|
||||
through_seq: Some(5),
|
||||
..base.clone()
|
||||
};
|
||||
let ahead = admin::BackupStanding {
|
||||
last_error: Some("the backup folder holds a longer history of these books".into()),
|
||||
error_kind: Some("ahead".into()),
|
||||
..there.clone()
|
||||
};
|
||||
let said = say(&ahead);
|
||||
assert!(said.contains("restored from an older backup"), "{said}");
|
||||
assert!(said.contains("start a new backup set"), "{said}");
|
||||
let lost = admin::BackupStanding {
|
||||
last_error: Some("no longer has its key".into()),
|
||||
error_kind: Some("key_missing".into()),
|
||||
sealed: true,
|
||||
..there.clone()
|
||||
};
|
||||
assert!(say(&lost).contains("Enter the backup passphrase again"));
|
||||
let drill = admin::BackupStanding {
|
||||
drill_error: Some(
|
||||
"the newest backup (number 3, from today) is damaged; an older one from last week is whole"
|
||||
.into(),
|
||||
),
|
||||
error_kind: Some("newest_damaged".into()),
|
||||
..there.clone()
|
||||
};
|
||||
let said = say(&drill);
|
||||
assert!(said.contains("weekly check"), "{said}");
|
||||
assert!(said.contains("older books"), "{said}");
|
||||
assert!(!said.contains("Proven restorable"), "{said}");
|
||||
let damaged = admin::BackupStanding {
|
||||
damaged_files: vec!["journal/000002-abc".into()],
|
||||
sync: Some(ledger_mcp::backup::sync_words(Some("Dropbox"))),
|
||||
..there.clone()
|
||||
};
|
||||
let said = say(&damaged);
|
||||
assert!(
|
||||
said.contains("found damaged and were written again"),
|
||||
"{said}"
|
||||
);
|
||||
assert!(said.contains("journal/000002-abc"), "{said}");
|
||||
assert!(said.contains("kept in sync by Dropbox"), "{said}");
|
||||
let preview = admin::RestorePreview {
|
||||
head: (3, "ab".into()),
|
||||
blobs: 0,
|
||||
vault_files: 0,
|
||||
exists: false,
|
||||
origin: None,
|
||||
sealed: false,
|
||||
passed_over: 2,
|
||||
written: Some("2026-11-14T10:00:00Z".into()),
|
||||
newest_written: Some("2026-11-21T10:00:00Z".into()),
|
||||
};
|
||||
let said = older_backup_words(&preview);
|
||||
assert!(said.starts_with("NOT THE NEWEST BACKUP"), "{said}");
|
||||
assert!(said.contains("passes over 2 newer backups"), "{said}");
|
||||
assert!(said.contains("This backup is from"), "{said}");
|
||||
assert!(said.contains("the newest in the folder is from"), "{said}");
|
||||
let with_folder = admin::BackupStanding {
|
||||
folder: Some("/media/disk/Backups".into()),
|
||||
..base.clone()
|
||||
|
||||
@@ -1615,6 +1615,87 @@ mod tests {
|
||||
assert_eq!(hide(&"x".repeat(2000), dir).len(), ERROR_MAX);
|
||||
}
|
||||
|
||||
fn obj(v: Value) -> Map<String, Value> {
|
||||
match v {
|
||||
Value::Object(m) => m,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
/// What the record says of whether the backups are sealed: the newest
|
||||
/// word on it (a set-up's choice, a push's `sealed`), and the key's
|
||||
/// fingerprint from the newest record that was made with one.
|
||||
#[test]
|
||||
fn the_record_remembers_whether_backups_were_sealed_and_with_which_key() {
|
||||
assert_eq!(sealed_before(&[]), None);
|
||||
let setup = obj(json!({"kind": "setup", "passphrase": "set", "fp": "abc"}));
|
||||
let sealed_push = obj(json!({"kind": "push", "ok": true, "sealed": true, "fp": "abc"}));
|
||||
// A push that could not be made (no key) says sealed and no
|
||||
// fingerprint: the fingerprint is the one before it.
|
||||
let stopped = obj(json!({"kind": "push", "ok": false, "sealed": true}));
|
||||
let removed = obj(json!({"kind": "setup", "passphrase": "removed"}));
|
||||
let plain_push = obj(json!({"kind": "push", "ok": true, "sealed": false}));
|
||||
let commit = obj(json!({"kind": "commit", "ok": true}));
|
||||
assert_eq!(
|
||||
sealed_before(std::slice::from_ref(&setup)),
|
||||
Some((true, Some("abc".into())))
|
||||
);
|
||||
assert_eq!(
|
||||
sealed_before(&[
|
||||
setup.clone(),
|
||||
sealed_push.clone(),
|
||||
stopped.clone(),
|
||||
commit.clone()
|
||||
]),
|
||||
Some((true, Some("abc".into())))
|
||||
);
|
||||
// Taken off on purpose: plain is meant, whatever came before.
|
||||
assert_eq!(
|
||||
sealed_before(&[setup.clone(), sealed_push, stopped, removed.clone()]),
|
||||
Some((false, None))
|
||||
);
|
||||
assert_eq!(
|
||||
sealed_before(&[setup, removed, plain_push]),
|
||||
Some((false, None))
|
||||
);
|
||||
// Records that say nothing of it (older ones) say nothing.
|
||||
assert_eq!(sealed_before(&[commit]), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_folder_a_sync_service_keeps_is_known_by_its_path() {
|
||||
for (path, service) in [
|
||||
("/home/u/Dropbox/Backups", Some("Dropbox")),
|
||||
("/home/u/Dropbox (Personal)/Books", Some("Dropbox")),
|
||||
(
|
||||
"/Users/u/Library/CloudStorage/OneDrive-Acme/Books",
|
||||
Some("OneDrive"),
|
||||
),
|
||||
("/Users/u/OneDrive/Books", Some("OneDrive")),
|
||||
(
|
||||
"/Users/u/Library/Mobile Documents/com~apple~CloudDocs/Books",
|
||||
Some("iCloud Drive"),
|
||||
),
|
||||
("/Users/u/iCloud Drive/Books", Some("iCloud Drive")),
|
||||
("/home/u/Google Drive/My Drive/Books", Some("Google Drive")),
|
||||
("/home/u/Nextcloud/Books", Some("Nextcloud")),
|
||||
("/media/u/usb-stick/Backups", None),
|
||||
("/home/u/Documents/Dropboxes-are-not-it", None),
|
||||
] {
|
||||
assert_eq!(sync_service(Path::new(path)), service, "{path}");
|
||||
}
|
||||
let said = sync_words(Some("Dropbox"));
|
||||
assert!(said.contains("kept in sync by Dropbox"));
|
||||
for part in [
|
||||
"one computer only",
|
||||
"available offline",
|
||||
"folder of its own",
|
||||
] {
|
||||
assert!(said.contains(part), "{part}");
|
||||
assert!(sync_words(None).contains(part), "{part}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A record of `kind` for target `key`, `ago` before `now`.
|
||||
fn rec(
|
||||
now: chrono::DateTime<chrono::Utc>,
|
||||
|
||||
@@ -5418,7 +5418,7 @@ mod tests {
|
||||
// Its journal piece is damaged, one byte.
|
||||
let piece = std::fs::read_dir(
|
||||
dir.join(ledger_store::backup::LOCAL_DIR)
|
||||
.join("acme")
|
||||
.join("wanderbooks-acme")
|
||||
.join("journal"),
|
||||
)
|
||||
.unwrap()
|
||||
|
||||
Reference in new issue
Block a user