C#: compatible schema ids publish a schema on open, Mesh takes only the older layout, the refusal names its file

A record whose schema id the catalog lists only as a compatible id now opens (the cache resolved a persisted schema by entry id
alone). CultMesh's fallback to the older catalog-entry reader fires only for a store in that layout, decided by the entry's slot 5,
not for any decode failure, so a current-layout store with a malformed slot is refused as CultCache refuses it.
CultStoreUnreadableException.Path names the refused file. New vectors: compatible-id-only-v3 (accepted by all four) and three
current-layout catalogs with one malformed slot. The contract states the writer's invariant.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-30 06:54:17 +02:00
commit 969d78de39
16 changed files with 118 additions and 16 deletions

View file

@ -123,6 +123,15 @@ namespace GameCult.Caching.Tests
Assert.That(Refusal("unknown-header.msgpack"), Does.Contain("cultcache.store.v9"));
}
// Slots of the current catalog layout that do not decode are refused by name, as a malformed store is.
[TestCase("current-catalog-bad-canonical.msgpack")]
[TestCase("current-catalog-bad-members.msgpack")]
[TestCase("current-catalog-bad-compat.msgpack")]
public void SingleFileRefusesAMalformedCurrentCatalogEntry(string vector)
{
Assert.That(Refusal(vector), Is.Not.Empty);
}
[Test]
public void SingleFileRefusesExtraRecordSlotNamingTheRecord()
{

View file

@ -71,7 +71,7 @@ namespace GameCult.Caching.Tests
if (reads)
Assert.DoesNotThrow(Open);
else
Assert.That(Open, Throws.TypeOf<CultStoreUnreadableException>());
Assert.That(Open, Throws.TypeOf<CultStoreUnreadableException>().With.Property(nameof(CultStoreUnreadableException.Path)).EqualTo(path));
}
[TestCaseSource(nameof(Vectors))]
@ -116,6 +116,7 @@ namespace GameCult.Caching.Tests
// 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")]
[TestCase("zero-byte.bin", "cultcache.store.v1")]
[TestCase("empty-array.bin", "cultcache.store.v1")]
public void AConditionalCommitOntoAReadableFileKeepsItsHeader(string vector, string header)

View file

@ -56,6 +56,16 @@ public sealed class CultMeshVariantRefusalTests
Refusal("legacy-catalog-trailing.msgpack").Message.Should().Contain("after its MessagePack array");
}
// A store in the current layout with one catalog slot malformed is refused as CultCache refuses it. It is not the older layout,
// so it is not read with the older reader, which would take the malformed canonical schema slot for a slot to skip.
[TestCase("current-catalog-bad-canonical.msgpack")]
[TestCase("current-catalog-bad-members.msgpack")]
[TestCase("current-catalog-bad-compat.msgpack")]
public void ReadSingleFileDocument_RefusesAMalformedCurrentCatalogEntry(string vector)
{
Refusal(vector).Path.Should().Be(VectorPath(vector));
}
// Q6: CultMesh does not resolve variants. It refuses a variant key naming it and its base, and still reads the plain
// records of the same v2 store.
[Test]

View file

@ -12,6 +12,12 @@ at test time. Run: python generate.py (needs msgpack).
legacy reader accepts
legacy-catalog-trailing.msgpack legacy-catalog-plain plus three bytes after the array: one array is
required of the legacy layout too
current-catalog-bad-canonical.msgpack
current-catalog-bad-members.msgpack
current-catalog-bad-compat.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
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)
@ -49,3 +55,10 @@ write("legacy-catalog-extra-slot.msgpack",
write("legacy-catalog-plain.msgpack", [header, [legacy(entry) for entry in catalog], records])
(here / "legacy-catalog-trailing.msgpack").write_bytes(
msgpack.packb([header, [legacy(entry) for entry in catalog], records], use_bin_type=True) + b"\x01\x02\x03")
current = catalog[0]
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:]),
):
write(name + ".msgpack", [header, [entry] + catalog[1:], records])

View file

@ -0,0 +1 @@
“²cultcache.store.v3‘—±vectors.item.next¬vectors.item¯vectors.item.v1¬vectors.itemÙL{"schemaName":"vectors.item","schemaVersion":"vectors.item.v1","members":[]}‘¬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

View file

@ -39,6 +39,8 @@ vectors = {
"missing-schema-v3": pack([base[0], [], base[2]]),
# The same, with each payload opening with its schema version: no runtime recovers a schema from a payload.
"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]]),
# 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

@ -23,3 +23,4 @@ extra-top-slot.bin refuses refuses refuses refuses
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