Milestone 6: canvas for health and leaving
Devices report freshness per vault every 30 s (counts only); the canvas shows current / behind / offline, held secrets in red, and a Nudge that reaches the device at its next check-in. Notes kept in two versions can be compared side by side and tidied on the hub's copy. Handovers are reviewed in the vault panel; people can be removed from the team and restored with a one-time link. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -311,3 +311,81 @@ fn canvas_session_and_undo_window() {
|
||||
let res = agent.get(format!("{url}/api/canvas")).header("Cookie", &session).header("X-Lune", "1").call().unwrap();
|
||||
assert_eq!(res.status(), 401);
|
||||
}
|
||||
|
||||
// ---- Milestone 6: freshness, Nudge, tidying on the canvas ----
|
||||
|
||||
#[test]
|
||||
fn health_nudge_and_tidy() {
|
||||
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, "Codex").unwrap();
|
||||
let codex = as_device(&url, &sen_w);
|
||||
let devops = codex.create_vault("DevOps").unwrap();
|
||||
let hermes_w = hub::login(&url, &codex.pair().unwrap(), "Hermes").unwrap();
|
||||
|
||||
// The same lines changed on two devices: the hub's copy keeps both.
|
||||
as_device(&url, &sen_w);
|
||||
let (cfg_a, _, _) = vault::add("DevOps", &tmp.path().join("codex"), &devops.git_url, "Codex").unwrap();
|
||||
let a = Vault::open(&cfg_a, "Codex").unwrap();
|
||||
std::fs::write(a.root.join("runbook.md"), "restart: TODO\n").unwrap();
|
||||
a.save_changes(None, &HashSet::new()).unwrap();
|
||||
a.sync().unwrap();
|
||||
let hermes = as_device(&url, &hermes_w);
|
||||
let (cfg_h, _, _) = vault::add("DevOps", &tmp.path().join("hermes"), &devops.git_url, "Hermes").unwrap();
|
||||
let h = Vault::open(&cfg_h, "Hermes").unwrap();
|
||||
as_device(&url, &sen_w);
|
||||
std::fs::write(a.root.join("runbook.md"), "restart: systemctl\n").unwrap();
|
||||
a.save_changes(None, &HashSet::new()).unwrap();
|
||||
a.sync().unwrap();
|
||||
as_device(&url, &hermes_w);
|
||||
std::fs::write(h.root.join("runbook.md"), "restart: docker\n").unwrap();
|
||||
h.save_changes(None, &HashSet::new()).unwrap();
|
||||
h.sync().unwrap();
|
||||
|
||||
// Codex reports something waiting; Hermes never reports.
|
||||
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 }])
|
||||
.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": codex.pair().unwrap() })).unwrap();
|
||||
let session = res.headers().get("set-cookie").unwrap().to_str().unwrap().split(';').next().unwrap().to_string();
|
||||
let get = |path: &str| -> serde_json::Value {
|
||||
agent.get(format!("{url}{path}")).header("Cookie", &session).header("X-Lune", "1").call().unwrap().body_mut().read_json().unwrap()
|
||||
};
|
||||
let post = |path: &str, body: serde_json::Value| -> serde_json::Value {
|
||||
agent.post(format!("{url}{path}")).header("Cookie", &session).header("X-Lune", "1").send_json(body).unwrap().body_mut().read_json().unwrap()
|
||||
};
|
||||
|
||||
let canvas = get("/api/canvas");
|
||||
let devices = canvas["people"][0]["devices"].as_array().unwrap().clone();
|
||||
let status = |label: &str| devices.iter().find(|d| d["label"] == label).unwrap()["health"]["status"].clone();
|
||||
assert_eq!(status("Codex"), "behind");
|
||||
assert_eq!(status("Hermes"), "offline");
|
||||
let tidy = canvas["vaults"][0]["tidy"].as_array().unwrap().clone();
|
||||
assert_eq!(tidy.len(), 1, "{canvas}");
|
||||
let copy = tidy[0]["copy"].as_str().unwrap().to_string();
|
||||
|
||||
// Nudge reaches Hermes exactly once.
|
||||
let hermes_id = devices.iter().find(|d| d["label"] == "Hermes").unwrap()["id"].as_str().unwrap().to_string();
|
||||
post("/api/nudge", serde_json::json!({ "device_id": hermes_id }));
|
||||
as_device(&url, &hermes_w);
|
||||
assert!(hermes.me().unwrap().nudge);
|
||||
assert!(!hermes.me().unwrap().nudge);
|
||||
|
||||
// Compare side by side, then keep the copy's version: the copy disappears everywhere.
|
||||
let c = post("/api/tidy/compare", serde_json::json!({ "vault": "DevOps", "copy": copy }));
|
||||
assert_eq!(c["note_text"], "restart: systemctl\n");
|
||||
assert_eq!(c["copy_text"], "restart: docker\n");
|
||||
let r = post("/api/tidy/resolve", serde_json::json!({ "vault": "DevOps", "copy": copy, "keep": "copy" }));
|
||||
assert!(r["message"].as_str().unwrap().contains("kept Hermes's version"), "{r}");
|
||||
as_device(&url, &sen_w);
|
||||
a.save_changes(None, &HashSet::new()).unwrap();
|
||||
a.sync().unwrap();
|
||||
assert_eq!(std::fs::read(a.root.join("runbook.md")).unwrap(), b"restart: docker\n");
|
||||
assert!(!a.root.join(©).exists());
|
||||
assert!(get("/api/canvas")["vaults"][0]["tidy"].as_array().unwrap().is_empty());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user