Catalog writers merge entries that share an id; every reader resolves an id by its owner first

Entries that share a schema id are one schema seen by different writers, so the writer lists every id any of them lists, in any
order: C# single-file and directory (CultSchemaCatalogEntry.MergeById), TypeScript and Python. Rust synthesises one entry per id and
has no such merge. An id that one entry owns and another lists as compatible names the owner in Rust, TypeScript, Python and the TS
inspector, as C# already did (own-id-over-compatible-v3). Also: a directory manifest in an unreadable format is the typed refusal
naming it, cultnet-py applies and reports a record under the local schema id, and Rust's error prints its cause once.
Vectors for the Mesh layout discriminator: a nil and an integer at catalog slot 5.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-30 08:17:59 +02:00
commit f96a0e7f7a
20 changed files with 290 additions and 48 deletions

View file

@ -127,6 +127,8 @@ namespace GameCult.Caching.Tests
[TestCase("current-catalog-bad-canonical.msgpack")]
[TestCase("current-catalog-bad-members.msgpack")]
[TestCase("current-catalog-bad-compat.msgpack")]
[TestCase("current-catalog-bad-slot5-nil.msgpack")]
[TestCase("current-catalog-bad-slot5-int.msgpack")]
public void SingleFileRefusesAMalformedCurrentCatalogEntry(string vector)
{
Assert.That(Refusal(vector), Is.Not.Empty);

View file

@ -155,6 +155,67 @@ namespace GameCult.Caching.Tests
Assert.That(rewritten.Records.Select(record => record.SchemaId), Does.Contain("vectors.old.id"));
}
// An id one entry owns and a later entry lists as compatible names the entry that owns it.
[Test]
public void AnIdAnEntryOwnsNamesThatEntryNotOneThatListsItAsCompatible()
{
var path = Path.Combine(_directory, "own-id.cc");
File.WriteAllBytes(path, File.ReadAllBytes(Path.Combine(VectorRoot(), "own-id-over-compatible-v3.bin")));
using var cache = CultCacheMessagePack.Create(path, new CultCacheOpenOptions { Registry = Registry });
Assert.That(cache.Get<VectorItem>(new CultRecordKey("alpha")), Is.Not.Null, "the record read as the schema that owns its id");
}
// A directory rewrite where the entry that lists a kept record's id shares its own id with the schema being written keeps that
// id in the entry it writes, so the manifest still reads.
[Test]
public void ADirectoryRewriteMergesEntriesThatShareAnIdAndKeepsEveryIdTheyList()
{
var path = DirectoryStore("merged.cc");
var manifest = CultDocumentMessagePackSerialization.DeserializeSnapshot(File.ReadAllBytes(path));
var entry = manifest.SchemaCatalog.Single();
manifest.Records.Single().SchemaId = "vectors.old.id";
entry.CompatibleSchemaIds = new[] { entry.SchemaId, "vectors.old.id" };
File.WriteAllBytes(path, CultDocumentMessagePackSerialization.SerializeSnapshot(manifest));
using (var cache = CultCacheMessagePack.Create(path, new CultCacheOpenOptions { Registry = Registry, UseDirectoryStore = true }))
cache.Commit(batch => batch.Upsert(typeof(IdDeck), new IdDeck { Name = "e" }, new CultRecordKey("e")));
var rewritten = CultDocumentMessagePackSerialization.DeserializeSnapshot(File.ReadAllBytes(path));
Assert.That(rewritten.SchemaCatalog.Single().CompatibleSchemaIds, Does.Contain("vectors.old.id"));
}
// Entries that share an id are merged whatever order they arrive in: every id any of them lists survives.
[Test]
public void EntriesThatShareAnIdMergeTheirCompatibleIdsInEitherOrder()
{
CultSchemaCatalogEntry Entry(params string[] compatible) => new()
{
SchemaId = "x", SchemaName = "n", SchemaVersion = "n.v1", ContentHash = "h", CompatibleSchemaIds = compatible
};
var plain = Entry("x");
var wide = Entry("x", "y");
foreach (var order in new[] { new[] { plain, wide }, new[] { wide, plain } })
foreach (var preferLast in new[] { false, true })
{
var merged = CultSchemaCatalogEntry.MergeById(order, preferLast).Single();
Assert.That(merged.CompatibleSchemaIds, Is.EquivalentTo(new[] { "x", "y" }));
}
}
// A directory manifest in a format the directory store does not read is refused with the typed exception, naming it.
[Test]
public void ADirectoryManifestInAnotherFormatIsRefusedNamingIt()
{
var path = Path.Combine(_directory, "wrong-format.cc");
File.WriteAllBytes(path, File.ReadAllBytes(Path.Combine(VectorRoot(), "..", "v3-base.msgpack")));
Assert.That(
() => CultCacheMessagePack.Create(path, new CultCacheOpenOptions { Registry = Registry, UseDirectoryStore = true }),
Throws.TypeOf<CultStoreUnreadableException>().With.Property(nameof(CultStoreUnreadableException.Path)).EqualTo(path));
}
// A commit that lands onto the file as it is keeps the header the file carries: a store already v3 stays v3.
[TestCase("../v3-base.msgpack", "cultcache.store.v3")]
[TestCase("compatible-id-only-v3.bin", "cultcache.store.v3")]

