cultcache-rs: a hand impl that describes no rows keeps the file's rows; test type-level refusal and bytes vs type_name
All checks were successful
CultMesh portability and performance / ubuntu-latest reactive semantics and leases (pull_request) Successful in 26m18s
All checks were successful
CultMesh portability and performance / ubuntu-latest reactive semantics and leases (pull_request) Successful in 26m18s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
11a46364f6
commit
6d129ebffc
2 changed files with 49 additions and 2 deletions
|
|
@ -1177,4 +1177,21 @@ mod tests {
|
|||
assert!(tokens.find("\"Ident\"").unwrap() < tokens.find("\"RawBytes\"").unwrap(), "key order: {tokens}");
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn a_type_level_attribute_other_than_type_name_is_refused_on_slots_and_unions() {
|
||||
let message = slots_result(r#"#[cultcache(type = "t")] struct S { #[cultcache(key = 0)] a: String }"#).unwrap_err().to_string();
|
||||
assert!(message.contains("unsupported cultcache attribute"), "{message}");
|
||||
let input: DeriveInput = syn::parse_str(r#"#[cultcache(global)] enum U { #[cultcache(key = 0)] A }"#).unwrap();
|
||||
let message = union_codec(input).unwrap_err().to_string();
|
||||
assert!(message.contains("unsupported cultcache attribute"), "{message}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_explicit_type_name_wins_over_bytes_and_bytes_names_a_byte_array() {
|
||||
let tokens = entry_tokens(r#"#[cultcache(type = "t")] struct S { #[cultcache(key = 0, bytes, type_name = "Ns.Blob")] a: Vec<u8> }"#);
|
||||
assert!(tokens.contains("\"Ns.Blob\"") && !tokens.contains("\"System.Byte[]\""), "{tokens}");
|
||||
let tokens = entry_tokens(r#"#[cultcache(type = "t")] struct S { #[cultcache(key = 0, bytes)] a: Vec<u8> }"#);
|
||||
assert!(tokens.contains("\"System.Byte[]\""), "{tokens}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4881,7 +4881,7 @@ fn encode_store_snapshot(
|
|||
}));
|
||||
}
|
||||
}
|
||||
// An id a registered type owns is described from that type at every write, whatever the file holds. An entry the file holds for
|
||||
// An id a registered type owns and describes (a hand impl describes no rows) is described from that type at every write, whatever the file holds. An entry the file holds for
|
||||
// any other id is written back as the file holds it: this runtime keeps no description of another runtime's schema, so it
|
||||
// never replaces one. It describes such an id itself only when the file has no entry for it, or when a registered type owns
|
||||
// the id under another name (a rename, where the registered type names the id).
|
||||
|
|
@ -4893,7 +4893,7 @@ fn encode_store_snapshot(
|
|||
let mut catalog = BTreeMap::<String, PersistedSchemaCatalogEntry>::new();
|
||||
for (schema_id, document_type) in named {
|
||||
if schema_id == document_type
|
||||
&& let Some(members) = described_types.get(&schema_id)
|
||||
&& let Some(members) = described_types.get(&schema_id).filter(|members| !members.is_empty())
|
||||
{
|
||||
let entry = described(&schema_id, document_type, members);
|
||||
catalog.entry(entry.0.clone()).or_insert(entry);
|
||||
|
|
@ -8396,6 +8396,36 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Clone, serde::Serialize, serde::Deserialize)]
|
||||
struct HandWritten {
|
||||
a: String,
|
||||
}
|
||||
|
||||
impl DatabaseEntry for HandWritten {
|
||||
const TYPE: &'static str = "handnote";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_hand_impl_that_describes_no_rows_keeps_the_rows_the_file_holds() -> Result<()> {
|
||||
let temp = tempfile::tempdir()?;
|
||||
let path = temp.path().join("store.cc");
|
||||
let row = note_rows().remove(0);
|
||||
let held = PersistedSchemaCatalogEntry(
|
||||
"handnote".into(), "handnote".into(), "handnote.v1".into(), "handnote".into(), "{}".into(), vec!["handnote".into()], vec![row.clone()],
|
||||
);
|
||||
let record = PersistedRecord("carried".into(), "handnote".into(), "2026-09-30T00:00:00Z".into(), rmp_serde::to_vec(&HandWritten { a: "x".into() })?);
|
||||
std::fs::write(&path, rmp_serde::to_vec(&PersistedStoreSnapshot("cultcache.store.v1".into(), vec![held], vec![record]))?)?;
|
||||
let mut cache = CultCache::new();
|
||||
cache.register_entry_type::<HandWritten>()?;
|
||||
cache.add_generic_backing_store(SingleFileMessagePackBackingStore::new(&path))?;
|
||||
cache.pull_all_backing_stores()?;
|
||||
cache.put("another", &HandWritten { a: "y".into() })?;
|
||||
let catalog = written_catalog(&path)?;
|
||||
assert_eq!(catalog.len(), 1);
|
||||
assert_eq!(catalog[0].6, vec![row], "one row before, one row after");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_type_no_registration_describes_gets_members_empty() -> Result<()> {
|
||||
let temp = tempfile::tempdir()?;
|
||||
|
|
|
|||
Loading…
Reference in a new issue