0.1.4: settings decide where a vault shares; leaving always finishes
- A folder found sharing somewhere other than its settings say is set back (every 30 s, under the vault's op lock). Two programs racing — the 0.1.1 CLI upload against the 0.1.2 app's check-in — had left Brain's settings on the hub and its folder on Gitea, so it kept "syncing" to the wrong place. - Leaving hands over to the vault's own hub, never to wherever the folder points. If the hub refuses the history (an older entry has a possible secret), the device hands over its current notes as one entry with those lines replaced, instead of retrying forever with the folder read-only. - The app says "leaving" while that's in progress instead of "Synced". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -689,3 +689,58 @@ fn a_vault_moves_onto_the_hub_only_once_it_is_detached() {
|
||||
assert_eq!(std::fs::read(o.root.join("idea.md")).unwrap(), b"second\n");
|
||||
assert_eq!(std::fs::read(o.root.join("later.md")).unwrap(), b"kept here\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leaving_finishes_even_when_the_folder_points_elsewhere_and_history_has_a_secret() {
|
||||
let _turn = SERIAL.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let tmp = tempfile::TempDir::new().unwrap();
|
||||
let data = tmp.path().join("data");
|
||||
let (_hub, url, owner_link) = start_hub(&data);
|
||||
let (_, sen_w) = hub::join(&owner_link, "Mac").unwrap();
|
||||
let mut mac = device(&url, &sen_w, "Mac", &tmp.path().join("mac"));
|
||||
mac.use_hub_credentials();
|
||||
let ops = mac.hubs[0].create_vault("Ops").unwrap();
|
||||
check_in(&mut mac);
|
||||
let v = open(&mac, "Ops");
|
||||
write_and_save(&v, "plan.md", "shared\n");
|
||||
v.sync().unwrap();
|
||||
|
||||
// A line this device was told isn't a secret, which the hub never heard: it can't be shared.
|
||||
std::fs::write(v.root.join("aws.md"), "aws_access_key_id = AKIAIOSFODNN7EXAMPLE\n").unwrap();
|
||||
let hit = v.secret_holds().unwrap()[0].hits[0].clone();
|
||||
secrets::allow(&v.git_dir, &hit, "aws.md").unwrap();
|
||||
v.save_changes(None, &HashSet::new()).unwrap();
|
||||
assert!(v.sync().is_err());
|
||||
// And the folder was left pointing somewhere else (another program changed it), while the settings say the hub.
|
||||
let elsewhere = tmp.path().join("elsewhere.git");
|
||||
lune_core::git2::Repository::init_bare(&elsewhere).unwrap();
|
||||
v.relink(&format!("file://{}", elsewhere.display())).unwrap();
|
||||
drop(v);
|
||||
|
||||
// Deleting the vault: the device still finishes leaving, handing over to the hub, the key line replaced.
|
||||
mac.use_hub_credentials();
|
||||
mac.hubs[0].delete_vault("Ops").unwrap();
|
||||
let said = check_in(&mut mac);
|
||||
assert!(mac.vaults.is_empty(), "{said:?}");
|
||||
let repo = lune_core::git2::Repository::open_bare(data.join(format!("repos/{}.git", ops.id))).unwrap();
|
||||
let handover = repo.references_glob("refs/handover/*").unwrap().next().unwrap().unwrap().peel_to_commit().unwrap();
|
||||
let blob = |name: &str| handover.tree().unwrap().get_name(name).unwrap().to_object(&repo).unwrap().peel_to_blob().unwrap().content().to_vec();
|
||||
let aws = String::from_utf8(blob("aws.md")).unwrap();
|
||||
assert!(!aws.contains("AKIA") && aws.contains("secret removed"), "{aws}");
|
||||
assert_eq!(blob("plan.md"), b"shared\n");
|
||||
assert!(lune_core::git2::Repository::open_bare(&elsewhere).unwrap().references().unwrap().count() == 0, "nothing went elsewhere");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_folder_follows_its_settings() {
|
||||
let tmp = tempfile::TempDir::new().unwrap();
|
||||
let a = tmp.path().join("a.git");
|
||||
lune_core::git2::Repository::init_bare(&a).unwrap();
|
||||
let (cfg, _, _) = vault::add("Notes", &tmp.path().join("notes"), &format!("file://{}", a.display()), "Mac").unwrap();
|
||||
let v = Vault::open(&cfg, "Mac").unwrap();
|
||||
assert!(!v.follow(&cfg.remote).unwrap());
|
||||
v.relink("file:///somewhere/else.git").unwrap();
|
||||
assert!(v.follow(&cfg.remote).unwrap());
|
||||
assert_eq!(v.remote_url().as_deref(), Some(cfg.remote.as_str()));
|
||||
assert!(v.follow("").unwrap() && v.is_local());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user