View file

@ -61,6 +61,8 @@ public sealed class CultMeshVariantRefusalTests
[TestCase("current-catalog-bad-canonical.msgpack")]
[TestCase("current-catalog-bad-members.msgpack")]
[TestCase("current-catalog-bad-compat.msgpack")]
[TestCase("current-catalog-bad-slot5-nil.msgpack")]
[TestCase("current-catalog-bad-slot5-int.msgpack")]
public void ReadSingleFileDocument_RefusesAMalformedCurrentCatalogEntry(string vector)
{
Refusal(vector).Path.Should().Be(VectorPath(vector));

View file

@ -18,6 +18,10 @@ at test time. Run: python generate.py (needs msgpack).
v1 header, plain records, and the first catalog entry of the current layout with one slot
malformed (canonical schema json an int; members an int; a compatible id an int). Not the
older layout, so CultMesh refuses them as CultCache does
current-catalog-bad-slot5-nil.msgpack
current-catalog-bad-slot5-int.msgpack
the same, with slot 5 (the compatible ids) nil or an integer: neither is a string, so neither is
the older layout
v1-base.msgpack NOT generated here: written once by the Python runtime at CultLib
69a21bb (SingleFileMessagePackBackingStore.push of alpha and
beta, type vectors.item, before any C0 code existed)
@ -60,6 +64,8 @@ for name, entry in (
("current-catalog-bad-canonical", current[:4] + [5]),
("current-catalog-bad-members", current[:6] + [5]),
("current-catalog-bad-compat", current[:5] + [[7]] + current[6:]),
("current-catalog-bad-slot5-nil", current[:5] + [None] + current[6:]),
("current-catalog-bad-slot5-int", current[:5] + [7] + current[6:]),
):
# One catalog entry and the records that use it: the older-layout reader takes an entry's slot 5 for a string, so a second
# current-layout entry would make it refuse for that reason, not for the malformed slot under test.

View file

@ -41,6 +41,8 @@ vectors = {
"missing-schema-versioned-v3": pack([base[0], [], [record[:3] + [pack(["vectors.item.v1", "n", 1])] for record in base[2]]]),
# The record names its schema by an id the catalog publishes only as a compatible id of an entry with another id.
"compatible-id-only-v3": pack([base[0], [[base[1][0][0] + ".next"] + base[1][0][1:]], base[2]]),
# An id that one entry owns and a later entry lists as compatible names the entry that owns it (here, vectors.item).
"own-id-over-compatible-v3": pack([base[0], base[1] + [["vectors.item.next", "vectors.other", "vectors.other.v1", "vectors.item.next", "{}", ["vectors.item"], []]], base[2]]),
# v3-base plus a variant of alpha: a fifth record slot, [baseKey, overrides[]], over an empty payload, overriding the name. Only C# reads it.
"variant-slot-v3": pack([base[0], base[1], base[2] + [["gamma"] + base[2][0][1:3] + [b"", ["alpha", [[0, [[0, ""]], "", "gamma"]]]]]]),
# v3-base with a fourth top-level slot after the records.

View file

@ -24,3 +24,4 @@ missing-schema-v3.bin refuses refuses refuses refuses
variant-slot-v3.bin reads refuses refuses refuses
missing-schema-versioned-v3.bin refuses refuses refuses refuses
compatible-id-only-v3.bin reads reads reads reads
own-id-over-compatible-v3.bin reads reads reads reads

View file

@ -0,0 +1 @@
“²cultcache.store.v3’—¬vectors.item¬vectors.item¯vectors.item.v1¬vectors.itemÙL{"schemaName":"vectors.item","schemaVersion":"vectors.item.v1","members":[]}‘¬vectors.item<65>—±vectors.item.next­vectors.other°vectors.other.v1±vectors.item.next¢{}‘¬vectors.item<65>’”¥alpha¬vectors.item¹2026-09-29T00:00:00+00:00Ä’¥alpha”¤beta¬vectors.item¹2026-09-29T00:00:01+00:00Ä’¤beta