From 9fd3b8b13bff46eb9cae39bf3307fcdd0c6f3948 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 27 Nov 2026 22:51:48 +0100 Subject: [PATCH] cultcache-rs: annotate the interop example, document member rows, readers pin the Rust rows Co-Authored-By: Claude Sonnet 5.5 --- .../cultcache-py/tests/test_catalog_members.py | 11 +++++++++++ packages/cultcache-rs/CHANGELOG.md | 2 ++ packages/cultcache-rs/README.md | 9 +++++++++ .../cultcache-rs/examples/cultcache_interop.rs | 11 ++++++----- .../cultcache-ts/test/catalog-members.test.ts | 18 ++++++++++++++++++ .../CatalogMemberVectorTests.cs | 18 ++++++++++++++++++ 6 files changed, 64 insertions(+), 5 deletions(-) diff --git a/packages/cultcache-py/tests/test_catalog_members.py b/packages/cultcache-py/tests/test_catalog_members.py index 1443214d..706f631e 100644 --- a/packages/cultcache-py/tests/test_catalog_members.py +++ b/packages/cultcache-py/tests/test_catalog_members.py @@ -46,6 +46,17 @@ class CatalogMembersVectorTests(unittest.TestCase): self.assertEqual(envelopes[0].catalog_entry.schema_name, "tests.catalog_members") self.assertEqual(tuple(envelopes[0].catalog_entry.members), ()) + def test_the_rust_written_store_with_member_rows_publishes_every_row_of_the_shared_table(self) -> None: + envelopes = pull("rust-members-store.cc") + self.assertEqual([envelope.key for envelope in envelopes], ["m:1"]) + entry = envelopes[0].catalog_entry + self.assertEqual(entry.schema_name, "tests.catalog_members") + rows = [ + [m.slot, m.member_name, m.type_name, m.is_reference, m.is_many, m.target_schema_name, m.is_name, m.index_alias] + for m in entry.members + ] + self.assertEqual(rows, TABLE) + if __name__ == "__main__": unittest.main() diff --git a/packages/cultcache-rs/CHANGELOG.md b/packages/cultcache-rs/CHANGELOG.md index a5216284..38a5d4cd 100644 --- a/packages/cultcache-rs/CHANGELOG.md +++ b/packages/cultcache-rs/CHANGELOG.md @@ -8,6 +8,7 @@ only in git history. ### Added +- `CultTypeName`, `SchemaCatalogMember`, `SchemaCatalogEntry::members`, `DatabaseEntry::schema_members`, `CacheBackingStore::describe` (provided, a no-op) and `#[cultcache(type_name = "...")]` on a type or a `DatabaseEntry` field: a Rust-written catalog entry carries a member row (slot, name, C# type name) for every member of a registered type, as C#, TypeScript and Python write. A field type with no name is written `System.Object`. Readers keep reading `members []` stores. - `CacheBackingStore::push_all_unchanged(entries)` returning `CultPushUnchanged` (`Committed { stamps }` or `Changed { changed_keys }`), a provided method whose default refuses with an error naming the store kind and `push_all_unchanged`: a custom store keeps compiling and its writes of indexed types are refused until it implements it. The three bundled stores keep what each handle last read or wrote (a clone starts empty). Public `CultCacheWriteConflict { record_keys, changed_keys }`. - `CultCache::update_with_attempts` and the conditional `update`: each attempt reads the record from its home store with its content version in one read, applies a function to a copy and commits only over that version, rerunning on a lost race (default five attempts). The result is `CultUpdateResult`, outcome `Updated`, `Declined` (the function returned `None`) or `LostRace`, with the cache's document. Public types `CultStoredRecord`, `CultCommitIf`, `CultUpdateOutcome`, `CultUpdateResult`. - `CacheBackingStore::read(key)` and `commit_if(entry, expected)`, provided methods whose defaults refuse with an error naming the store kind; `SingleFileMessagePackBackingStore` implements both. The content version is the lowercase hex SHA-256 of the record re-encoded as the store file writes it (key, schema id, `stored_at`, payload). It equals the SHA-256 of the record's bytes in the file, and so the C# reference's `tests/vectors/content-version`, whenever the file's MessagePack encodings are minimal, which every runtime's writer produces; a hand-edited file with a non-minimal encoding (for example a `str8` key that fits a fixstr) hashes differently from its slice here. New dependency `sha2` 0.10 and eight new lockfile crates: `sha2`, `digest`, `block-buffer`, `crypto-common`, `generic-array`, `typenum`, `cpufeatures`, `version_check`. @@ -19,6 +20,7 @@ only in git history. ### Changed +- Rust-written catalog entries carry member rows, so a C# reader whose declaration differs now refuses the store; the new `SchemaCatalogEntry` field breaks struct-literal construction. - A redb store that already holds two types at one key (written by a build before the one-record-per-key rule) refuses a write of either held type at that key with `SchemaConflictError`, where it once succeeded; delete one of the two rows (`delete(type, key)` removes that type's row alone), then write. - `CultCache::delete::` of a key nothing holds now refuses, as `put` and `is_writable` do, when `T` has no home store ("No backing store is registered…") or when a store carries a foreign record at the key or another registered type holds it (before: `Ok(false)`). - `is_stored_at_stamp(&str)` (new, public) is the one shape a peer's `storedAt` must parse as, pinned by `tests/vectors/stored-at-stamp` (RFC 3339 `YYYY-MM-DDThh:mm:ss`, a 1 to 9 digit fraction, `Z` or `+hh:mm`/`-hh:mm`; uppercase `T`/`Z`, a real date, seconds 00-59, years 0001-9999), hand-checked because `chrono`'s RFC 3339 reader takes other shapes. `put_raw_envelope` and `put_prepared_batch` refuse a `stored_at` that is not a stamp (before: only a blank one) and mint nothing (variants:ruling:raw-put-without-stamp-refused). diff --git a/packages/cultcache-rs/README.md b/packages/cultcache-rs/README.md index 986c6cd4..03471496 100644 --- a/packages/cultcache-rs/README.md +++ b/packages/cultcache-rs/README.md @@ -353,6 +353,15 @@ marked `default` use `Default::default()` when older payloads are read. Deleted field slots should stay reserved until an explicit store migration rewrites the data. +A store this cache writes carries a catalog row for every member of a type the cache has registered: the slot, the member name (the +field's name in PascalCase, as C#, TypeScript and Python spell it) and a C# type name. `CultTypeName` supplies the type name of the +std types (`i32` is `System.Int32`, `Vec` is `System.Collections.Generic.List`, an `Option` of a value type is +`System.Nullable`, a map is `System.Collections.Generic.Dictionary`, `serde_bytes::ByteBuf` and a `bytes` field are +`System.Byte[]`). Name your own type with `#[cultcache(type_name = "Ns.Type")]` on a `DatabaseEntry`, `CultSlots` or `CultUnion`, and +override one member with `#[cultcache(key = N, type_name = "System.Guid")]` on a `DatabaseEntry` field. A field type that names +nothing is written `System.Object`. `pull_schema_catalog` returns the rows as `SchemaCatalogEntry::members`. A C# reader refuses a +store whose row differs from its own declaration in type name, name flag or index alias, so annotate the types a C# peer also reads. + The single-file MessagePack store rewrites an atomic snapshot. That is a sane starting point for small typed state surfaces, settings, Epiphany agent memory, heartbeat state, and other compact control-plane data. Large corpora should use diff --git a/packages/cultcache-rs/examples/cultcache_interop.rs b/packages/cultcache-rs/examples/cultcache_interop.rs index dcafee5f..cba5308f 100644 --- a/packages/cultcache-rs/examples/cultcache_interop.rs +++ b/packages/cultcache-rs/examples/cultcache_interop.rs @@ -16,7 +16,7 @@ const INTEROP_SCHEMA_VERSION: &str = "cultcache.interop_note.v1"; struct CultCacheInteropNote { #[cultcache(key = 0)] schema_version: String, - #[cultcache(key = 1)] + #[cultcache(key = 1, name)] document_id: String, #[cultcache(key = 2)] author_runtime_id: String, @@ -24,7 +24,7 @@ struct CultCacheInteropNote { title: String, #[cultcache(key = 4)] body: String, - #[cultcache(key = 5, default)] + #[cultcache(key = 5, default, type_name = "System.String[]")] tags: Vec, } @@ -35,14 +35,15 @@ struct CultCacheInteropMark(String, String); #[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)] #[cultcache(type = "cultcache.interop-deck", schema = "CultCacheInteropDeck")] struct CultCacheInteropDeck { - #[cultcache(key = 0)] + #[cultcache(key = 0, name)] document_id: String, - #[cultcache(key = 1, default)] + #[cultcache(key = 1, default, type_name = "System.Collections.Generic.List")] marks: Vec, } // A union field and nested bytes: the shapes a Bifrost-style store holds beyond plain strings. #[derive(Clone, Debug, PartialEq, Eq, CultUnion)] +#[cultcache(type_name = "InteropArm")] enum InteropArm { #[cultcache(key = 0)] Text(InteropTextArm), @@ -67,7 +68,7 @@ struct InteropPackArm { #[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)] #[cultcache(type = "cultcache.interop-shape", schema = "CultCacheInteropShape")] struct CultCacheInteropShape { - #[cultcache(key = 0)] + #[cultcache(key = 0, name)] document_id: String, #[cultcache(key = 1)] arm: InteropArm, diff --git a/packages/cultcache-ts/test/catalog-members.test.ts b/packages/cultcache-ts/test/catalog-members.test.ts index a6023955..be93d147 100644 --- a/packages/cultcache-ts/test/catalog-members.test.ts +++ b/packages/cultcache-ts/test/catalog-members.test.ts @@ -45,3 +45,21 @@ test("the Rust written store publishes members [] for tests.catalog_members and assert.equal(envelopes[0].catalogEntry?.schemaName, "tests.catalog_members"); assert.deepEqual(envelopes[0].catalogEntry?.members ?? [], []); }); + +test("the Rust written store with member rows publishes every row of the shared table and one record m:1", () => { + const { envelopes } = readSingleFileStore(join(vectors, "rust-members-store.cc")); + assert.deepEqual(envelopes.map((envelope) => envelope.key), ["m:1"]); + const entry = envelopes[0].catalogEntry; + assert.equal(entry?.schemaName, "tests.catalog_members"); + const rows = (entry?.members ?? []).map((member) => [ + member.slot, + member.memberName, + member.typeName, + member.isReference ?? false, + member.isMany ?? false, + member.targetSchemaName ?? null, + member.isName ?? false, + member.indexAlias ?? null, + ]); + assert.deepEqual(rows, table); +}); diff --git a/tests/GameCult.Caching.Tests/CatalogMemberVectorTests.cs b/tests/GameCult.Caching.Tests/CatalogMemberVectorTests.cs index 0d02e20d..dd92f2c3 100644 --- a/tests/GameCult.Caching.Tests/CatalogMemberVectorTests.cs +++ b/tests/GameCult.Caching.Tests/CatalogMemberVectorTests.cs @@ -264,5 +264,23 @@ namespace GameCult.Caching.Tests ["defaulted_missing_slot"] = 29, })); } + + [Test] + public void RustWrittenStoreReadsWithItsRows() + { + // A Rust-written store with member rows loads typed with no refusal. Only the two id/hash drifts remain (the Rust entry's id and + // content hash are the schema name); the members-[] store adds defaulted_missing_slot x29, which the rows remove. + AssertEqualToExpected(ReadM1("rust-members-store.cc", out var reports)); + var warnings = reports.SelectMany(report => report.Warnings).GroupBy(warning => warning.Code).ToDictionary(group => group.Key, group => group.Count()); + Assert.That(warnings, Is.EquivalentTo(new Dictionary + { + ["compatible_schema_id_drift"] = 1, + ["content_hash_drift"] = 1, + })); + var expected = ExpectedRows(); + var actual = CatalogRows("rust-members-store.cc"); + Assert.That(actual, Has.Count.EqualTo(expected.Count)); + for (var i = 0; i < expected.Count; i++) Assert.That(actual[i], Is.EqualTo(expected[i]), "row " + i); + } } }