Milestone 5: canvas for access

The hub now serves a React canvas (web/, embedded at build time):
grant by dragging a vault onto a person, revoke by pulling a ribbon
until it snaps with an 8 s Undo the hub honours before anything reaches
devices, invites (including vaults dropped on invitees), device rename
and removal, Float/Dock, and panels with a button for every gesture.

Sign-in without passwords (SPEC §8): `lunesync open` one-time link or
a pairing code typed on the hub; 30-day HttpOnly session cookie plus an
X-Lune header on every canvas request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-29 07:56:41 +07:00
parent 4025726083
commit 193cb06f85
27 changed files with 3574 additions and 39 deletions

View File

@@ -254,3 +254,60 @@ fn taking_access_back() {
assert!(log.iter().any(|a| a == action), "missing {action} in {log:?}");
}
}
// ---- Milestone 5: the canvas's sessions and the Undo window ----
#[test]
fn canvas_session_and_undo_window() {
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);
codex.create_vault("DevOps").unwrap();
let link = codex.invite("Alice", &[("DevOps".into(), "edit".into())]).unwrap();
hub::join(&link, "Alice laptop").unwrap();
as_device(&url, &sen_w);
let agent: ureq::Agent = ureq::Agent::config_builder().http_status_as_error(false).build().into();
// Sign in with a pairing code: the browser gets a session cookie.
let res = agent.post(format!("{url}/api/web/signin")).send_json(serde_json::json!({ "code": codex.pair().unwrap() })).unwrap();
assert_eq!(res.status(), 200);
let cookie = res.headers().get("set-cookie").unwrap().to_str().unwrap().to_string();
assert!(cookie.contains("HttpOnly") && cookie.contains("SameSite=Strict"), "{cookie}");
let session = cookie.split(';').next().unwrap().to_string();
// Without the canvas header, a cookie alone gets nothing (no cross-site requests).
let res = agent.get(format!("{url}/api/canvas")).header("Cookie", &session).call().unwrap();
assert_eq!(res.status(), 403);
let canvas = |agent: &ureq::Agent| -> serde_json::Value {
agent.get(format!("{url}/api/canvas")).header("Cookie", &session).header("X-Lune", "1").call().unwrap().body_mut().read_json().unwrap()
};
let c = canvas(&agent);
assert_eq!(c["me"]["person"], "Sen");
assert_eq!(c["members"].as_array().unwrap().len(), 2);
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 alice_has_devops = || codex.members("DevOps").unwrap().iter().any(|m| m.person == "Alice");
// Pull the ribbon, then Undo inside the window: nothing happened.
let pending = post("/api/remove", serde_json::json!({"person": "Alice", "vault": "DevOps", "delay_seconds": 2}))["pending"].as_i64().unwrap();
assert!(alice_has_devops(), "still a member during the Undo window");
post("/api/remove/undo", serde_json::json!({ "pending": pending }));
std::thread::sleep(std::time::Duration::from_millis(3500));
assert!(alice_has_devops());
// Pull again and let the window pass: the removal goes through.
post("/api/remove", serde_json::json!({"person": "Alice", "vault": "DevOps", "delay_seconds": 1}));
std::thread::sleep(std::time::Duration::from_millis(3000));
assert!(!alice_has_devops());
let undo = post("/api/remove/undo", serde_json::json!({ "pending": pending }));
assert!(undo["error"].as_str().unwrap().contains("too late"));
// Signing out ends the session.
post("/api/web/signout", serde_json::json!({}));
let res = agent.get(format!("{url}/api/canvas")).header("Cookie", &session).header("X-Lune", "1").call().unwrap();
assert_eq!(res.status(), 401);
}