test(store): backups as properties; claims for the plain-folder form
WB-backup-1 to WB-backup-11 state the laws (a destination only grows; a manifest names only pieces that exist and hash right; a restore of any whole manifest is a prefix of the books; other or newer history is never written; two writers cannot corrupt a destination and a death at any write leaves the previous manifest whole; a damaged piece is never restored; a wrong passphrase never yields books). Property tests hold them over random books, random backups, random interleavings of two writers, and any flipped or cut piece. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
91d88dcee7
commit
11188be47e
3 files changed
+509
-4
No files matched your search
@@ -0,0 +1,320 @@
|
||||
//! Backups as properties (WB-backup-1 to WB-backup-7): random books and
|
||||
//! random sequences of backups, interleavings of two writers, damage to any
|
||||
//! piece, and passphrases that are not the right one. Each case builds a
|
||||
//! book, which is the cost; the cases are few and the oracles are the laws.
|
||||
|
||||
use ledger_core::{AccountType, Currency};
|
||||
use ledger_store::Store;
|
||||
use ledger_store::backup::{
|
||||
BackupError, BackupKey, Ctx, Cut, Destination, find, verify_found, write_destination,
|
||||
};
|
||||
use proptest::prelude::*;
|
||||
use std::collections::BTreeMap;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
/// One thing that happens to the books between backups.
|
||||
#[derive(Clone, Debug)]
|
||||
enum Op {
|
||||
/// A new account.
|
||||
Account,
|
||||
/// A stored file of these bytes (the same bytes twice are one file).
|
||||
File(Vec<u8>),
|
||||
/// A backup.
|
||||
Backup,
|
||||
}
|
||||
|
||||
fn ops() -> impl Strategy<Value = Vec<Op>> {
|
||||
prop::collection::vec(
|
||||
prop_oneof![
|
||||
2 => Just(Op::Account),
|
||||
2 => prop::collection::vec(any::<u8>(), 1..40).prop_map(Op::File),
|
||||
3 => Just(Op::Backup),
|
||||
],
|
||||
2..9,
|
||||
)
|
||||
}
|
||||
|
||||
fn plain(folder: &Path) -> Destination {
|
||||
Destination {
|
||||
folder: folder.to_path_buf(),
|
||||
key: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn tree(root: &Path) -> BTreeMap<String, Vec<u8>> {
|
||||
fn walk(base: &Path, dir: &Path, out: &mut BTreeMap<String, Vec<u8>>) {
|
||||
for e in std::fs::read_dir(dir).unwrap() {
|
||||
let p = e.unwrap().path();
|
||||
if p.is_dir() {
|
||||
walk(base, &p, out);
|
||||
} else {
|
||||
let rel = p
|
||||
.strip_prefix(base)
|
||||
.unwrap()
|
||||
.to_string_lossy()
|
||||
.replace('\\', "/");
|
||||
out.insert(rel, std::fs::read(&p).unwrap());
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut out = BTreeMap::new();
|
||||
if root.is_dir() {
|
||||
walk(root, root, &mut out);
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
fn copy_tree(from: &Path, to: &Path) {
|
||||
std::fs::create_dir_all(to).unwrap();
|
||||
for (rel, bytes) in tree(from) {
|
||||
let p = to.join(rel);
|
||||
std::fs::create_dir_all(p.parent().unwrap()).unwrap();
|
||||
std::fs::write(p, bytes).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
/// A book with one account, and a way to apply [`Op`]s to it.
|
||||
struct Books {
|
||||
store: Store,
|
||||
dir: std::path::PathBuf,
|
||||
n: usize,
|
||||
}
|
||||
|
||||
impl Books {
|
||||
fn new(dir: &Path) -> Self {
|
||||
let mut store = Store::create(dir, Currency::USD).unwrap();
|
||||
store
|
||||
.add_account("1000", "Cash", AccountType::Asset, None, false)
|
||||
.unwrap();
|
||||
Self {
|
||||
store,
|
||||
dir: dir.to_path_buf(),
|
||||
n: 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn apply(&mut self, op: &Op) {
|
||||
match op {
|
||||
Op::Account => {
|
||||
self.n += 1;
|
||||
self.store
|
||||
.add_account(
|
||||
&format!("{}", 6000 + self.n),
|
||||
&format!("Expense {}", self.n),
|
||||
AccountType::Expense,
|
||||
None,
|
||||
false,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
Op::File(bytes) => {
|
||||
self.store
|
||||
.attach_receipt(None, "f.bin", "application/octet-stream", bytes, None)
|
||||
.unwrap();
|
||||
}
|
||||
Op::Backup => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn cut(&self) -> Cut {
|
||||
Cut::take("acme", &self.dir, self.store.head()).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
fn prove(
|
||||
folder: &Path,
|
||||
pass: Option<&str>,
|
||||
scratch: &Path,
|
||||
) -> Result<ledger_store::backup::Verified, BackupError> {
|
||||
let found = find(folder, pass, &Ctx::new())?;
|
||||
verify_found(&found, scratch, &Ctx::new())
|
||||
}
|
||||
|
||||
fn config() -> ProptestConfig {
|
||||
ProptestConfig {
|
||||
cases: 5,
|
||||
max_shrink_iters: 4,
|
||||
failure_persistence: None,
|
||||
..ProptestConfig::default()
|
||||
}
|
||||
}
|
||||
|
||||
proptest! {
|
||||
#![proptest_config(config())]
|
||||
|
||||
/// WB-backup-1: whatever the books do and whenever they are backed up,
|
||||
/// every file the destination held is still there, byte for byte.
|
||||
#[test]
|
||||
fn a_destination_only_grows(ops in ops()) {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let mut books = Books::new(&dir.path().join("book"));
|
||||
let disk = dir.path().join("disk");
|
||||
std::fs::create_dir(&disk).unwrap();
|
||||
let mut before = tree(&disk);
|
||||
for op in &ops {
|
||||
books.apply(op);
|
||||
if matches!(op, Op::Backup) {
|
||||
write_destination(&plain(&disk), &books.cut(), true, &Ctx::new()).unwrap();
|
||||
let after = tree(&disk);
|
||||
for (name, bytes) in &before {
|
||||
prop_assert_eq!(after.get(name), Some(bytes), "{} changed or went", name);
|
||||
}
|
||||
prop_assert!(!after.keys().any(|n| n.contains(".wb-tmp-")));
|
||||
before = after;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// WB-backup-3: the destination as of any of its manifests restores to
|
||||
/// books whose journal is byte-identical to the beginning of the
|
||||
/// books' journal now, and whose head is the one that manifest names.
|
||||
#[test]
|
||||
fn any_whole_manifest_restores_a_prefix_of_the_books(ops in ops()) {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let mut books = Books::new(&dir.path().join("book"));
|
||||
let disk = dir.path().join("disk");
|
||||
std::fs::create_dir(&disk).unwrap();
|
||||
let mut heads = Vec::new();
|
||||
for op in &ops {
|
||||
books.apply(op);
|
||||
if matches!(op, Op::Backup) {
|
||||
let w = write_destination(&plain(&disk), &books.cut(), true, &Ctx::new()).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();
|
||||
if w.new {
|
||||
heads.push((w.number, w.head));
|
||||
}
|
||||
let live = std::fs::read(dir.path().join("book").join("journal.jsonl")).unwrap();
|
||||
for (number, head) in &heads {
|
||||
// The destination as it was when that manifest was the newest.
|
||||
let then = dir.path().join(format!("then-{number}"));
|
||||
copy_tree(&disk, &then);
|
||||
for (name, _) in tree(&then) {
|
||||
if let Some(n) = name
|
||||
.strip_prefix("acme/manifests/")
|
||||
.and_then(|r| r.strip_suffix(".json"))
|
||||
.and_then(|r| r.parse::<u64>().ok())
|
||||
&& n > *number
|
||||
{
|
||||
std::fs::remove_file(then.join(&name)).unwrap();
|
||||
}
|
||||
}
|
||||
let v = prove(&then, None, &dir.path().join(format!("v-{number}"))).unwrap();
|
||||
prop_assert_eq!(&v.head, head);
|
||||
let restored = std::fs::read(v.tree.join("journal.jsonl")).unwrap();
|
||||
prop_assert!(live.starts_with(&restored));
|
||||
}
|
||||
}
|
||||
|
||||
/// WB-backup-5: a writer that finds another writer's backup appear at
|
||||
/// any of its write points (the other with books a little behind or a
|
||||
/// little ahead) leaves a destination that proves whole, at the head
|
||||
/// of one of them, restoring to a prefix of the longer books.
|
||||
#[test]
|
||||
fn random_interleavings_of_two_writers_leave_a_whole_backup(
|
||||
files in prop::collection::vec(prop::collection::vec(any::<u8>(), 1..20), 1..3),
|
||||
rival_after in 0usize..3,
|
||||
at in 0usize..14,
|
||||
) {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let mut books = Books::new(&dir.path().join("book"));
|
||||
for f in &files {
|
||||
books.apply(&Op::File(f.clone()));
|
||||
}
|
||||
let first = books.cut();
|
||||
for _ in 0..rival_after {
|
||||
books.apply(&Op::Account);
|
||||
}
|
||||
let second = books.cut();
|
||||
let disk = dir.path().join("disk");
|
||||
std::fs::create_dir(&disk).unwrap();
|
||||
// The writer of `first` is met, at its `at`th write point, by a
|
||||
// complete write of `second`.
|
||||
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 |_, _| {
|
||||
if count.fetch_add(1, Ordering::SeqCst) == at {
|
||||
write_destination(&plain(&disk), &second, true, &Ctx::new()).unwrap();
|
||||
}
|
||||
false
|
||||
}))
|
||||
};
|
||||
let mine = write_destination(&plain(&disk), &first, true, &rival);
|
||||
match mine {
|
||||
Ok(_) | Err(BackupError::Ahead(..)) | Err(BackupError::Elsewhere) => {}
|
||||
Err(e) => prop_assert!(false, "{e:?}"),
|
||||
}
|
||||
let v = prove(&disk, None, &dir.path().join("v")).unwrap();
|
||||
prop_assert!(v.head == *first.head() || v.head == *second.head());
|
||||
let live = std::fs::read(dir.path().join("book").join("journal.jsonl")).unwrap();
|
||||
prop_assert!(live.starts_with(&std::fs::read(v.tree.join("journal.jsonl")).unwrap()));
|
||||
}
|
||||
|
||||
/// WB-backup-6: a piece with one byte flipped, or cut anywhere, is
|
||||
/// found: the backup that names it is not restored.
|
||||
#[test]
|
||||
fn any_flipped_or_cut_piece_is_found_never_restored(
|
||||
ops in ops(),
|
||||
pick in any::<prop::sample::Index>(),
|
||||
at in any::<prop::sample::Index>(),
|
||||
cut in any::<bool>(),
|
||||
) {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let mut books = Books::new(&dir.path().join("book"));
|
||||
books.apply(&Op::File(vec![1, 2, 3, 4]));
|
||||
let disk = dir.path().join("disk");
|
||||
std::fs::create_dir(&disk).unwrap();
|
||||
for op in &ops {
|
||||
books.apply(op);
|
||||
}
|
||||
write_destination(&plain(&disk), &books.cut(), true, &Ctx::new()).unwrap();
|
||||
let set = disk.join("acme");
|
||||
let pieces: Vec<String> = tree(&set)
|
||||
.into_keys()
|
||||
.filter(|n| !n.starts_with("manifests/") && n != "READ-ME.txt")
|
||||
.collect();
|
||||
let name = &pieces[pick.index(pieces.len())];
|
||||
let path = set.join(name);
|
||||
let mut bytes = std::fs::read(&path).unwrap();
|
||||
prop_assume!(!bytes.is_empty());
|
||||
let i = at.index(bytes.len());
|
||||
if cut {
|
||||
bytes.truncate(i);
|
||||
} else {
|
||||
bytes[i] ^= 0x01;
|
||||
}
|
||||
std::fs::write(&path, &bytes).unwrap();
|
||||
let scratch = dir.path().join("v");
|
||||
prop_assert!(prove(&disk, None, &scratch).is_err(), "{name} damaged was restored");
|
||||
prop_assert!(!scratch.exists());
|
||||
}
|
||||
|
||||
/// WB-backup-7: no passphrase but the right one gives books.
|
||||
#[test]
|
||||
fn a_wrong_passphrase_never_yields_books(wrong in "[a-zA-Z0-9 ]{1,30}") {
|
||||
prop_assume!(wrong != "the right words, exactly");
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let books = Books::new(&dir.path().join("book"));
|
||||
let disk = dir.path().join("disk");
|
||||
std::fs::create_dir(&disk).unwrap();
|
||||
let dest = Destination {
|
||||
folder: disk.clone(),
|
||||
key: Some(BackupKey::generate("the right words, exactly").unwrap()),
|
||||
};
|
||||
write_destination(&dest, &books.cut(), true, &Ctx::new()).unwrap();
|
||||
let scratch = dir.path().join("v");
|
||||
let got = prove(&disk, Some(&wrong), &scratch);
|
||||
prop_assert!(matches!(got, Err(BackupError::WrongPassphrase)), "{got:?}");
|
||||
prop_assert!(!scratch.exists());
|
||||
let none = prove(&disk, None, &scratch);
|
||||
prop_assert!(matches!(none, Err(BackupError::NeedsPassphrase)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
# Claims: backups
|
||||
|
||||
Wanderbooks' own product rules for backups: plain folders, written once,
|
||||
optionally sealed with a passphrase (plan P15 section 9, D-91 and D-92,
|
||||
`plan/p15-app-and-relay.md`). No authority outside this product states them.
|
||||
They are `WB-backup-<n>`. They replace the rules for backups made with git
|
||||
(D-30, D-31), which are gone.
|
||||
|
||||
Rules: none from bookspec's list; these are product rules only. What a backup
|
||||
holds (the journal, the stored files, the vault, the keys, the access log;
|
||||
never the database, which a restore rebuilds) and when it runs are unchanged
|
||||
(plan 3.7).
|
||||
|
||||
---
|
||||
|
||||
### Product rules
|
||||
|
||||
**WB-backup-1 A backup is plain files, each written once, so a destination
|
||||
only grows.** A destination is a folder the person picks. It holds one folder
|
||||
per set of books, with a read-me in plain words, a folder of manifests, and
|
||||
the pieces the manifests name: the journal and the access log as numbered
|
||||
segments, an index of the stored files, the stored files themselves under
|
||||
their hash, and the vault and the keys under their content hash. Every file is
|
||||
put once: written under a scratch name in its own folder, synced, and given
|
||||
its name by a hard link, which is made exactly once or refused; where a disk
|
||||
makes no links a piece is moved into place when its name is free and a
|
||||
manifest is created exclusively under its number. Nothing in a destination is
|
||||
ever deleted or rewritten by the program: the only file it removes there is the
|
||||
scratch file it made a moment before. So a service that syncs the folder never
|
||||
sees a file change under it, and an earlier state of the books is always still
|
||||
there (the journal is the history: an earlier state is a shorter prefix, and
|
||||
each manifest marks one).
|
||||
*Enforced:* `ledger_store::backup::write_destination`,
|
||||
`ledger_store::backup::Destination`, `crates/ledger-store/src/backup/io.rs`.
|
||||
*Checked:* `ledger-store` `tests/backup.rs`
|
||||
(`a_backup_is_the_book_and_proves_whole`,
|
||||
`a_program_that_dies_at_any_write_leaves_what_proved_whole_before`),
|
||||
`tests/backup_props.rs` (`a_destination_only_grows`).
|
||||
|
||||
**WB-backup-2 A backup is whole when its manifest is in place, and a manifest
|
||||
names only pieces that exist and hash right.** The manifest is written last
|
||||
and atomically. It names the books' id, the head and sequence number it
|
||||
reaches, every segment, and the vault and key files, each by where it is, how
|
||||
long it is and what is in it (SHA-256); each manifest stands alone, so one
|
||||
that is lost, or replaced by a sync service's conflict copy, takes nothing
|
||||
else with it. A reader takes the newest manifest whose pieces are all there at
|
||||
the length it names, and the proof re-hashes every piece: the journal's chain
|
||||
replays, every stored file re-hashes, every TIN record the books name and the
|
||||
key that opens them are there, the head is the one recorded. A manifest that is
|
||||
cut short or changed is no manifest. A run that dies leaves pieces no manifest
|
||||
names, which are harmless.
|
||||
*Enforced:* `ledger_store::backup::find`, `ledger_store::backup::verify_found`,
|
||||
`ledger_store::backup::drill`.
|
||||
*Checked:* `ledger-store` `tests/backup.rs`
|
||||
(`a_flipped_or_cut_piece_is_found_and_never_restored`,
|
||||
`the_text_read_from_a_stored_file_is_a_stored_file_too`).
|
||||
|
||||
**WB-backup-3 A restore of any whole manifest yields books whose journal is
|
||||
byte-identical to a prefix of the source's.** A restore previews first and
|
||||
restores only the head it previewed, as new books or replacing books (which are
|
||||
moved whole into the legacy folder, never deleted). When the newest manifest is
|
||||
damaged the newest whole one is used and the preview says how many were passed
|
||||
over. The backup's journal is a byte prefix of the live one (a drill checks it).
|
||||
*Enforced:* `ledger_store::backup::verify_found`, `ledger_store::root::Root::restore`,
|
||||
`ledger_store::root::Root::restore_preview`.
|
||||
*Checked:* `ledger-store` `tests/backup_props.rs`
|
||||
(`any_whole_manifest_restores_a_prefix_of_the_books`),
|
||||
`tests/backup.rs` (`a_damaged_newest_backup_falls_back_to_the_one_before_and_says_so`);
|
||||
`ledger-cli` `tests/backups.rs` (`a_restore_is_of_the_backup_previewed_only`,
|
||||
`restore_never_overwrites_and_replacing_keeps_the_old_books`).
|
||||
|
||||
**WB-backup-4 A destination of other books, another history of these, or more
|
||||
than these books have is never written.** Before writing, the destination's
|
||||
newest whole manifest must be a point on the live journal: the bytes of the
|
||||
journal it names are the first bytes of the live one. Otherwise the destination
|
||||
holds other books or a different history, or a newer one than this computer has,
|
||||
and that is said, and nothing is written. A folder that took these books'
|
||||
backups and holds none now is a disk not connected, never made again where the
|
||||
disk should be unless the person says it is a new disk.
|
||||
*Enforced:* `ledger_store::backup::write_destination`,
|
||||
`ledger_store::backup::BackupError`.
|
||||
*Checked:* `ledger-store` `tests/backup.rs`
|
||||
(`a_destination_of_other_books_or_another_history_is_never_written`,
|
||||
`a_disk_that_is_gone_is_never_made_again_where_it_should_be`); `ledger-cli`
|
||||
`tests/backups.rs` (`a_backup_of_another_history_is_never_written_over`,
|
||||
`restored_books_never_make_their_backup_folder_again`).
|
||||
|
||||
**WB-backup-5 Two programs, or two computers, writing one destination cannot
|
||||
corrupt it, and a program that dies at any write leaves what proved whole
|
||||
before.** Pieces are named by what is in them, so two writers of one piece write
|
||||
the same bytes; the only decision is which writer takes the next manifest
|
||||
number, and the disk decides it (exclusive create). The loser looks again and
|
||||
goes on from what the winner wrote, or finds nothing left to write. A program
|
||||
that dies at any write point (a scratch file, a piece, the manifest) leaves a
|
||||
destination whose newest whole manifest is the one before, or the new one, and
|
||||
a restore from it is a prefix of the books. No lock a sync service ignores is
|
||||
relied on.
|
||||
*Enforced:* `ledger_store::backup::write_destination`,
|
||||
`crates/ledger-store/src/backup/write.rs`.
|
||||
*Checked:* `ledger-store` `tests/backup.rs`
|
||||
(`two_programs_writing_one_destination_do_not_corrupt_it`,
|
||||
`a_loser_of_a_manifest_number_goes_on_from_the_winner`,
|
||||
`a_program_that_dies_at_any_write_leaves_what_proved_whole_before`),
|
||||
`tests/backup_props.rs` (`random_interleavings_of_two_writers_leave_a_whole_backup`).
|
||||
|
||||
**WB-backup-6 A flipped or cut piece is found and never restored.** Every piece
|
||||
is checked against what its manifest says, in length and in hash, and a sealed
|
||||
piece against its seal; a piece that fails ends the proof of that manifest, and
|
||||
nothing is put in the books' place from it.
|
||||
*Enforced:* `ledger_store::backup::verify_found`.
|
||||
*Checked:* `ledger-store` `tests/backup_props.rs`
|
||||
(`any_flipped_or_cut_piece_is_found_never_restored`), `tests/backup.rs`
|
||||
(`a_flipped_or_cut_piece_is_found_and_never_restored`); `ledger-cli`
|
||||
`tests/backups.rs` (`restore_refuses_a_damaged_backup_and_writes_nothing`,
|
||||
`restore_drill_failure_is_flagged`).
|
||||
|
||||
**WB-backup-7 A passphrase seals every piece, and a wrong passphrase never
|
||||
yields books.** The passphrase is offered at set-up and is off by default
|
||||
(D-92). With one, every piece and every manifest is sealed with
|
||||
XChaCha20-Poly1305 in chunks of 1 MiB, each bound to what is in it and to
|
||||
whether it is the last. The key is derived from the passphrase with Argon2id at
|
||||
the owner passphrase's own cost (64 MiB, 3 passes, 1 lane) and a salt of its
|
||||
own, which the set's header records, so another computer derives the same key.
|
||||
File names are made from the key and say no more than counts and sizes. The
|
||||
header carries a sealed check, so a wrong passphrase is told from a damaged
|
||||
header. The derived key is kept on this computer only, in the book's own
|
||||
folder, readable by the person's account alone; never in a backup, never in the
|
||||
journal, never in a record or an error. Changing the passphrase starts a new set
|
||||
beside the old one and removing it makes the next backup plain: pieces already
|
||||
written are never rewritten, so the old ones stay as they were, sealed with the
|
||||
passphrase they were made with. A forgotten passphrase cannot be recovered, and
|
||||
the set-up says so.
|
||||
*Enforced:* `ledger_store::backup::BackupKey`,
|
||||
`crates/ledger-store/src/backup/seal.rs`.
|
||||
*Checked:* `ledger-store` `tests/backup.rs`
|
||||
(`a_sealed_backup_gives_away_counts_and_sizes_only`,
|
||||
`a_wrong_passphrase_never_yields_books_and_is_told_from_damage`,
|
||||
`a_changed_passphrase_is_a_new_set_beside_the_old_which_is_untouched`,
|
||||
`the_key_is_kept_privately_and_only_there`), `tests/backup_props.rs`
|
||||
(`a_wrong_passphrase_never_yields_books`).
|
||||
|
||||
**WB-backup-8 "Save a backup..." is the same backup as one file.** The file is a
|
||||
zip of the set's folder form holding one manifest and only the pieces it names,
|
||||
sealed when the backups are, with the extension .wbbackup. A file by the name
|
||||
asked for is never written over, and is moved into place only when whole.
|
||||
Restore reads a destination folder, a set's own folder, or this file.
|
||||
*Enforced:* `ledger_store::backup::save_file`, `ledger_store::backup::FILE_EXTENSION`.
|
||||
*Checked:* `ledger-store` `tests/backup.rs`
|
||||
(`a_single_file_holds_the_same_backup_plain_or_sealed`).
|
||||
|
||||
**WB-backup-9 A stopped backup leaves a destination that proves whole at its
|
||||
previous manifest, and a close is bounded.** A backup a close stops (the
|
||||
books' close, or a call or timer's backup when a close begins) looks for the
|
||||
stop between pieces and once per chunk of a file read, so it ends promptly and
|
||||
writes no manifest; the server records `stopped` and no result of the run's
|
||||
own, and the close's own last backup is stopped only at its bound.
|
||||
*Enforced:* `ledger_store::backup::Ctx`, `ledger_mcp::backup::Backups`.
|
||||
*Checked:* `ledger-store` `tests/backup.rs`
|
||||
(`a_stopped_backup_leaves_what_proved_whole_before`); `ledger-cli`
|
||||
`tests/book_open_close.rs`
|
||||
(`a_close_is_not_answered_while_its_backup_still_runs`,
|
||||
`a_close_stops_a_running_backup_call_and_says_so`).
|
||||
|
||||
**WB-backup-10 Older forms are left alone and said.** Books that still carry
|
||||
the old setting naming a private repository open and work; the backup status
|
||||
says in plain words that it is no longer used and to choose a folder. An older
|
||||
backup history in a book's own folder, and an older backup folder made with git
|
||||
beside a destination, are neither read, written, moved nor deleted; the new form
|
||||
goes beside them, and the status says once, until a backup has been made in the
|
||||
new form, that the older one is no longer written. A person who has an older
|
||||
backup clones it themselves and adopts the plain folder (docs/backups.md).
|
||||
*Enforced:* `ledger_mcp::backup::Backups`.
|
||||
*Checked:* `ledger-cli` `tests/backups.rs`
|
||||
(`old_settings_and_an_old_backup_history_are_left_alone_and_said`,
|
||||
`a_clone_of_an_old_git_backup_is_adopted_as_a_plain_folder`).
|
||||
|
||||
**WB-backup-11 A format upgrade needs a proven local backup, made under the
|
||||
store's lock.** The local backup is the same form in the book's own folder
|
||||
(`local-backup`), written and proven to hold the books exactly as they are
|
||||
(journal, vault and keys byte for byte, every stored file re-hashed) before
|
||||
the journal's format moves, all under the store's lock.
|
||||
*Enforced:* `ledger_store::backup::write_local`, `ledger_store::backup::prove_local`,
|
||||
`ledger_mcp::backup::Backups`.
|
||||
*Checked:* `ledger-mcp` `local.rs` (`format_upgrade_waits_for_consent`,
|
||||
`no_upgrade_unless_the_backup_is_proven`, `no_upgrade_without_a_backup`).
|
||||
@@ -185,8 +185,8 @@ consent; `tests/p2_compat.rs`). Only the owner's go-ahead moves them, with the
|
||||
owner passphrase (the server checks it, Argon2id): in the app, which asks at
|
||||
every open until it is given, or with `wanderbooks books upgrade ID` at a
|
||||
terminal, whose commands that open the books also ask; never an agent, and no
|
||||
tool. Before the upgrade the server commits the books to their own backup
|
||||
repository and proves the copy holds them exactly as they are (journal, stored
|
||||
tool. Before the upgrade the server writes the books to a local backup in their own
|
||||
folder (WB-backup-11) and proves it holds them exactly as they are (journal, stored
|
||||
files, vault and keys, byte for byte), all under the books' lock; a backup
|
||||
that can't be made or proven upgrades nothing. The upgrade is then one
|
||||
`journal.format_set` declaring the whole format, so a book's format moves
|
||||
@@ -195,8 +195,8 @@ copy is new books of this version and moves to its format as it is made (the
|
||||
original keeps its own). The upgrade never weakens the gate: books declaring a
|
||||
feature this version doesn't know are newer, as above.
|
||||
|
||||
*Enforced:* `ledger_store::format` (`current`, `JournalFormat::upgrade`), `Store::create`, `Store::upgrade_format`, `Root::adopt`, `ledger_store::backup::prove_archive`, ledger-mcp `Backups::upgrade_format` and `local.rs` (the passphrase), ledger-host `host.rs` (the lease intent, handed to the server) and `commands.rs` (`books upgrade`, asking at open), ledger-gui `owner.rs` (the notice and the dialog).
|
||||
*Checked:* `ledger-store` `tests/format_upgrade.rs` (new books in this version's format, a change waiting for the upgrade, every old-books fixture upgrading to its figures, a newer feature still refused), the unit tests in `format.rs` and `backup.rs` (`the_archive_proves_to_hold_the_book_as_it_is_keys_and_all`), `tests/root.rs` (adoption); `ledger-mcp` `local.rs` (`format_upgrade_waits_for_consent`, `no_upgrade_without_a_backup`, `no_upgrade_unless_the_backup_just_made_is_proven`); `ledger-host` `lease.rs` (`a_consent_never_shows_its_passphrase`); `ledger-cli` `tests/format_upgrade.rs` (from end to end); `ledger-gui` `tests/format_upgrade.rs`.
|
||||
*Enforced:* `ledger_store::format` (`current`, `JournalFormat::upgrade`), `Store::create`, `Store::upgrade_format`, `Root::adopt`, `ledger_store::backup::prove_local`, ledger-mcp `Backups::upgrade_format` and `local.rs` (the passphrase), ledger-host `host.rs` (the lease intent, handed to the server) and `commands.rs` (`books upgrade`, asking at open), ledger-gui `owner.rs` (the notice and the dialog).
|
||||
*Checked:* `ledger-store` `tests/format_upgrade.rs` (new books in this version's format, a change waiting for the upgrade, every old-books fixture upgrading to its figures, a newer feature still refused), the unit tests in `format.rs`, `tests/root.rs` (adoption); `ledger-mcp` `local.rs` (`format_upgrade_waits_for_consent`, `no_upgrade_without_a_backup`, `no_upgrade_unless_the_backup_is_proven`); `ledger-host` `lease.rs` (`a_consent_never_shows_its_passphrase`); `ledger-cli` `tests/format_upgrade.rs` (from end to end); `ledger-gui` `tests/format_upgrade.rs`.
|
||||
|
||||
**WB-format-4 Each projection schema in a file of its own.** (The lead's
|
||||
decision, 2026-10-21, for 3.9's "before consent, the way back is always
|
||||
|
||||
Reference in new issue
Block a user