Catalog-member vectors: the C# store, README, TypeScript and Python readers (rs-member-rows-vectors)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-27 22:24:11 +01:00
commit aade365abb
4 changed files with 136 additions and 0 deletions

View file

@ -0,0 +1,52 @@
from __future__ import annotations
import shutil
import tempfile
import unittest
from pathlib import Path
from cultcache_py import SingleFileMessagePackBackingStore
# tests/vectors/catalog-members (variants:ruling:rs-catalog-member-rows-every-member): one record in two stores. The C# reference's
# publishes a catalog row for each of the 17 members; the one cultcache-rs wrote before it wrote member rows publishes members [].
# A reader takes both and pulls the one record m:1.
VECTORS = Path(__file__).resolve().parents[3] / "tests" / "vectors" / "catalog-members"
def pull(name: str):
directory = Path(tempfile.mkdtemp())
copy = directory / "store.cc"
shutil.copyfile(VECTORS / name, copy)
try:
return SingleFileMessagePackBackingStore(copy).pull_all()
finally:
shutil.rmtree(directory, ignore_errors=True)
class CatalogMembersVectorTests(unittest.TestCase):
def test_the_csharp_written_store_publishes_17_members_and_one_record(self) -> None:
envelopes = pull("csharp-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")
members = entry.members
self.assertEqual(
[(member.slot, member.member_name) for member in members],
[(0, "Title"), (1, "Sku"), (2, "Count"), (3, "Total"), (4, "Ratio"), (5, "Scale"), (6, "Flag"), (7, "MaybeCount"),
(8, "Note"), (9, "Tags"), (10, "Labels"), (11, "Raw"), (12, "Chunks"), (13, "Weights"), (14, "Mark"), (15, "Arm"),
(17, "Late")],
)
self.assertTrue(members[0].is_name)
self.assertEqual(members[1].index_alias, "sku")
self.assertEqual(members[7].type_name, "System.Nullable<System.Int32>")
self.assertEqual(members[14].type_name, "GameCult.Caching.Tests.CatalogMemberMark")
def test_the_rust_written_store_publishes_no_members_and_one_record(self) -> None:
envelopes = pull("rust-members-empty-store.cc")
self.assertEqual([envelope.key for envelope in envelopes], ["m:1"])
self.assertEqual(envelopes[0].catalog_entry.schema_name, "tests.catalog_members")
self.assertEqual(tuple(envelopes[0].catalog_entry.members), ())
if __name__ == "__main__":
unittest.main()

View file

