0.1.3: upload a vault to a team from the app, detach first; AGPL-3.0
- The Lune window shows Upload on a vault that isn't on a team, for the team owner and anyone who manages a vault there. The hub now lets those people create vaults too (was owner only); /api/me and the canvas say can_create. - A vault on its own remote (GitHub, GitLab, Gitea…) must be detached first (`lunesync vault detach`, or the Upload sheet's Detach): it shares what's waiting one last time, then lives on this device only. Upload refuses anything else, and a check-in no longer silently moves a same-named vault off its own remote onto the hub. - Upload logic moved from the CLI into core (lune_core::upload). - Canvas: "1 person loses access". - License: AGPL-3.0-only. README and SPEC §8 updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -621,3 +621,71 @@ fn deleting_a_vault_and_leaving_a_team() {
|
||||
lune_core::membership::leave_hub(&mut stale, "http://127.0.0.1:9", true).unwrap();
|
||||
assert!(stale.hubs.is_empty() && stale.vaults.is_empty() && kept.exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_vault_moves_onto_the_hub_only_once_it_is_detached() {
|
||||
let _turn = SERIAL.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let tmp = tempfile::TempDir::new().unwrap();
|
||||
let (_hub, url, owner_link) = start_hub(&tmp.path().join("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 sen = mac.hubs[0].clone();
|
||||
sen.create_vault("Team").unwrap();
|
||||
|
||||
// Creating vaults: the owner, and people who manage a vault; not people who only edit.
|
||||
let (_, ed_w) = hub::join(&sen.invite("Ed", &[("Team".into(), "edit".into())]).unwrap(), "Ed pc").unwrap();
|
||||
let ed = as_device(&url, &ed_w);
|
||||
assert!(!ed.me().unwrap().can_create);
|
||||
assert!(ed.create_vault("Eds").is_err());
|
||||
as_device(&url, &sen_w);
|
||||
sen.grant("Ed", "Team", "manage").unwrap();
|
||||
let ed = as_device(&url, &ed_w);
|
||||
assert!(ed.me().unwrap().can_create);
|
||||
assert_eq!(ed.create_vault("Eds").unwrap().role, "manage");
|
||||
|
||||
// A vault on its own remote (a stand-in for GitLab), with history.
|
||||
let gitlab = tmp.path().join("gitlab.git");
|
||||
lune_core::git2::Repository::init_bare(&gitlab).unwrap();
|
||||
let remote_url = format!("file://{}", gitlab.display());
|
||||
let (cfg, _, err) = vault::add("Brain", &tmp.path().join("mac/Brain"), &remote_url, "Mac").unwrap();
|
||||
assert_eq!(err, None);
|
||||
mac.vaults.push(cfg);
|
||||
let v = open(&mac, "Brain");
|
||||
write_and_save(&v, "idea.md", "first\n");
|
||||
v.sync().unwrap();
|
||||
write_and_save(&v, "idea.md", "second\n");
|
||||
drop(v);
|
||||
|
||||
// Not uploaded while it still syncs elsewhere, and a check-in doesn't move it either.
|
||||
let sen = as_device(&url, &sen_w);
|
||||
let err = lune_core::upload::upload(&mut mac, &sen, "Brain", false).unwrap_err().to_string();
|
||||
assert!(err.contains("Detach it"), "{err}");
|
||||
sen.create_vault("Brain").unwrap();
|
||||
check_in(&mut mac);
|
||||
assert!(mac.find("Brain").unwrap().hub_vault.is_none(), "a vault on its own remote stays put");
|
||||
|
||||
// Detaching shares what was waiting there one last time, then it's only on this device.
|
||||
lune_core::upload::detach(&mut mac, "Brain").unwrap();
|
||||
let there = lune_core::git2::Repository::open_bare(&gitlab).unwrap();
|
||||
let tip = there.find_branch("main", lune_core::git2::BranchType::Local).unwrap().get().peel_to_commit().unwrap();
|
||||
assert_eq!(tip.tree().unwrap().get_name("idea.md").unwrap().to_object(&there).unwrap().as_blob().unwrap().content(), b"second\n");
|
||||
let v = open(&mac, "Brain");
|
||||
assert!(v.is_local());
|
||||
write_and_save(&v, "later.md", "kept here\n");
|
||||
v.sync().unwrap();
|
||||
assert_eq!(lune_core::status::of(mac.find("Brain").unwrap(), "Mac").headline, "Only on this device · not shared");
|
||||
drop(v);
|
||||
|
||||
// Uploading joins the same-named team vault, history included; another device gets every note.
|
||||
let said = lune_core::upload::upload(&mut mac, &sen, "Brain", false).unwrap();
|
||||
assert!(said.contains("history included"), "{said}");
|
||||
assert!(mac.find("Brain").unwrap().hub_vault.is_some());
|
||||
let code = sen.pair().unwrap();
|
||||
let other_w = hub::login(&url, &code, "Air").unwrap();
|
||||
let mut other = device(&url, &other_w, "Air", &tmp.path().join("air"));
|
||||
check_in(&mut other);
|
||||
let o = open(&other, "Brain");
|
||||
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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user