From d61216dd62527b4530bf49137e13b6a9ee6c7d68 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 27 Nov 2026 20:19:36 +0100 Subject: [PATCH] cultcache-rs: pin removal and UTF-16 order of the moved-store keys Co-Authored-By: Claude Sonnet 5.5 --- packages/cultcache-rs/tests/unique_index.rs | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/cultcache-rs/tests/unique_index.rs b/packages/cultcache-rs/tests/unique_index.rs index 2bd4b530..d1124587 100644 --- a/packages/cultcache-rs/tests/unique_index.rs +++ b/packages/cultcache-rs/tests/unique_index.rs @@ -1025,3 +1025,26 @@ fn registering_without_the_index_releases_the_holders() { cache.put("b", &Twin { sku: "S".into(), category: "x".into() }).unwrap(); assert!(cache.register_entry_type::().is_err(), "the duplicate now written is a held violation"); } + +#[test] +fn a_record_another_writer_removed_or_added_moves_the_store_and_the_keys_come_back_in_utf16_order() { + for kind in ["single", "redb", "owned"] { + let dir = tempfile::tempdir().unwrap(); + let kind = kinds(dir.path()).into_iter().find(|(name, _)| *name == kind).unwrap().1; + let mut seed = reader(&kind, dir.path()); + seed.put("a", &Plain { value: "gone soon".into() }).unwrap(); + let mut second = reader(&kind, dir.path()); + let mut other = reader(&kind, dir.path()); + + // A removal alone moves the store. + assert!(other.delete::("a").unwrap()); + assert_eq!(conflict_of(&second.put("c", &unique("fresh")).unwrap_err()).changed_keys, ["a"]); + assert!(second.get::("a").unwrap().is_none(), "the removal is loaded"); + + // Keys sort by UTF-16 code unit: b, then the astral U+10400 (D801 DC00), then U+FF21. + for key in ["\u{ff21}", "\u{10400}", "b"] { + other.put(key, &Plain { value: "x".into() }).unwrap(); + } + assert_eq!(conflict_of(&second.put("c", &unique("fresh")).unwrap_err()).changed_keys, ["b", "\u{10400}", "\u{ff21}"]); + } +}