Merge variants C0: every reader refuses what C1 will write, by name
C#, TypeScript, Python, Rust and CultMesh refuse an unknown cultcache.store.* header and a fifth record slot, naming the version or the key and schemaId. The silent slot-skipping and C#'s ignored header are deleted, and CultMesh's second record decoder is gone. Shared vectors are in tests/vectors/document-variants-c0/. v1 stores stay byte-identical. At base, the single-file commit's read-modify-write rewrote a v2 store as v1, which lost data; it now refuses. Soul passed it. Cross-runtime interop was run and passes. Three C# Caching tests fail on Linux at both base and tip: they are Windows share-mode tests (a FileShare.Read handle blocking delete/replace), which cannot pass on Linux. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
e382bb4e20
20 changed files with 471 additions and 44 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#nullable enable
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using GameCult.Caching;
|
||||
using GameCult.Caching.MessagePack;
|
||||
|
|
@ -83,6 +84,82 @@ namespace GameCult.Caching.Tests
|
|||
}
|
||||
}
|
||||
|
||||
// Shared refusal vectors: tests/vectors/document-variants-c0, read by every runtime's tests.
|
||||
private const string ItemSchemaId = "sha256:88d3fdf0a927acf3b163940d8f8c7fe62b3316542ce771a67ec8bc038f594788";
|
||||
|
||||
private static string VectorPath(string name)
|
||||
{
|
||||
for (var dir = new DirectoryInfo(TestContext.CurrentContext.TestDirectory); dir != null; dir = dir.Parent)
|
||||
{
|
||||
var candidate = Path.Combine(dir.FullName, "tests", "vectors", "document-variants-c0", name);
|
||||
if (File.Exists(candidate)) return candidate;
|
||||
}
|
||||
throw new FileNotFoundException($"Shared vector {name} not found above {TestContext.CurrentContext.TestDirectory}.");
|
||||
}
|
||||
|
||||
private static string Refusal(string vector)
|
||||
{
|
||||
var root = Path.Combine(Path.GetTempPath(), $"cultlib-vector-{Guid.NewGuid():N}");
|
||||
Directory.CreateDirectory(root);
|
||||
try
|
||||
{
|
||||
var file = Path.Combine(root, "store.msgpack");
|
||||
File.Copy(VectorPath(vector), file);
|
||||
using var cache = new CultCache();
|
||||
var error = Assert.Catch(() => cache.AddBackingStore(new SingleFileMessagePackBackingStore(file)));
|
||||
Assert.That(error, Is.Not.Null);
|
||||
Assert.That(error!.ToString(), Does.Contain(nameof(NotSupportedException)));
|
||||
return error.ToString();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (Directory.Exists(root)) Directory.Delete(root, recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SingleFileRefusesUnknownHeaderByName()
|
||||
{
|
||||
Assert.That(Refusal("unknown-header.msgpack"), Does.Contain("cultcache.store.v9"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SingleFileRefusesExtraRecordSlotNamingTheRecord()
|
||||
{
|
||||
var message = Refusal("extra-slot-full-payload.msgpack");
|
||||
Assert.That(message, Does.Contain("item:anvil"));
|
||||
Assert.That(message, Does.Contain(ItemSchemaId));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SingleFileRefusesVariantStoreByVersionOrRecord()
|
||||
{
|
||||
Assert.That(Refusal("variant-v2.msgpack"),
|
||||
Does.Contain("cultcache.store.v2").Or.Contain("item:anvil-big"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SnapshotWithoutAFormatVersionIsRefusedNotDefaultedToV1()
|
||||
{
|
||||
// [nil, [], []]
|
||||
var bytes = new byte[] { 0x93, 0xc0, 0x90, 0x90 };
|
||||
|
||||
Assert.That(() => CultDocumentMessagePackSerialization.DeserializeSnapshot(bytes),
|
||||
Throws.TypeOf<NotSupportedException>().With.Message.Contains("format version"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void V1StoreWrittenAtTheBaseCommitStillDecodesByteForByte()
|
||||
{
|
||||
var snapshot = CultDocumentMessagePackSerialization.DeserializeSnapshot(File.ReadAllBytes(VectorPath("v1-base.msgpack")));
|
||||
CultDocumentMessagePackSerialization.RequireSingleFileFormat(snapshot);
|
||||
|
||||
Assert.That(snapshot.FormatVersion, Is.EqualTo("cultcache.store.v1"));
|
||||
Assert.That(snapshot.Records.Select(record => record.Key), Is.EqualTo(new[] { "alpha", "beta" }));
|
||||
Assert.That(snapshot.Records[0].Payload, Is.EqualTo(new byte[] { 0x92, 0xa5, (byte)'a', (byte)'l', (byte)'p', (byte)'h', (byte)'a', 0x01 }));
|
||||
Assert.That(snapshot.Records[1].Payload, Is.EqualTo(new byte[] { 0x92, 0xa4, (byte)'b', (byte)'e', (byte)'t', (byte)'a', 0x02 }));
|
||||
}
|
||||
|
||||
// Format strings taken from DirectoryMessagePackBackingStore.cs at 0db1fe5.
|
||||
[TestCase("cultcache.store.v1")]
|
||||
[TestCase("cultcache.store.v1.directory")]
|
||||
|
|
|
|||
54
tests/GameCult.Mesh.Tests/CultMeshVariantRefusalTests.cs
Normal file
54
tests/GameCult.Mesh.Tests/CultMeshVariantRefusalTests.cs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using FluentAssertions;
|
||||
using GameCult.Caching;
|
||||
using NUnit.Framework;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Mesh.Tests;
|
||||
|
||||
// Shared refusal vectors: tests/vectors/document-variants-c0, read by every runtime's tests.
|
||||
public sealed class CultMeshVariantRefusalTests
|
||||
{
|
||||
private const string ItemSchemaId = "sha256:88d3fdf0a927acf3b163940d8f8c7fe62b3316542ce771a67ec8bc038f594788";
|
||||
|
||||
private static string VectorPath(string name)
|
||||
{
|
||||
for (var dir = new DirectoryInfo(TestContext.CurrentContext.TestDirectory); dir != null; dir = dir.Parent)
|
||||
{
|
||||
var candidate = Path.Combine(dir.FullName, "tests", "vectors", "document-variants-c0", name);
|
||||
if (File.Exists(candidate)) return candidate;
|
||||
}
|
||||
throw new FileNotFoundException($"Shared vector {name} not found above {TestContext.CurrentContext.TestDirectory}.");
|
||||
}
|
||||
|
||||
private static NotSupportedException Refusal(string vector) =>
|
||||
Assert.Throws<NotSupportedException>(() =>
|
||||
CultMesh.ReadSingleFileDocumentPayload(VectorPath(vector), new CultRecordKey("item:bellows"), ItemSchemaId))!;
|
||||
|
||||
[Test]
|
||||
public void ReadSingleFileDocument_RefusesUnknownHeaderByName() =>
|
||||
Refusal("unknown-header.msgpack").Message.Should().Contain("cultcache.store.v9");
|
||||
|
||||
[Test]
|
||||
public void ReadSingleFileDocument_RefusesExtraRecordSlotNamingTheRecord()
|
||||
{
|
||||
var message = Refusal("extra-slot-full-payload.msgpack").Message;
|
||||
message.Should().Contain("item:anvil").And.Contain(ItemSchemaId);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReadSingleFileDocument_RefusesExtraRecordSlotInTheLegacyCatalogLayoutToo()
|
||||
{
|
||||
var message = Refusal("legacy-catalog-extra-slot.msgpack").Message;
|
||||
message.Should().Contain("item:anvil").And.Contain(ItemSchemaId);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReadSingleFileDocument_RefusesVariantStoreByVersionOrRecord()
|
||||
{
|
||||
var message = Refusal("variant-v2.msgpack").Message;
|
||||
(message.Contains("cultcache.store.v2") || message.Contains("item:anvil-big")).Should().BeTrue(message);
|
||||
}
|
||||
}
|
||||
3
tests/vectors/document-variants-c0/.gitattributes
vendored
Normal file
3
tests/vectors/document-variants-c0/.gitattributes
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Refusal vectors are byte-exact; never convert line endings.
|
||||
* binary
|
||||
*.py text
|
||||
Binary file not shown.
41
tests/vectors/document-variants-c0/generate.py
Normal file
41
tests/vectors/document-variants-c0/generate.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
"""Generates the shared C0 refusal vectors from the pre-Cut 2 v1 store (written before any
|
||||
variant code existed). Every runtime's tests read the committed bytes; nothing regenerates them
|
||||
at test time. Run: python generate.py (needs msgpack).
|
||||
|
||||
unknown-header.msgpack header cultcache.store.v9, otherwise the v1 store
|
||||
extra-slot-full-payload.msgpack v1 header, record item:anvil gains slot 4, payload stays full
|
||||
legacy-catalog-extra-slot.msgpack
|
||||
v1 header, catalog entry in the older layout (contentHash at slot
|
||||
5), so CultMesh's legacy snapshot reader takes it, plus the
|
||||
extra-slot record
|
||||
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)
|
||||
variant-v2.msgpack what C1 writes for a variant: header v2, record slot 4 =
|
||||
[baseKey, overrides[]], empty payload (override op Set = 0,
|
||||
path steps are [slot, elementId])
|
||||
"""
|
||||
import pathlib
|
||||
|
||||
import msgpack
|
||||
|
||||
here = pathlib.Path(__file__).resolve().parent
|
||||
source = here.parent.parent / "GameCult.Caching.Tests" / "Fixtures" / "pre-cut2" / "single-file-v1" / "store.msgpack"
|
||||
header, catalog, records = msgpack.unpackb(source.read_bytes(), raw=False)
|
||||
assert header == "cultcache.store.v1"
|
||||
anvil = records[0]
|
||||
assert anvil[0] == "item:anvil"
|
||||
|
||||
|
||||
def write(name, snapshot):
|
||||
(here / name).write_bytes(msgpack.packb(snapshot, use_bin_type=True))
|
||||
|
||||
|
||||
write("unknown-header.msgpack", ["cultcache.store.v9", catalog, records])
|
||||
write("extra-slot-full-payload.msgpack",
|
||||
[header, catalog, [anvil + [["item:bellows", []]]] + records[1:]])
|
||||
variant = ["item:anvil-big", anvil[1], anvil[2], b"", ["item:anvil", [[0, [[1, ""]], "", 99]]]]
|
||||
write("variant-v2.msgpack", ["cultcache.store.v2", catalog, records + [variant]])
|
||||
legacy_entry = [catalog[0][0], catalog[0][1], catalog[0][2], catalog[0][4], None, catalog[0][3], []]
|
||||
write("legacy-catalog-extra-slot.msgpack",
|
||||
[header, [legacy_entry], [anvil + [["item:bellows", []]]]])
|
||||
|
|
@ -0,0 +1 @@
|
|||
“²cultcache.store.v1‘—ÙGsha256:88d3fdf0a927acf3b163940d8f8c7fe62b3316542ce771a67ec8bc038f594788µfixtures.precut2.item¸fixtures.precut2.item.v1Úp{"schemaName":"fixtures.precut2.item","schemaVersion":"fixtures.precut2.item.v1","members":[{"slot":0,"name":"Name","type":"System.String","isReference":false,"many":false,"targetSchemaName":null,"indexAlias":null,"isName":true},{"slot":1,"name":"Count","type":"System.Int32","isReference":false,"many":false,"targetSchemaName":null,"indexAlias":null,"isName":false}]}ÀÙGsha256:dadf30bc920849ee89ed5d70cc73027070dd7571c5f878db1901f3abc459cc0c<30>‘•ªitem:anvilÙGsha256:88d3fdf0a927acf3b163940d8f8c7fe62b3316542ce771a67ec8bc038f594788Ù!2026-09-13T15:14:36.4032226+00:00Ä’¥anvil’¬item:bellows<77>
|
||||
BIN
tests/vectors/document-variants-c0/unknown-header.msgpack
Normal file
BIN
tests/vectors/document-variants-c0/unknown-header.msgpack
Normal file
Binary file not shown.
1
tests/vectors/document-variants-c0/v1-base.msgpack
Normal file
1
tests/vectors/document-variants-c0/v1-base.msgpack
Normal file
|
|
@ -0,0 +1 @@
|
|||
“²cultcache.store.v1‘—¬vectors.item¬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
|
||||
BIN
tests/vectors/document-variants-c0/variant-v2.msgpack
Normal file
BIN
tests/vectors/document-variants-c0/variant-v2.msgpack
Normal file
Binary file not shown.
Loading…
Reference in a new issue