Add local CAS file roots

This commit is contained in:
Eric Wendland 2026-05-18 03:50:09 +02:00
commit e1f36ffafb
12 changed files with 581 additions and 13 deletions

View file

@ -168,6 +168,85 @@ fn cas_pin_unpin_updates_local_pin_metadata() {
}
}
#[test]
fn cas_file_root_add_list_scan_detects_changes() {
let home = tempfile::tempdir().expect("tempdir");
let paths = geth_config::GethPaths::from_home(home.path());
let node = geth_node::init_node(&paths).expect("init node");
let root_path = home.path().join("notes-root");
std::fs::create_dir_all(&root_path).expect("create root");
std::fs::write(root_path.join("a.txt"), b"alpha").expect("write a");
let response = geth_node::handle_request(
&node,
geth_control::ControlRequest::CasRootAdd {
name: "notes".to_owned(),
path: root_path.clone(),
},
)
.expect("add root");
match response {
geth_control::ControlResponse::CasRootAdded { root } => {
assert_eq!(root.name, "notes");
assert!(root.latest_tree.is_none());
}
other => panic!("unexpected response: {other:?}"),
}
let response = geth_node::handle_request(&node, geth_control::ControlRequest::CasRootList)
.expect("list roots");
match response {
geth_control::ControlResponse::CasRootList { roots } => {
assert_eq!(roots.len(), 1);
assert_eq!(roots[0].name, "notes");
}
other => panic!("unexpected response: {other:?}"),
}
let response = geth_node::handle_request(
&node,
geth_control::ControlRequest::CasRootScan {
name: "notes".to_owned(),
},
)
.expect("initial scan");
let first_tree = match response {
geth_control::ControlResponse::CasRootScanned { scan } => {
assert_eq!(scan.changes.len(), 1);
assert!(scan.root.latest_tree.is_some());
assert!(scan.note.contains("never overwrites"));
scan.tree.hash
}
other => panic!("unexpected response: {other:?}"),
};
std::fs::rename(root_path.join("a.txt"), root_path.join("b.txt")).expect("rename a to b");
std::fs::write(root_path.join("c.txt"), b"charlie").expect("write c");
let response = geth_node::handle_request(
&node,
geth_control::ControlRequest::CasRootScan {
name: "notes".to_owned(),
},
)
.expect("second scan");
match response {
geth_control::ControlResponse::CasRootScanned { scan } => {
assert_ne!(scan.tree.hash, first_tree);
assert!(scan.changes.iter().any(|change| {
matches!(
change,
geth_cas::FileRootChange::Renamed { from, to }
if from == "a.txt" && to == "b.txt"
)
}));
assert!(scan.changes.iter().any(|change| {
matches!(change, geth_cas::FileRootChange::Created { path } if path == "c.txt")
}));
}
other => panic!("unexpected response: {other:?}"),
}
}
#[test]
fn cas_cleanup_removes_unpinned_and_retains_pinned_blobs() {
let home = tempfile::tempdir().expect("tempdir");