feat: the window and the server say each new state in words; a proof cut short is made again; the proof does not mistake the books' own recovery for a changed head

- books ahead of the folder (as after a restore from an older backup) offer a
  new backup set beside the old one, at the person's request: books.back_up_now
  new_set, back-up --new-set, a button in the Backups window
- a key file lost from a sealed destination stops backups and asks for the
  passphrase; plain is written only after an explicit removal, which the record
  keeps (a damaged record falls back to what the folder itself holds)
- a restore that is not of the newest backup says so first, in the warning
  colour, with both dates and how many backups it passes over
- a folder a sync service keeps (or may) is said in plain words at set-up and
  in the window: one computer only, kept offline, a second computer its own
- a drill that finds only an older whole backup fails in words
- a manifest whose proof was cut short is marked unproven and proven by the
  next backup, even one with nothing new; a saved backup file is proven whole
  before it is given its name
- the proof compares the journal its pieces make with the head the manifest
  records before the books open, and lets opening add only after it
- the restore tests are split from backups.rs to keep each under a minute; the
  clone-of-an-old-git-backup test builds the working tree without git

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-21 20:07:38 -07:00
1 parent 9ac47a3f10
commit 344b3b4abe
21 files changed
+2346 -690

No files matched your search

+21 -9
View File
@@ -452,6 +452,7 @@ fn pieces(set: &Path) -> Vec<PathBuf> {
.keys()
.filter(|n| {
!n.starts_with("manifests/")
&& !n.starts_with("proofs/")
&& !n.ends_with("READ-ME.txt")
&& !n.ends_with("header.json")
})
@@ -562,7 +563,13 @@ fn a_program_that_dies_at_any_write_leaves_what_proved_whole_before() {
let mut s = book(&b);
let base_disk = dir.path().join("base");
std::fs::create_dir(&base_disk).unwrap();
write_destination(&plain(&base_disk), &cut(&b, &s), true, &Ctx::new()).unwrap();
write_destination(
&plain(&base_disk),
&cut(&b, &s),
true,
&Ctx::new().with_proof_skipped(),
)
.unwrap();
let first_head = s.head();
more(&mut s, 1);
let c = cut(&b, &s);
@@ -573,10 +580,12 @@ fn a_program_that_dies_at_any_write_leaves_what_proved_whole_before() {
let disk = dir.path().join("probe");
copy_tree(&base_disk, &disk);
let n = counted.clone();
let ctx = Ctx::new().with_faults(Arc::new(move |_, _| {
n.fetch_add(1, Ordering::SeqCst);
false
}));
let ctx = Ctx::new()
.with_proof_skipped()
.with_faults(Arc::new(move |_, _| {
n.fetch_add(1, Ordering::SeqCst);
false
}));
write_destination(&plain(&disk), &c, true, &ctx).unwrap();
counted.load(Ordering::SeqCst)
};
@@ -588,9 +597,11 @@ fn a_program_that_dies_at_any_write_leaves_what_proved_whole_before() {
let n = Arc::new(AtomicUsize::new(0));
let ctx = {
let n = n.clone();
Ctx::new().with_faults(Arc::new(move |_, _| {
n.fetch_add(1, Ordering::SeqCst) == die_at
}))
Ctx::new()
.with_proof_skipped()
.with_faults(Arc::new(move |_, _| {
n.fetch_add(1, Ordering::SeqCst) == die_at
}))
};
let err = write_destination(&plain(&disk), &c, true, &ctx).unwrap_err();
assert_eq!(err, BackupError::Died, "point {die_at}");
@@ -609,7 +620,8 @@ fn a_program_that_dies_at_any_write_leaves_what_proved_whole_before() {
assert!(live.starts_with(&restored), "point {die_at}");
// And the next run goes on from it (proven again at some points:
// each proof replays the books).
let w = write_destination(&plain(&disk), &c, true, &Ctx::new()).unwrap();
let w =
write_destination(&plain(&disk), &c, true, &Ctx::new().with_proof_skipped()).unwrap();
assert_eq!(w.head, s.head());
if die_at % 6 == 0 {
let again = prove(&disk, None, dir.path(), &format!("again-{die_at}")).unwrap();
+12
View File
@@ -223,8 +223,17 @@ fn a_taken_number_or_name_is_never_replaced_on_a_disk_that_makes_no_links() {
const PASS: &str = "correct horse battery staple";
/// The count of derived keys is the process's: the tests that read it, and
/// every test that derives one, take turns.
static KEYS: std::sync::Mutex<()> = std::sync::Mutex::new(());
fn one_at_a_time() -> std::sync::MutexGuard<'static, ()> {
KEYS.lock().unwrap_or_else(|e| e.into_inner())
}
#[test]
fn sealed_pieces_are_spread_over_folders_as_the_plain_form_does() {
let _turn = one_at_a_time();
let dir = tempfile::tempdir().unwrap();
let b = dir.path().join("book");
let mut s = book(&b);
@@ -295,6 +304,7 @@ fn set_header(header: &Path, edit: impl Fn(&mut serde_json::Value)) {
#[test]
fn a_header_cannot_ask_for_more_than_a_few_times_what_this_program_spends() {
let _turn = one_at_a_time();
let dir = tempfile::tempdir().unwrap();
let b = dir.path().join("book");
let s = book(&b);
@@ -330,6 +340,7 @@ fn a_header_cannot_ask_for_more_than_a_few_times_what_this_program_spends() {
#[test]
fn a_header_that_was_changed_reads_as_damage_and_not_as_a_wrong_passphrase() {
let _turn = one_at_a_time();
let dir = tempfile::tempdir().unwrap();
let b = dir.path().join("book");
let s = book(&b);
@@ -365,6 +376,7 @@ fn a_header_that_was_changed_reads_as_damage_and_not_as_a_wrong_passphrase() {
#[test]
fn a_folder_of_sealed_sets_costs_one_key_derivation_per_setting_not_one_per_set() {
let _turn = one_at_a_time();
let dir = tempfile::tempdir().unwrap();
let b = dir.path().join("book");
let s = book(&b);
+29 -8
View File
@@ -36,6 +36,13 @@ fn ops() -> impl Strategy<Value = Vec<Op>> {
)
}
/// A context for tests of logic, not of durability: nothing is synced.
fn fast() -> Ctx {
// The proof after a backup has tests of its own (backup_repair.rs); the
// properties here prove what they make by restoring it.
Ctx::new().with_no_sync().with_proof_skipped()
}
fn plain(folder: &Path) -> Destination {
Destination {
folder: folder.to_path_buf(),
@@ -156,7 +163,7 @@ proptest! {
for op in &ops {
books.apply(op);
if matches!(op, Op::Backup) {
write_destination(&plain(&disk), &books.cut(), true, &Ctx::new()).unwrap();
write_destination(&plain(&disk), &books.cut(), true, &fast()).unwrap();
let after = tree(&disk);
for (name, bytes) in &before {
prop_assert_eq!(after.get(name), Some(bytes), "{} changed or went", name);
@@ -180,14 +187,14 @@ proptest! {
for op in &ops {
books.apply(op);
if matches!(op, Op::Backup) {
let w = write_destination(&plain(&disk), &books.cut(), true, &Ctx::new()).unwrap();
let w = write_destination(&plain(&disk), &books.cut(), true, &fast()).unwrap();
if w.new {
heads.push((w.number, w.head));
}
}
}
// (A last backup, so there is at least one.)
let w = write_destination(&plain(&disk), &books.cut(), true, &Ctx::new()).unwrap();
let w = write_destination(&plain(&disk), &books.cut(), true, &fast()).unwrap();
if w.new {
heads.push((w.number, w.head));
}
@@ -240,9 +247,15 @@ proptest! {
let count = Arc::new(AtomicUsize::new(0));
let rival = {
let (disk, second, count) = (disk.clone(), second.clone(), count.clone());
Ctx::new().with_faults(Arc::new(move |_, _| {
fast().with_faults(Arc::new(move |_, _| {
if count.fetch_add(1, Ordering::SeqCst) == at {
write_destination(&plain(&disk), &second, true, &Ctx::new()).unwrap();
write_destination(
&plain(&disk),
&second,
true,
&fast(),
)
.unwrap();
}
false
}))
@@ -275,11 +288,19 @@ proptest! {
for op in &ops {
books.apply(op);
}
write_destination(&plain(&disk), &books.cut(), true, &Ctx::new()).unwrap();
write_destination(
&plain(&disk),
&books.cut(),
true,
&fast(),
)
.unwrap();
let set = disk.join("wanderbooks-acme");
let pieces: Vec<String> = tree(&set)
.into_keys()
.filter(|n| !n.starts_with("manifests/") && n != "READ-ME.txt")
.filter(|n| {
!n.starts_with("manifests/") && !n.starts_with("proofs/") && n != "READ-ME.txt"
})
.collect();
let name = &pieces[pick.index(pieces.len())];
let path = set.join(name);
@@ -309,7 +330,7 @@ proptest! {
folder: disk.clone(),
key: Some(BackupKey::generate("the right words, exactly").unwrap()),
};
write_destination(&dest, &books.cut(), true, &Ctx::new()).unwrap();
write_destination(&dest, &books.cut(), true, &fast()).unwrap();
let scratch = dir.path().join("v");
let got = prove(&disk, Some(&wrong), &scratch);
prop_assert!(matches!(got, Err(BackupError::WrongPassphrase)), "{got:?}");
@@ -739,3 +739,52 @@ fn a_backup_cut_while_the_vault_is_being_written_restores_a_vault_that_matches_t
.any(|n| n.contains(".staged-") || n.contains(".purging-"))
);
}
#[test]
fn a_proof_cut_short_by_a_close_ends_cleanly_and_is_made_again_by_the_next_backup() {
use std::sync::atomic::{AtomicBool, Ordering};
let dir = tempfile::tempdir().unwrap();
let b = dir.path().join("book");
let s = book(&b);
let disk = dir.path().join("disk");
std::fs::create_dir(&disk).unwrap();
// The books close while the backup's proof is under way (here: as it
// replays the chain).
let stop = Arc::new(AtomicBool::new(false));
let ctx = {
let stop = stop.clone();
Ctx::new()
.with_stop(stop.clone())
.with_phase_watch(Arc::new(move |p: &str| {
if p == "replay" {
stop.store(true, Ordering::SeqCst);
}
}))
};
let err = write_destination(&plain(&disk), &cut(&b, &s), true, &ctx).unwrap_err();
assert!(matches!(err, BackupError::Cancelled(_)), "{err:?}");
// Nothing of the proof is left behind in the books' folder, and the
// manifest that was written is there but is not marked proven.
let left: Vec<_> = std::fs::read_dir(b.join("ops"))
.map(|d| {
d.flatten()
.filter(|e| e.file_name().to_string_lossy().starts_with("proof-"))
.collect()
})
.unwrap_or_default();
assert!(left.is_empty(), "scratch books left: {left:?}");
let set = set_of(&disk);
assert!(set.join("manifests/000001.json").is_file());
assert!(!set.join("proofs/000001").exists());
// The next backup has nothing new to write, and still proves it: it
// never says good of a backup that was not proven.
let w = write_destination(&plain(&disk), &cut(&b, &s), true, &Ctx::new()).unwrap();
assert_eq!(w.number, 1);
assert!(!w.new, "{w:?}");
assert!(set.join("proofs/000001").is_file());
// Once proven, a backup with nothing new is only looked at.
let before = tree(&disk);
let w = write_destination(&plain(&disk), &cut(&b, &s), true, &Ctx::new()).unwrap();
assert!(!w.new);
assert_eq!(tree(&disk), before);
}