0.1.6: GBrain brains — refreshed after sync, clashes never make a second page
- A vault has a kind on the hub: Obsidian (as before) or GBrain. Set it with
`lunesync vault kind`, the canvas panel or the window; Lune suggests it when
it finds gbrain.yml / .gbrain-source. Every change is in the access log.
- GBrain vaults: devices that have `gbrain` (looked for beyond PATH) are asked
once whether to refresh it after sync. Lune then runs
`gbrain sync --source <name> --no-pull` in the background after notes arrive
or are saved; it never holds up syncing. A failed refresh turns the vault
amber ("GBrain not refreshed") with Retry, also on the canvas.
- Clashes in GBrain vaults: lines both sides added are kept in the one note,
incoming first. Same lines changed: the incoming version stays, this
device's waits under Notes to tidy, stored in .git/lune/tidy (never a copy
file GBrain would index). Applies to syncing, undo, held notes and
handovers. Held notes moved aside stay red until decided.
- .gbrain-source is kept per device. Obsidian vaults are unchanged.
- SPEC: M8 section and decisions recorded.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
//! The hub end to end: one-time links, pairing, roles enforced by the hub, secrets refused (P3).
|
||||
|
||||
use lune_core::config::VaultKind;
|
||||
use lune_core::hub::{self, HubLink};
|
||||
use lune_core::vault::{self, Vault};
|
||||
use lune_core::{remote, secrets, state};
|
||||
@@ -354,7 +355,7 @@ fn health_nudge_and_tidy() {
|
||||
let codex = as_device(&url, &sen_w);
|
||||
std::fs::write(a.root.join("draft.md"), "unsaved\n").unwrap();
|
||||
codex
|
||||
.report(&[hub::VaultHealth { vault_id: devops.id, last_synced: Some(1), waiting: 1, held_secrets: 0, holding: false }])
|
||||
.report(&[hub::VaultHealth { vault_id: devops.id, last_synced: Some(1), waiting: 1, held_secrets: 0, holding: false, gbrain_failed: false, to_tidy: 0 }])
|
||||
.unwrap();
|
||||
|
||||
let agent: ureq::Agent = ureq::Agent::config_builder().http_status_as_error(false).build().into();
|
||||
@@ -616,6 +617,7 @@ fn deleting_a_vault_and_leaving_a_team() {
|
||||
branch: "main".into(),
|
||||
hub_vault: Some(1),
|
||||
hub_url: Some("http://127.0.0.1:9".into()),
|
||||
..Default::default()
|
||||
});
|
||||
assert!(lune_core::membership::leave_hub(&mut stale, "http://127.0.0.1:9", false).is_err());
|
||||
lune_core::membership::leave_hub(&mut stale, "http://127.0.0.1:9", true).unwrap();
|
||||
@@ -818,3 +820,70 @@ fn a_folder_follows_its_settings() {
|
||||
assert_eq!(v.remote_url().as_deref(), Some(cfg.remote.as_str()));
|
||||
assert!(v.follow("").unwrap() && v.is_local());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_vaults_kind_is_set_on_the_hub_and_every_device_follows() {
|
||||
let _turn = SERIAL.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let tmp = tempfile::TempDir::new().unwrap();
|
||||
unsafe { std::env::set_var("LUNE_HOME", tmp.path().join("cfg")) };
|
||||
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 link = mac.hubs[0].clone();
|
||||
link.create_vault("Brain").unwrap();
|
||||
// Existing and new vaults are Obsidian until someone says otherwise.
|
||||
assert_eq!(link.me().unwrap().vaults[0].kind, VaultKind::Obsidian);
|
||||
check_in(&mut mac);
|
||||
assert_eq!(mac.find("Brain").unwrap().kind, VaultKind::Obsidian);
|
||||
|
||||
// A Read member can't change it; Manage (here the owner) can, and it's logged.
|
||||
let invite = link.invite("Bob", &[("Brain".into(), "read".into())]).unwrap();
|
||||
let (_, bob_w) = hub::join(&invite, "Bob pc").unwrap();
|
||||
let bob = as_device(&url, &bob_w);
|
||||
let err = format!("{:#}", bob.vault_kind("Brain", Some(VaultKind::Gbrain), false).unwrap_err());
|
||||
assert!(err.contains("Manage"), "{err}");
|
||||
assert!(link.vault_kind("Brain", Some(VaultKind::Gbrain), false).is_ok());
|
||||
assert_eq!(bob.me().unwrap().vaults[0].kind, VaultKind::Gbrain);
|
||||
let log = link.log(20).unwrap();
|
||||
assert!(log.iter().any(|e| e.action == "vault setting" && e.detail == "Brain: kind set to GBrain"), "{log:?}");
|
||||
|
||||
// The device learns it at its next check-in, keeps it in its config, and ignores the per-device pin.
|
||||
mac.use_hub_credentials();
|
||||
let said = check_in(&mut mac);
|
||||
assert!(said.iter().any(|m| m.contains("GBrain")), "{said:?}");
|
||||
assert_eq!(mac.find("Brain").unwrap().kind, VaultKind::Gbrain);
|
||||
assert_eq!(Config::load().unwrap().find("Brain").unwrap().kind, VaultKind::Gbrain);
|
||||
let v = open(&mac, "Brain");
|
||||
write_and_save(&v, ".gbrain-source", "brain\n");
|
||||
write_and_save(&v, "gbrain.yml", "x: 1\n");
|
||||
assert_eq!(v.tracked_files().unwrap(), vec!["gbrain.yml".to_string()]);
|
||||
|
||||
// A device whose refresh failed says so; the canvas shows the vault's kind and which device is stale.
|
||||
let vid = link.me().unwrap().vaults[0].id;
|
||||
link.report(&[hub::VaultHealth { vault_id: vid, last_synced: Some(db_now()), waiting: 0, held_secrets: 0, holding: false, gbrain_failed: true, to_tidy: 2 }])
|
||||
.unwrap();
|
||||
let agent: ureq::Agent = ureq::Agent::config_builder().http_status_as_error(false).build().into();
|
||||
let res = agent.post(format!("{url}/api/web/signin")).send_json(serde_json::json!({ "code": link.pair().unwrap() })).unwrap();
|
||||
let session = res.headers().get("set-cookie").unwrap().to_str().unwrap().split(';').next().unwrap().to_string();
|
||||
let canvas: serde_json::Value =
|
||||
agent.get(format!("{url}/api/canvas")).header("Cookie", &session).header("X-Lune", "1").call().unwrap().body_mut().read_json().unwrap();
|
||||
assert_eq!(canvas["vaults"][0]["kind"], "gbrain");
|
||||
assert_eq!(canvas["vaults"][0]["gbrain_stale"], serde_json::json!(["Mac"]));
|
||||
// Versions kept on a device are counted, never shown: the canvas says how many wait on which device.
|
||||
assert_eq!(canvas["vaults"][0]["tidy_on"], serde_json::json!([{ "device": "Mac", "count": 2 }]));
|
||||
assert_eq!(canvas["people"][0]["devices"][0]["health"]["status"], "behind");
|
||||
link.report(&[hub::VaultHealth { vault_id: vid, last_synced: Some(db_now()), waiting: 0, held_secrets: 0, holding: false, gbrain_failed: false, to_tidy: 0 }])
|
||||
.unwrap();
|
||||
|
||||
// Back to Obsidian: the device follows that too.
|
||||
link.vault_kind("Brain", Some(VaultKind::Obsidian), false).unwrap();
|
||||
check_in(&mut mac);
|
||||
assert_eq!(mac.find("Brain").unwrap().kind, VaultKind::Obsidian);
|
||||
// The "this looks like a GBrain" hint can be dismissed.
|
||||
link.vault_kind("Brain", None, true).unwrap();
|
||||
}
|
||||
|
||||
fn db_now() -> i64 {
|
||||
std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_secs() as i64
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user