Catalog-member vectors: TypeScript and Python readers assert every row of the shared table (fix batch 2)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-27 22:38:15 +01:00
commit d0a149cd9e
2 changed files with 32 additions and 29 deletions

View file

@ -1,5 +1,6 @@
from __future__ import annotations
import json
import shutil
import tempfile
import unittest
@ -8,10 +9,13 @@ 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.
# publishes a catalog row for each of the 29 members, every one of which members.json spells; 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"
# [slot, member, typeName, isReference, isMany, targetSchemaName, isName, indexAlias]
TABLE = json.loads((VECTORS / "members.json").read_text(encoding="utf-8"))
def pull(name: str):
directory = Path(tempfile.mkdtemp())
@ -24,22 +28,17 @@ def pull(name: str):
class CatalogMembersVectorTests(unittest.TestCase):
def test_the_csharp_written_store_publishes_17_members_and_one_record(self) -> None:
def test_the_csharp_written_store_publishes_every_row_of_the_shared_table(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")
self.assertEqual(len(TABLE), 29)
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)
def test_the_rust_written_store_publishes_no_members_and_one_record(self) -> None:
envelopes = pull("rust-members-empty-store.cc")

View file

@ -1,13 +1,13 @@
import assert from "node:assert/strict";
import { existsSync } from "node:fs";
import { existsSync, readFileSync } 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.
// publishes a catalog row for each of the 29 members, every one of which members.json spells; 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)) {
@ -17,22 +17,26 @@ function findVectors(from: string): string {
}
const vectors = findVectors(__dirname);
test("the C# written store publishes 17 members for tests.catalog_members and one record m:1", () => {
// [slot, member, typeName, isReference, isMany, targetSchemaName, isName, indexAlias]
const table = JSON.parse(readFileSync(join(vectors, "members.json"), "utf8")) as unknown[][];
test("the C# written store publishes every row of the shared table 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");
assert.equal(table.length, 29);
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);
});
test("the Rust written store publishes members [] for tests.catalog_members and one record m:1", () => {