From 588130b869bc112b639af293c928d98998695f3d Mon Sep 17 00:00:00 2001 From: Libby Date: Thu, 12 Nov 2026 08:46:38 +0000 Subject: [PATCH] Rust mesh: pin a snapshot over a stale node and correct the apply doc Co-Authored-By: Claude Sonnet 5.5 --- packages/cultmesh-rs/src/lib.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/packages/cultmesh-rs/src/lib.rs b/packages/cultmesh-rs/src/lib.rs index 7d8476e6..310629e3 100644 --- a/packages/cultmesh-rs/src/lib.rs +++ b/packages/cultmesh-rs/src/lib.rs @@ -735,9 +735,11 @@ impl CultMeshNode { self.apply_raw_snapshot_documents(documents) } - /// Applies the snapshot documents of registered schemas as one cache commit, as C# does: a refusal (a key this node - /// holds read-only because of unread slots from a newer peer or a payload this build cannot read, or any other the cache - /// judges) applies nothing. The commit lands in one backing store, so a snapshot spanning stores is refused whole. + /// Applies the snapshot documents as one cache commit, as C# does: a refusal (a key this node holds read-only because + /// of unread slots from a newer peer or a payload this build cannot read, or any other the cache judges) applies + /// nothing. A schema id the registry does not know is skipped, except one with a `.vN` suffix, which is taken as + /// registered and refuses the commit when its type is not (C# throws on an unknown schema too). The commit lands in + /// one backing store, so a snapshot spanning stores is refused whole. fn apply_raw_snapshot_documents( &mut self, documents: Vec, @@ -1253,6 +1255,21 @@ mod tests { Ok(()) } + #[test] + fn a_snapshot_applied_to_a_stale_node_keeps_the_records_another_writer_added() -> Result<()> { + let temp = tempfile::tempdir()?; + let path = temp.path().join("m.cc"); + let mut node = CultMesh::create_node(&path, TestDocuments, Default::default())?; + let mut other = CultMesh::create_node(&path, TestDocuments, Default::default())?; + other.put("added", &Note { body: "other writer".to_string() })?; + let plain = |body: &str| rmp_serde::to_vec(&(body,)); + assert_eq!(node.apply_raw_snapshot_documents(vec![raw_note("snap", plain("s")?)])?, 1); + let reopened = CultMesh::create_node(&path, TestDocuments, Default::default())?; + assert_eq!(reopened.get_required::("added")?.body, "other writer"); + assert_eq!(reopened.get_required::("snap")?.body, "s"); + Ok(()) + } + #[test] fn node_round_trips_registered_documents() -> Result<()> { let temp = tempfile::tempdir()?;