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

+30 -2
View File
@@ -147,6 +147,14 @@ pub enum Request {
#[serde(default)]
new_disk: bool,
},
/// Begin a new backup set beside the old one in the backup folder, and
/// back the books up to it (the books are behind the folder's: as
/// after a restore from an older backup): only at the person's
/// request; the old set is never touched.
BackUpNewSet {
/// The books.
id: String,
},
/// Set up a book's backups (D-91, D-92): the folder, and the
/// passphrase.
BackupSetup {
@@ -696,9 +704,16 @@ pub struct RestorePreview {
/// Whether it is protected by a passphrase.
#[serde(default)]
pub sealed: bool,
/// Newer backups in it that were not whole and were passed over.
/// Newer backups in it that were not whole or were damaged and were
/// passed over: not zero means this is not the newest backup there is.
#[serde(default)]
pub passed_over: u64,
/// When this backup was made (UTC), as its manifest says.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub written: Option<String>,
/// When the newest backup there is was made (UTC), if it can be read.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub newest_written: Option<String>,
}
/// What a restore did.
@@ -770,6 +785,17 @@ pub struct BackupStanding {
/// What to know or do: none set up, an older kind no longer used.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub note: Option<String>,
/// What kind of trouble the last backup or check had (`ahead`,
/// `elsewhere`, `key_missing`, `not_downloaded`, `newest_damaged`).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub error_kind: Option<String>,
/// Files in the backup folder found damaged and written again; each is
/// left where it is.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub damaged_files: Vec<String>,
/// What to tell a person of a folder a sync service keeps (or may).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub sync: Option<String>,
}
/// The server's answer.
@@ -947,7 +973,7 @@ pub fn call_within(
Request::Create { .. } | Request::Adopt { .. } | Request::Restore { .. } => {
Some("`wanderbooks books list` shows the books there are")
}
Request::BackUpNow { .. } => {
Request::BackUpNow { .. } | Request::BackUpNewSet { .. } => {
Some("`wanderbooks books back-up` again backs up whatever it didn't")
}
Request::TokenCreate { .. } | Request::TokenRevoke { .. } => {
@@ -1162,6 +1188,8 @@ mod tests {
origin: Some("acme".into()),
sealed: false,
passed_over: 0,
written: None,
newest_written: None,
}),
Response::Restored(Restored {
id: "acme".into(),
+22 -7
View File
@@ -317,21 +317,36 @@ pub const OLD_ARCHIVE: &str = "An older backup folder from an earlier version is
/// push that was made sealed or plain), with the key's fingerprint, which
/// opens nothing.
fn sealed_before(records: &[Map<String, Value>]) -> Option<(bool, Option<String>)> {
records.iter().rev().find_map(|r| {
let says = |r: &Map<String, Value>| -> Option<bool> {
if is(r, "setup") {
match r.get("passphrase").and_then(Value::as_str) {
Some("set") => Some((true, text(r, "fp"))),
Some("removed") => Some((false, None)),
Some("set") => Some(true),
Some("removed") => Some(false),
_ => None,
}
} else if is(r, "push") {
r.get("sealed")
.and_then(Value::as_bool)
.map(|sealed| (sealed, text(r, "fp")))
r.get("sealed").and_then(Value::as_bool)
} else {
None
}
})
};
let (at, sealed) = records
.iter()
.enumerate()
.rev()
.find_map(|(i, r)| says(r).map(|s| (i, s)))?;
// The fingerprint of the key the backups were sealed with: the newest
// record that was made with one (a push that couldn't be made says
// none).
let fp = sealed
.then(|| {
records[..=at]
.iter()
.rev()
.find_map(|r| says(r).filter(|s| *s).and_then(|_| text(r, "fp")))
})
.flatten();
Some((sealed, fp))
}
/// The records of a book's backup log, if it can be read.
+43 -36
View File
@@ -1614,42 +1614,8 @@ impl Books {
Err(why) => Response::Refused(self.hide(why)),
}
}
Request::BackUpNow { id, new_disk } => {
let id = match BookId::parse(&id) {
Ok(id) => id,
Err(e) => return refused(e),
};
let backups = match self.held().get(id.as_str()) {
Some(Book::Open { backups, .. }) => backups.clone(),
Some(Book::Failed(why)) => {
return Response::Refused(format!("those books didn't open: {why}"));
}
Some(Book::Closed) => return Response::Refused(self.not_open(&id)),
None => {
return Response::Refused(format!(
"there are no books called {:?}",
id.as_str()
));
}
};
let rt = tokio::runtime::Handle::current();
match rt.block_on(backups.run_with("asked", new_disk)) {
Ok(status) => Response::BackedUp {
head_seq: status.head_seq,
targets: status
.targets
.into_iter()
.map(|t| admin::BackedUpTarget {
target: t.target,
at: t.at,
through_seq: t.through_seq,
problem: t.last_error,
})
.collect(),
},
Err(why) => Response::Refused(self.hide(why)),
}
}
Request::BackUpNewSet { id } => self.back_up_response(&id, false, true),
Request::BackUpNow { id, new_disk } => self.back_up_response(&id, new_disk, false),
Request::BackupSetup {
id,
folder,
@@ -1685,6 +1651,9 @@ impl Books {
drill_error: t.and_then(|t| t.drill_error.clone()),
disconnected: t.is_some_and(|t| t.disconnected),
note: s.status.note,
error_kind: t.and_then(|t| t.error_kind.clone()),
damaged_files: t.map(|t| t.damaged_files.clone()).unwrap_or_default(),
sync: s.sync,
})
}
Err(r) => *r,
@@ -2225,6 +2194,42 @@ impl Books {
/// The backups of the open book `id`, or the refusal to give a request
/// that needs them.
/// Back the books `id` up now (`new_disk`: their disk is new; `new_set`:
/// begin a new set beside the old one), what came of it.
fn back_up_response(&self, id: &str, new_disk: bool, new_set: bool) -> Response {
let id = match BookId::parse(id) {
Ok(id) => id,
Err(e) => return Response::Refused(e.to_string()),
};
let backups = match self.held().get(id.as_str()) {
Some(Book::Open { backups, .. }) => backups.clone(),
Some(Book::Failed(why)) => {
return Response::Refused(format!("those books didn't open: {why}"));
}
Some(Book::Closed) => return Response::Refused(self.not_open(&id)),
None => {
return Response::Refused(format!("there are no books called {:?}", id.as_str()));
}
};
let rt = tokio::runtime::Handle::current();
match rt.block_on(backups.run_with_set("asked", new_disk, new_set)) {
Ok(status) => Response::BackedUp {
head_seq: status.head_seq,
targets: status
.targets
.into_iter()
.map(|t| admin::BackedUpTarget {
target: t.target,
at: t.at,
through_seq: t.through_seq,
problem: t.last_error,
})
.collect(),
},
Err(why) => Response::Refused(self.hide(why)),
}
}
fn backups_of(&self, id: &str) -> Result<Arc<crate::backup::Backups>, Box<Response>> {
let refused = |text: String| Box::new(Response::Refused(self.hide(text)));
let id = BookId::parse(id).map_err(|e| refused(e.to_string()))?;
@@ -2287,6 +2292,8 @@ impl Books {
origin: p.origin,
sealed: p.sealed,
passed_over: p.passed_over,
written: p.written,
newest_written: p.newest_written,
}),
Err(e) => said(e.to_string()),
};
+24 -2
View File
@@ -25,6 +25,12 @@ pub struct BackUpNowParams {
/// should hold one is otherwise a disk not connected.
#[serde(default)]
pub new_disk: bool,
/// The backup folder holds a longer history of these books than they
/// have now (a restore from an older backup): begin a new backup set
/// beside the old one, which is never touched. Only when the human
/// says so.
#[serde(default)]
pub new_set: bool,
}
#[derive(Debug, Serialize, JsonSchema)]
@@ -39,6 +45,16 @@ pub struct TargetOut {
pub through_seq: Option<u64>,
/// More than a day without the books' latest: tell the human.
pub stale: bool,
/// What kind of trouble the last backup or check had: `ahead` (the
/// folder holds a longer history of these books: offer new_set),
/// `elsewhere` (other or diverged books), `key_missing` (the backups
/// are sealed and this computer lost the key: ask the human for the
/// passphrase), `not_downloaded` (files a sync service has not put here
/// yet), `newest_damaged` (a restore would give older books).
pub error_kind: Option<String>,
/// Files in the backup folder found damaged and written again (each is
/// left where it is): tell the human.
pub damaged_files: Vec<String>,
/// Why its last backup failed, if it did.
pub last_error: Option<String>,
/// When its backup was last proven restorable (UTC), if ever: each
@@ -76,6 +92,8 @@ impl From<crate::backup::Status> for BackupOut {
last_ok_at: t.last_ok_at,
through_seq: t.through_seq,
stale: t.stale,
error_kind: t.error_kind,
damaged_files: t.damaged_files,
last_error: t.last_error,
last_drill_at: t.last_drill_at,
drill_error: t.drill_error,
@@ -102,7 +120,7 @@ impl BooksServer {
#[tool(
name = "books.back_up_now",
title = "Back up now",
description = "Back the books up now to the backup folder the settings name, and answer how it went (as books.backup). new_disk: true only when the human says the backup folder's disk is new: the books' backup is then begun there again. Needs books:admin.",
description = "Back the books up now to the backup folder the settings name, and answer how it went (as books.backup). new_disk: true only when the human says the backup folder's disk is new: the books' backup is then begun there again. new_set: true only when the human says so after a backup failed because the folder holds a longer history of these books (error_kind ahead): a new set begins beside the old one. Needs books:admin.",
annotations(
read_only_hint = false,
destructive_hint = false,
@@ -116,7 +134,11 @@ impl BooksServer {
) -> Result<Json<BackupOut>, String> {
// Stopped by a close (backup.rs INVARIANT 11): said so, and on
// record as stopped, not as an answer it gave.
match self.backups.run_with("asked", params.0.new_disk).await {
match self
.backups
.run_with_set("asked", params.0.new_disk, params.0.new_set)
.await
{
Ok(status) => Ok(Json(status.into())),
Err(why) if why.starts_with(crate::server::STOPPED_BY_CLOSE_WORDS) => {
crate::server::stopped_by_close();