Merge CultCache R1: typed read failures, no empty-file stores, no echoed values, typed write outcome

Only "nothing at the path" reads as an empty store; a zero-byte file is Undecodable in every
runtime; a dangling link is an I/O error. Errors name keys and schema ids only, never stored
values, and echo a header only in the cultcache.store.v<digits> shape. Single-file writes
report NotReplaced / ReplacedNotDurable / Rejected; an unlock failure after a successful write
no longer replaces the write's result.

Soul passes 1-3; batch 4 closes pass 3. Merged tree 9d9e76d4 verified on Yggdrasil: Rust
(cultcache, cultnet, cultmesh), cultcache-ts 44 including the four-runtime interop test,
cultnet-ts 198, cultcache-py 47, GameCult.Caching.Tests 346.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-30 21:13:24 +02:00
commit daedfdd658
9 changed files with 1486 additions and 165 deletions

View file

@ -167,6 +167,61 @@ namespace GameCult.Caching.Tests
Throws.TypeOf<NotSupportedException>().With.Message.Contains("format version"));
}
// Every runtime reads a store file the same way: a missing file is an empty store, an existing empty file is not
// a store (no CultCache writer leaves one), and an empty array carries no header, so it claims no format and is an
// empty store too.
[Test]
public async Task SingleFileRefusesAnEmptyFileAndOpensAMissingFileOrAnEmptyArrayAsEmpty()
{
var root = Path.Combine(Path.GetTempPath(), $"cultlib-empty-{Guid.NewGuid():N}");
Directory.CreateDirectory(root);
try
{
var empty = Path.Combine(root, "empty.msgpack");
File.WriteAllBytes(empty, Array.Empty<byte>());
using (var cache = new CultCache())
{
Assert.Catch(() => cache.AddBackingStore(new SingleFileMessagePackBackingStore(empty)));
Assert.That(cache.BackingStores, Is.Empty);
}
Assert.That(File.ReadAllBytes(empty), Is.Empty);
var emptyArray = Path.Combine(root, "empty-array.msgpack");
File.WriteAllBytes(emptyArray, new byte[] { 0x90 });
foreach (var path in new[] { Path.Combine(root, "missing.msgpack"), emptyArray })
{
using var cache = new CultCache();
cache.AddBackingStore(new SingleFileMessagePackBackingStore(path));
await cache.PullAllBackingStoresAsync();
Assert.That(cache.GetAll<PreCut2FixtureItem>(), Is.Empty, path);
}
}
finally
{
if (Directory.Exists(root)) Directory.Delete(root, recursive: true);
}
}
// A refusal echoes a header only in the shape cultcache.store.v<digits>; any other is described by its length.
[TestCase("cultcache.store.v12", true)]
[TestCase("cultcache.store.SECRET-HEADER", false)]
[TestCase("cultcache.store.v12SECRET", false)]
[TestCase("cultcache.store.v", false)]
public void SingleFileRefusalEchoesAHeaderOnlyInTheKnownShape(string header, bool echoed)
{
var snapshot = new CultPersistedStoreSnapshot { FormatVersion = header };
var error = Assert.Throws<NotSupportedException>(() => CultDocumentMessagePackSerialization.RequireSingleFileFormat(snapshot))!;
if (echoed)
{
Assert.That(error.Message, Does.Contain("format " + header + " is not"));
}
else
{
Assert.That(error.Message, Does.Not.Contain("SECRET").And.Not.Contain("format " + header + " is not"));
Assert.That(error.Message, Does.Contain($"of {header.Length} bytes"));
}
}
[Test]
public void V1StoreWrittenAtTheBaseCommitStillDecodesByteForByte()
{