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:
1 parent
51a7607a82
commit
83a32aec14
3 files changed
+55
-42
No files matched your search
@@ -408,15 +408,21 @@ fn format_lines(dir: &Path) -> usize {
|
||||
.count()
|
||||
}
|
||||
|
||||
/// git, on the books' own backup repository: what it said.
|
||||
fn archive_git(dir: &Path, args: &[&str]) -> String {
|
||||
let out = Command::new("git")
|
||||
.arg(format!("--git-dir={}", dir.join("archive.git").display()))
|
||||
.args(args)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(out.status.success(), "{out:?}");
|
||||
String::from_utf8(out.stdout).unwrap()
|
||||
/// The books' own local backup, proven whole and built in a scratch folder:
|
||||
/// the books as they were backed up.
|
||||
fn local_backup(dir: &Path) -> PathBuf {
|
||||
use ledger_store::backup::{Ctx, find, verify_found};
|
||||
let scratch = dir.join("scratch-local-backup");
|
||||
let _ = std::fs::remove_dir_all(&scratch);
|
||||
let found = find(
|
||||
&dir.join(ledger_store::backup::LOCAL_DIR),
|
||||
None,
|
||||
&Ctx::new(),
|
||||
)
|
||||
.expect("a local backup is there");
|
||||
verify_found(&found, &scratch, &Ctx::new())
|
||||
.expect("it proves whole")
|
||||
.tree
|
||||
}
|
||||
|
||||
fn a_setting() -> Value {
|
||||
@@ -585,17 +591,14 @@ fn format_upgrade_waits_for_consent() {
|
||||
let after = journal(&dir);
|
||||
assert!(after.starts_with(&before));
|
||||
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!(
|
||||
archive_git(&dir, &["show", &format!("{}:journal.jsonl", backup.trim())]).as_bytes(),
|
||||
std::fs::read(backup.join("journal.jsonl")).unwrap(),
|
||||
before.as_slice(),
|
||||
"the backup holds the books as they were"
|
||||
);
|
||||
assert_eq!(
|
||||
archive_git(
|
||||
&dir,
|
||||
&["show", &format!("{}:keys/legacy.key", backup.trim())]
|
||||
),
|
||||
std::fs::read_to_string(backup.join("keys").join("legacy.key")).unwrap(),
|
||||
"ab".repeat(32),
|
||||
"and their key"
|
||||
);
|
||||
@@ -801,19 +804,18 @@ fn books_p2_served_cut_over_whole() {
|
||||
2,
|
||||
"P2's declaration, then the upgrade's"
|
||||
);
|
||||
let backup = archive_git(&dir, &["rev-parse", "HEAD"]);
|
||||
let backup = local_backup(&dir);
|
||||
assert_eq!(
|
||||
archive_git(&dir, &["show", &format!("{}:journal.jsonl", backup.trim())]).as_bytes(),
|
||||
std::fs::read(backup.join("journal.jsonl")).unwrap(),
|
||||
waiting.as_slice(),
|
||||
"the backup holds the books as they were"
|
||||
);
|
||||
for kept in ["keys/legacy.key", "vault/tin-1.bin", "vault/tin-3.bin"] {
|
||||
let out = Command::new("git")
|
||||
.arg(format!("--git-dir={}", dir.join("archive.git").display()))
|
||||
.args(["show", &format!("{}:{kept}", backup.trim())])
|
||||
.output()
|
||||
.unwrap();
|
||||
assert_eq!(out.stdout, std::fs::read(dir.join(kept)).unwrap(), "{kept}");
|
||||
assert_eq!(
|
||||
std::fs::read(backup.join(kept)).unwrap(),
|
||||
std::fs::read(dir.join(kept)).unwrap(),
|
||||
"{kept}"
|
||||
);
|
||||
}
|
||||
assert_eq!(figures(&mut a), before, "the upgrade moves no figure");
|
||||
|
||||
|
||||
@@ -2655,6 +2655,20 @@ fn the_commands_given_run_as_the_agents_own_token() {
|
||||
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]
|
||||
fn a_backup_is_restored_from_the_command_line() {
|
||||
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}");
|
||||
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();
|
||||
// Previewed, and not done without a yes.
|
||||
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"),
|
||||
"{out:?}"
|
||||
);
|
||||
// A repository named otherwise: restored as the books it holds, by
|
||||
// default (here: over those, refused), said.
|
||||
let renamed = home.dir.path().join("disk").join("fernhill-backup.git");
|
||||
let out = Command::new("git")
|
||||
.args(["clone", "-q", "--bare"])
|
||||
.arg(backup)
|
||||
.arg(&renamed)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(out.status.success(), "{out:?}");
|
||||
// A folder named otherwise: restored as the books it holds, by default
|
||||
// (here: over those, refused), said.
|
||||
let renamed = home.dir.path().join("fernhill-backup");
|
||||
copy_folder(&disk.join("acme"), &renamed);
|
||||
let out = home.books(&["restore", renamed.to_str().unwrap(), "--yes"]);
|
||||
assert!(
|
||||
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\""),
|
||||
"{out:?}"
|
||||
);
|
||||
assert!(said.contains("--id acme"), "{out:?}");
|
||||
// A repository whose name is no id: still restored as its books.
|
||||
let odd = home.dir.path().join("disk").join("Fernhill_Backup.git");
|
||||
assert!(
|
||||
said.contains("They were backed up as \"acme\"; they come back as \"other\""),
|
||||
"{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();
|
||||
let out = home.books(&["restore", odd.to_str().unwrap(), "--yes"]);
|
||||
assert!(
|
||||
@@ -2738,7 +2749,7 @@ fn a_backup_is_restored_from_the_command_line() {
|
||||
String::from_utf8_lossy(&out.stdout).contains("Restored as \"copy\""),
|
||||
"{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).
|
||||
post_one(&mut a, 2).unwrap();
|
||||
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"),
|
||||
"{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.
|
||||
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"]);
|
||||
assert_eq!(out.status.code(), Some(1), "{out:?}");
|
||||
assert!(
|
||||
@@ -2925,7 +2936,7 @@ fn books_are_backed_up_now_from_the_command_line() {
|
||||
);
|
||||
let out = home.books(&["back-up", "acme", "--new-disk"]);
|
||||
assert!(out.status.success(), "{out:?}");
|
||||
assert!(disk.join("acme.git").join("HEAD").is_file());
|
||||
assert!(disk.join("acme").join("manifests").is_dir());
|
||||
a.end();
|
||||
}
|
||||
|
||||
|
||||
@@ -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> {
|
||||
if targets.is_empty() {
|
||||
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
|
||||
|
||||
Reference in new issue
Block a user