Milestone 7: the app normal people install (macOS)
A Tauri menu-bar app runs the same sync engine as `lunesync run`. It connects from the website with no code typed (lune://join and lune://pair links), shows status in the menu bar, and lets a person resolve held secrets, held big changes and kept-both notes side by side. Uninstall shares and hands over first, then removes only what Lune created. Releases are signed on the hub that holds the key (`lunehub release keygen/publish`); other hubs `release import` them. Apps verify the signature and the signed version. Clients older than the previous release are asked to update and keep saving locally. A device can now be on several hubs at once (own and workplace), each with its own key; the CLI takes --team when it matters. The supervisor and status summary moved into core, shared by the CLI and the app. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
163
hub/tests/hub.rs
163
hub/tests/hub.rs
@@ -120,7 +120,7 @@ fn device(url: &str, w: &hub::Welcome, label: &str, dir: &std::path::Path) -> Co
|
||||
Config {
|
||||
device_name: Some(label.into()),
|
||||
vaults_dir: Some(dir.to_path_buf()),
|
||||
hub: Some(HubLink { url: url.into(), device_id: w.device_id.clone(), key: w.key.clone() }),
|
||||
hubs: vec![HubLink { url: url.into(), device_id: w.device_id.clone(), key: w.key.clone() }],
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
@@ -151,7 +151,7 @@ fn taking_access_back() {
|
||||
let (_hub, url, owner_link) = start_hub(&tmp.path().join("data"));
|
||||
let (_, sen_w) = hub::join(&owner_link, "Codex").unwrap();
|
||||
let mut sen = device(&url, &sen_w, "Codex", &tmp.path().join("sen"));
|
||||
let sen_hub = sen.hub.clone().unwrap();
|
||||
let sen_hub = sen.hubs[0].clone();
|
||||
sen.use_hub_credentials();
|
||||
sen_hub.create_vault("DevOps").unwrap();
|
||||
sen_hub.create_vault("Notes").unwrap();
|
||||
@@ -206,7 +206,7 @@ fn taking_access_back() {
|
||||
assert!(!tmp.path().join("bob/DevOps").exists() && !tmp.path().join("bob/Notes").exists());
|
||||
let said = check_in(&mut bob);
|
||||
assert!(said[0].contains("removed from the hub"), "{said:?}");
|
||||
assert!(bob.hub.is_none());
|
||||
assert!(bob.hubs.is_empty());
|
||||
sen.use_hub_credentials();
|
||||
let bob_handover = sen_hub.handovers().unwrap().into_iter().find(|h| h.person == "Bob" && h.state == "received").unwrap();
|
||||
sen_hub.handover_decide(bob_handover.id, "discard").unwrap();
|
||||
@@ -389,3 +389,160 @@ fn health_nudge_and_tidy() {
|
||||
assert!(!a.root.join(©).exists());
|
||||
assert!(get("/api/canvas")["vaults"][0]["tidy"].as_array().unwrap().is_empty());
|
||||
}
|
||||
|
||||
fn lunehub(data: &std::path::Path, args: &[&str]) -> std::process::Output {
|
||||
Command::new(env!("CARGO_BIN_EXE_lunehub"))
|
||||
.args(args)
|
||||
.env("LUNE_HUB_DATA", data)
|
||||
.env("LUNE_RELEASE_PASSWORD", "test only")
|
||||
.output()
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn releases_are_signed_on_the_hub_and_old_clients_are_asked_to_update() {
|
||||
use base64::Engine;
|
||||
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);
|
||||
|
||||
// The key is made on the hub; only the public half leaves it.
|
||||
let made = lunehub(&data, &["release", "keygen"]);
|
||||
assert!(made.status.success(), "{}", String::from_utf8_lossy(&made.stderr));
|
||||
let pubkey = String::from_utf8(made.stdout).unwrap().lines().last().unwrap().trim().to_string();
|
||||
assert!(!lunehub(&data, &["release", "keygen"]).status.success(), "a second key would orphan every app");
|
||||
|
||||
let update = tmp.path().join("Lune.app.tar.gz");
|
||||
let dmg = tmp.path().join("Lune.dmg");
|
||||
for v in ["0.1.0", "0.2.0", "0.3.0"] {
|
||||
std::fs::write(&update, format!("app {v}")).unwrap();
|
||||
std::fs::write(&dmg, format!("dmg {v}")).unwrap();
|
||||
let out = lunehub(&data, &["release", "publish", v, update.to_str().unwrap(), dmg.to_str().unwrap(), "Notes"]);
|
||||
assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr));
|
||||
}
|
||||
let again = lunehub(&data, &["release", "publish", "0.2.5", update.to_str().unwrap(), dmg.to_str().unwrap()]);
|
||||
assert!(!again.status.success(), "versions only go up");
|
||||
|
||||
// The updater's question: 0.2.0 gets 0.3.0, signed with the hub's key, version bound in the signature.
|
||||
let agent = ureq::Agent::config_builder().http_status_as_error(false).build().new_agent();
|
||||
let mut res = agent.get(format!("{url}/api/update/darwin/aarch64/0.2.0")).call().unwrap();
|
||||
assert_eq!(res.status(), 200);
|
||||
let offer: serde_json::Value = res.body_mut().read_json().unwrap();
|
||||
assert_eq!(offer["version"], "0.3.0");
|
||||
let bytes = agent.get(offer["url"].as_str().unwrap()).call().unwrap().body_mut().read_to_vec().unwrap();
|
||||
assert_eq!(bytes, b"app 0.3.0");
|
||||
let b64 = |s: &str| String::from_utf8(base64::engine::general_purpose::STANDARD.decode(s).unwrap()).unwrap();
|
||||
let pk = minisign::PublicKeyBox::from_string(&b64(&pubkey)).unwrap().into_public_key().unwrap();
|
||||
let sig = minisign::SignatureBox::from_string(&b64(offer["signature"].as_str().unwrap())).unwrap();
|
||||
assert!(sig.trusted_comment().unwrap().contains("\tversion:0.3.0"));
|
||||
minisign::verify(&pk, &sig, std::io::Cursor::new(&bytes), true, false, false).unwrap();
|
||||
assert_eq!(agent.get(format!("{url}/api/update/darwin/aarch64/0.3.0")).call().unwrap().status(), 204);
|
||||
let mut dl = agent.get(format!("{url}/download/mac")).call().unwrap();
|
||||
assert_eq!(dl.body_mut().read_to_vec().unwrap(), b"dmg 0.3.0");
|
||||
|
||||
// A second hub (a workplace) offers the same signed release without ever holding the key.
|
||||
let work = tmp.path().join("work");
|
||||
std::fs::create_dir_all(&work).unwrap();
|
||||
let imported = lunehub(&work, &["release", "import", data.join("releases/0.3.0").to_str().unwrap()]);
|
||||
assert!(imported.status.success(), "{}", String::from_utf8_lossy(&imported.stderr));
|
||||
assert!(!work.join("release/update.key").exists());
|
||||
assert_eq!(std::fs::read(work.join("releases/0.3.0/release.json")).unwrap(), std::fs::read(data.join("releases/0.3.0/release.json")).unwrap());
|
||||
|
||||
// 0.1.0 is two releases behind: it keeps its place on the team but can't sync until it updates.
|
||||
remote::set_client_version("0.3.0");
|
||||
let (_, sen) = hub::join(&owner_link, "Codex").unwrap();
|
||||
let codex = as_device(&url, &sen);
|
||||
let devops = codex.create_vault("DevOps").unwrap();
|
||||
let (cfg, _, _) = vault::add("DevOps", &tmp.path().join("codex"), &devops.git_url, "Codex").unwrap();
|
||||
let v = Vault::open(&cfg, "Codex").unwrap();
|
||||
remote::set_client_version("0.1.0");
|
||||
assert!(format!("{:#}", codex.me().unwrap_err()).contains(remote::TOO_OLD));
|
||||
std::fs::write(v.root.join("note.md"), "kept while outdated\n").unwrap();
|
||||
assert!(v.save_changes(None, &HashSet::new()).unwrap().is_some(), "saving locally goes on");
|
||||
assert_eq!(remote::describe_error(&v.sync().unwrap_err()), remote::TOO_OLD);
|
||||
// One release behind still syncs.
|
||||
remote::set_client_version("0.2.0");
|
||||
assert_eq!(codex.me().unwrap().vaults.len(), 1);
|
||||
v.sync().unwrap();
|
||||
assert_eq!(v.waiting_files().unwrap(), 0);
|
||||
remote::set_client_version(env!("CARGO_PKG_VERSION"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn one_device_on_two_hubs_keeps_the_teams_apart() {
|
||||
let _turn = SERIAL.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let tmp = tempfile::TempDir::new().unwrap();
|
||||
let (_own, own_url, own_link) = start_hub(&tmp.path().join("own"));
|
||||
let (_work, work_url, work_link) = start_hub(&tmp.path().join("work"));
|
||||
|
||||
// Sen's own hub, with a Notes vault and a second device to read it from.
|
||||
let (_, sen_w) = hub::join(&own_link, "Mac").unwrap();
|
||||
let mut mac = device(&own_url, &sen_w, "Mac", &tmp.path().join("mac"));
|
||||
mac.use_hub_credentials();
|
||||
mac.hubs[0].create_vault("Notes").unwrap();
|
||||
let code = mac.hubs[0].pair().unwrap();
|
||||
let hermes_w = hub::login(&own_url, &code, "Hermes").unwrap();
|
||||
let mut hermes = device(&own_url, &hermes_w, "Hermes", &tmp.path().join("hermes"));
|
||||
|
||||
// The workplace hub (its owner is also called Sen by the test hub) has a Notes too; it invites Mov Sen.
|
||||
let (_, boss_w) = hub::join(&work_link, "Boss pc").unwrap();
|
||||
let mut boss = device(&work_url, &boss_w, "Boss pc", &tmp.path().join("boss"));
|
||||
boss.use_hub_credentials();
|
||||
boss.hubs[0].create_vault("Notes").unwrap();
|
||||
let invite = boss.hubs[0].invite("Mov Sen", &[("Notes".into(), "edit".into())]).unwrap();
|
||||
let (url, w) = hub::join(&invite, "Mac").unwrap();
|
||||
mac.hubs.push(HubLink { url, device_id: w.device_id, key: w.key });
|
||||
|
||||
// Both arrive, in separate folders, each tied to its own hub.
|
||||
let said = check_in(&mut mac);
|
||||
assert_eq!(mac.vaults.len(), 2, "{said:?}");
|
||||
let own_notes = mac.vaults.iter().find(|v| v.hub_url.as_deref() == Some(own_url.as_str())).unwrap().clone();
|
||||
let work_notes = mac.vaults.iter().find(|v| v.hub_url.as_deref() == Some(work_url.as_str())).unwrap().clone();
|
||||
assert_ne!(own_notes.path, work_notes.path);
|
||||
mac.use_hub_credentials();
|
||||
let label = mac.device_label();
|
||||
let (a, b) = (Vault::open(&own_notes, &label).unwrap(), Vault::open(&work_notes, &label).unwrap());
|
||||
write_and_save(&a, "home.md", "mine\n");
|
||||
write_and_save(&b, "work.md", "the company's\n");
|
||||
a.sync().unwrap();
|
||||
b.sync().unwrap();
|
||||
|
||||
check_in(&mut hermes);
|
||||
let h = open(&hermes, "Notes");
|
||||
h.sync().unwrap();
|
||||
assert!(h.root.join("home.md").exists() && !h.root.join("work.md").exists());
|
||||
check_in(&mut boss);
|
||||
let bn = open(&boss, "Notes");
|
||||
bn.sync().unwrap();
|
||||
assert!(bn.root.join("work.md").exists() && !bn.root.join("home.md").exists());
|
||||
|
||||
// The workplace takes Sen's access back: only that folder leaves.
|
||||
boss.use_hub_credentials();
|
||||
boss.hubs[0].remove("Mov Sen", "Notes", false).unwrap();
|
||||
check_in(&mut mac);
|
||||
assert!(!work_notes.path.exists());
|
||||
assert_eq!(std::fs::read(own_notes.path.join("home.md")).unwrap(), b"mine\n");
|
||||
assert_eq!(mac.vaults.len(), 1);
|
||||
let a = open(&mac, "Notes");
|
||||
write_and_save(&a, "home.md", "still mine\n");
|
||||
a.sync().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_single_hub_config_from_before_moves_into_the_list() {
|
||||
let tmp = tempfile::TempDir::new().unwrap();
|
||||
std::fs::write(
|
||||
tmp.path().join("config.toml"),
|
||||
"device_name = \"Mac\"\n\n[hub]\nurl = \"https://hub.example\"\ndevice_id = \"dev_1\"\nkey = \"k\"\n\n\
|
||||
[[vault]]\nname = \"Notes\"\npath = \"/tmp/notes\"\nremote = \"https://hub.example/git/1.git\"\nbranch = \"main\"\nhub_vault = 1\n",
|
||||
)
|
||||
.unwrap();
|
||||
let _turn = SERIAL.lock().unwrap_or_else(|e| e.into_inner());
|
||||
unsafe { std::env::set_var("LUNE_HOME", tmp.path()) };
|
||||
let c = Config::load().unwrap();
|
||||
unsafe { std::env::remove_var("LUNE_HOME") };
|
||||
assert_eq!(c.hubs.len(), 1);
|
||||
assert_eq!(c.vaults[0].hub_url.as_deref(), Some("https://hub.example"));
|
||||
assert_eq!(c.hub_of(&c.vaults[0]).unwrap().device_id, "dev_1");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user