test(cli): the command-line and upgrade tests on the new form

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-21 18:24:48 -07:00
1 parent 51a7607a82
commit 83a32aec14
3 files changed
+55 -42

No files matched your search

+25 -23
View File
@@ -408,15 +408,21 @@ fn format_lines(dir: &Path) -> usize {
.count() .count()
} }
/// git, on the books' own backup repository: what it said. /// The books' own local backup, proven whole and built in a scratch folder:
fn archive_git(dir: &Path, args: &[&str]) -> String { /// the books as they were backed up.
let out = Command::new("git") fn local_backup(dir: &Path) -> PathBuf {
.arg(format!("--git-dir={}", dir.join("archive.git").display())) use ledger_store::backup::{Ctx, find, verify_found};
.args(args) let scratch = dir.join("scratch-local-backup");
.output() let _ = std::fs::remove_dir_all(&scratch);
.unwrap(); let found = find(
assert!(out.status.success(), "{out:?}"); &dir.join(ledger_store::backup::LOCAL_DIR),
String::from_utf8(out.stdout).unwrap() None,
&Ctx::new(),
)
.expect("a local backup is there");
verify_found(&found, &scratch, &Ctx::new())
.expect("it proves whole")
.tree
} }
fn a_setting() -> Value { fn a_setting() -> Value {
@@ -585,17 +591,14 @@ fn format_upgrade_waits_for_consent() {
let after = journal(&dir); let after = journal(&dir);
assert!(after.starts_with(&before)); assert!(after.starts_with(&before));
assert_eq!(format_lines(&dir), 1, "the format moved once"); assert_eq!(format_lines(&dir), 1, "the format moved once");
let backup = archive_git(&dir, &["rev-parse", "HEAD"]); let backup = local_backup(&dir);
assert_eq!( assert_eq!(
archive_git(&dir, &["show", &format!("{}:journal.jsonl", backup.trim())]).as_bytes(), std::fs::read(backup.join("journal.jsonl")).unwrap(),
before.as_slice(), before.as_slice(),
"the backup holds the books as they were" "the backup holds the books as they were"
); );
assert_eq!( assert_eq!(
archive_git( std::fs::read_to_string(backup.join("keys").join("legacy.key")).unwrap(),
&dir,
&["show", &format!("{}:keys/legacy.key", backup.trim())]
),
"ab".repeat(32), "ab".repeat(32),
"and their key" "and their key"
); );
@@ -801,19 +804,18 @@ fn books_p2_served_cut_over_whole() {
2, 2,
"P2's declaration, then the upgrade's" "P2's declaration, then the upgrade's"
); );
let backup = archive_git(&dir, &["rev-parse", "HEAD"]); let backup = local_backup(&dir);
assert_eq!( assert_eq!(
archive_git(&dir, &["show", &format!("{}:journal.jsonl", backup.trim())]).as_bytes(), std::fs::read(backup.join("journal.jsonl")).unwrap(),
waiting.as_slice(), waiting.as_slice(),
"the backup holds the books as they were" "the backup holds the books as they were"
); );
for kept in ["keys/legacy.key", "vault/tin-1.bin", "vault/tin-3.bin"] { for kept in ["keys/legacy.key", "vault/tin-1.bin", "vault/tin-3.bin"] {
let out = Command::new("git") assert_eq!(
.arg(format!("--git-dir={}", dir.join("archive.git").display())) std::fs::read(backup.join(kept)).unwrap(),
.args(["show", &format!("{}:{kept}", backup.trim())]) std::fs::read(dir.join(kept)).unwrap(),
.output() "{kept}"
.unwrap(); );
assert_eq!(out.stdout, std::fs::read(dir.join(kept)).unwrap(), "{kept}");
} }
assert_eq!(figures(&mut a), before, "the upgrade moves no figure"); assert_eq!(figures(&mut a), before, "the upgrade moves no figure");
+29 -18
View File
@@ -2655,6 +2655,20 @@ fn the_commands_given_run_as_the_agents_own_token() {
a.end(); a.end();
} }
/// A copy of a folder and everything in it.
fn copy_folder(from: &std::path::Path, to: &std::path::Path) {
std::fs::create_dir_all(to).unwrap();
for e in std::fs::read_dir(from).unwrap() {
let e = e.unwrap();
let target = to.join(e.file_name());
if e.path().is_dir() {
copy_folder(&e.path(), &target);
} else {
std::fs::copy(e.path(), target).unwrap();
}
}
}
#[test] #[test]
fn a_backup_is_restored_from_the_command_line() { fn a_backup_is_restored_from_the_command_line() {
let home = Home::new("restore"); let home = Home::new("restore");
@@ -2683,7 +2697,7 @@ fn a_backup_is_restored_from_the_command_line() {
); );
assert_eq!(s["targets"][0]["last_error"], Value::Null, "{s}"); assert_eq!(s["targets"][0]["last_error"], Value::Null, "{s}");
let head = s["head_seq"].as_u64().unwrap(); let head = s["head_seq"].as_u64().unwrap();
let backup = disk.join("acme.git"); let backup = disk.join("acme");
let backup = backup.to_str().unwrap(); let backup = backup.to_str().unwrap();
// Previewed, and not done without a yes. // Previewed, and not done without a yes.
let out = home.books(&["restore", backup, "--id", "copy"]); let out = home.books(&["restore", backup, "--id", "copy"]);
@@ -2700,16 +2714,10 @@ fn a_backup_is_restored_from_the_command_line() {
String::from_utf8_lossy(&out.stderr).contains("already books called"), String::from_utf8_lossy(&out.stderr).contains("already books called"),
"{out:?}" "{out:?}"
); );
// A repository named otherwise: restored as the books it holds, by // A folder named otherwise: restored as the books it holds, by default
// default (here: over those, refused), said. // (here: over those, refused), said.
let renamed = home.dir.path().join("disk").join("fernhill-backup.git"); let renamed = home.dir.path().join("fernhill-backup");
let out = Command::new("git") copy_folder(&disk.join("acme"), &renamed);
.args(["clone", "-q", "--bare"])
.arg(backup)
.arg(&renamed)
.output()
.unwrap();
assert!(out.status.success(), "{out:?}");
let out = home.books(&["restore", renamed.to_str().unwrap(), "--yes"]); let out = home.books(&["restore", renamed.to_str().unwrap(), "--yes"]);
assert!( assert!(
String::from_utf8_lossy(&out.stderr).contains("already books called \"acme\""), String::from_utf8_lossy(&out.stderr).contains("already books called \"acme\""),
@@ -2721,9 +2729,12 @@ fn a_backup_is_restored_from_the_command_line() {
said.contains("It is a backup of the books \"acme\""), said.contains("It is a backup of the books \"acme\""),
"{out:?}" "{out:?}"
); );
assert!(said.contains("--id acme"), "{out:?}"); assert!(
// A repository whose name is no id: still restored as its books. said.contains("They were backed up as \"acme\"; they come back as \"other\""),
let odd = home.dir.path().join("disk").join("Fernhill_Backup.git"); "{out:?}"
);
// A folder whose name is no id: still restored as its books.
let odd = home.dir.path().join("Fernhill_Backup");
std::fs::rename(&renamed, &odd).unwrap(); std::fs::rename(&renamed, &odd).unwrap();
let out = home.books(&["restore", odd.to_str().unwrap(), "--yes"]); let out = home.books(&["restore", odd.to_str().unwrap(), "--yes"]);
assert!( assert!(
@@ -2738,7 +2749,7 @@ fn a_backup_is_restored_from_the_command_line() {
String::from_utf8_lossy(&out.stdout).contains("Restored as \"copy\""), String::from_utf8_lossy(&out.stdout).contains("Restored as \"copy\""),
"{out:?}" "{out:?}"
); );
// Replacing them, the old kept: from the repository named otherwise, // Replacing them, the old kept: from the folder named otherwise,
// given no id (the books it holds are replaced). // given no id (the books it holds are replaced).
post_one(&mut a, 2).unwrap(); post_one(&mut a, 2).unwrap();
let out = home.books(&["restore", renamed.to_str().unwrap(), "--replace", "--yes"]); let out = home.books(&["restore", renamed.to_str().unwrap(), "--replace", "--yes"]);
@@ -2914,9 +2925,9 @@ fn books_are_backed_up_now_from_the_command_line() {
String::from_utf8_lossy(&out.stdout).contains("Backed up to the backup folder"), String::from_utf8_lossy(&out.stdout).contains("Backed up to the backup folder"),
"{out:?}" "{out:?}"
); );
assert!(disk.join("acme.git").join("HEAD").is_file()); assert!(disk.join("acme").join("manifests").is_dir());
// A folder gone since: said, and --new-disk begins it again. // A folder gone since: said, and --new-disk begins it again.
std::fs::rename(disk.join("acme.git"), home.dir.path().join("away.git")).unwrap(); std::fs::rename(disk.join("acme"), home.dir.path().join("away")).unwrap();
let out = home.books(&["back-up", "acme"]); let out = home.books(&["back-up", "acme"]);
assert_eq!(out.status.code(), Some(1), "{out:?}"); assert_eq!(out.status.code(), Some(1), "{out:?}");
assert!( assert!(
@@ -2925,7 +2936,7 @@ fn books_are_backed_up_now_from_the_command_line() {
); );
let out = home.books(&["back-up", "acme", "--new-disk"]); let out = home.books(&["back-up", "acme", "--new-disk"]);
assert!(out.status.success(), "{out:?}"); assert!(out.status.success(), "{out:?}");
assert!(disk.join("acme.git").join("HEAD").is_file()); assert!(disk.join("acme").join("manifests").is_dir());
a.end(); a.end();
} }
+1 -1
View File
@@ -1819,7 +1819,7 @@ const CONNECT_WAIT: Duration = Duration::from_secs(60);
pub fn backed_up_lines(head_seq: u64, targets: &[admin::BackedUpTarget]) -> Vec<String> { pub fn backed_up_lines(head_seq: u64, targets: &[admin::BackedUpTarget]) -> Vec<String> {
if targets.is_empty() { if targets.is_empty() {
return vec![ return vec![
"No backups are set up: ask your agent to set the private repository and the backup folder.".into(), "No backups are set up: choose a backup folder, in the window or with `wanderbooks books backup-setup ID --folder FOLDER`.".into(),
]; ];
} }
targets targets