@ -0,0 +1,43 @@
import assert from "node:assert/strict";
import { existsSync } from "node:fs";
import { dirname, join, resolve } from "node:path";
import { test } from "node:test";
import { readSingleFileStore } from "../src/single-file-messagepack-backing-store";
// tests/vectors/catalog-members (variants:ruling:rs-catalog-member-rows-every-member): one record in two stores. The C# reference's
// publishes a catalog row for each of the 17 members; the one cultcache-rs wrote before it wrote member rows publishes members [].
// A reader takes both and pulls the one record m:1.
function findVectors(from: string): string {
for (let dir = from; ; dir = dirname(dir)) {
if (existsSync(join(dir, "tests", "vectors", "catalog-members"))) return join(dir, "tests", "vectors", "catalog-members");
if (resolve(dir, "..") === dir) throw new Error("tests/vectors/catalog-members not found above the test.");
}
}
const vectors = findVectors(__dirname);
test("the C# written store publishes 17 members for tests.catalog_members and one record m:1", () => {
const { envelopes } = readSingleFileStore(join(vectors, "csharp-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 members = entry?.members ?? [];
assert.equal(members.length, 17);
assert.deepEqual(
members.map((member) => [member.slot, member.memberName]),
[[0, "Title"], [1, "Sku"], [2, "Count"], [3, "Total"], [4, "Ratio"], [5, "Scale"], [6, "Flag"], [7, "MaybeCount"], [8, "Note"],
[9, "Tags"], [10, "Labels"], [11, "Raw"], [12, "Chunks"], [13, "Weights"], [14, "Mark"], [15, "Arm"], [17, "Late"]],
);
assert.equal(members[0].isName, true);
assert.equal(members[1].indexAlias, "sku");
assert.equal(members[7].typeName, "System.Nullable<System.Int32>");
assert.equal(members[14].typeName, "GameCult.Caching.Tests.CatalogMemberMark");
});
test("the Rust written store publishes members [] for tests.catalog_members and one record m:1", () => {
const { envelopes } = readSingleFileStore(join(vectors, "rust-members-empty-store.cc"));
assert.deepEqual(envelopes.map((envelope) => envelope.key), ["m:1"]);
assert.equal(envelopes[0].catalogEntry?.schemaName, "tests.catalog_members");
assert.deepEqual(envelopes[0].catalogEntry?.members ?? [], []);
});

View file

@ -0,0 +1,41 @@
# catalog-members vector
Two stores holding the same record, `m:1` of type `tests.catalog_members` (version `tests.catalog_members.v1`), with a value in every slot.
`variants:ruling:rs-catalog-member-rows-every-member` is the ruling they serve: cultcache-rs writes a catalog row for every member, and
every runtime keeps reading a store whose Rust-written entry holds `members []`.
- `csharp-members-store.cc` is written by the C# reference (`CatalogMemberVectorTests`, under `CULTCACHE_WRITE_VECTORS=1`; every other run compares
the bytes). Its catalog entry carries the 17 rows below, in slot order, which is the order C# discovers members in.
- `rust-members-empty-store.cc` is written by cultcache-rs at base e503edf2 (`packages/cultcache-rs/tests/catalog_members.rs`, `the_members_empty_store_vector`,
under `CULTCACHE_WRITE_VECTORS=1`). It is the one vector in this folder C# does not write, and it is never regenerated: it pins the bytes old Rust wrote,
and a later Rust writes member rows. A Rust-written entry has id = schema name = `tests.catalog_members`, version `tests.catalog_members.v1`, and `members []`.
The type: a name (Title), a unique index (Sku), the scalar leaves, a nullable, a nullable string, a list, an array, a byte array, a list of byte arrays,
a dictionary, a record (`Mark`: slot 0 Label string, slot 1 Weight int), a union (`Arm`: arm 0 `CatalogMemberTextArm {Text}`, arm 1 `CatalogMemberCountArm {Count}`),
a gap at slot 16, and a slot above it (Late). The record holds: Title `Brass lantern`, Sku `LAN-0042`, Count -7, Total 10000000000, Ratio 0.25, Scale 1.5, Flag true,
MaybeCount 3, Note `handle with care`, Tags [fragile, lit], Labels [a, b, c], Raw 00 01 02 FE FF, Chunks [09 08, 07], Weights {brass 12, glass 3},
Mark {stamp, 5}, Arm Count 21, Late -9000000000.
C# rows (slot, member name, typeName):
| slot | member | typeName | role |
| --- | --- | --- | --- |
| 0 | Title | `System.String` | name |
| 1 | Sku | `System.String` | index `sku` |
| 2 | Count | `System.Int32` | |
| 3 | Total | `System.UInt64` | |
| 4 | Ratio | `System.Double` | |
| 5 | Scale | `System.Single` | |
| 6 | Flag | `System.Boolean` | |
| 7 | MaybeCount | `System.Nullable<System.Int32>` | |
| 8 | Note | `System.String` | |
| 9 | Tags | `System.Collections.Generic.List<System.String>` | |
| 10 | Labels | `System.String[]` | |
| 11 | Raw | `System.Byte[]` | |
| 12 | Chunks | `System.Collections.Generic.List<System.Byte[]>` | |
| 13 | Weights | `System.Collections.Generic.Dictionary<System.String, System.Int32>` | |
| 14 | Mark | `GameCult.Caching.Tests.CatalogMemberMark` | |
| 15 | Arm | `GameCult.Caching.Tests.CatalogMemberArm` | |
| 17 | Late | `System.Int64` | |
Readers: C# loads both stores typed (the Rust one with `defaulted_missing_slot` warnings only); Rust reads both records; TypeScript and Python read both stores and see 17 and 0 members.

Binary file not shown.