From b6905c2c1cc500915277d8cd07a82731e615c3a0 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 13 Sep 2026 17:17:14 +0200 Subject: [PATCH] Pin stores written before Cut 2 with checked-in fixtures Fixtures were produced by CultLib 0db1fe5 from a temporary worktree: a v4 directory store and a v1 single-file store holding the same three records. Tests reopen both and assert every value, and assert the directory store refuses v1, v1.directory, v2 and v3 manifests without touching the bytes. Co-Authored-By: Claude Opus 5 --- .../Fixtures/pre-cut2/README.md | 29 +++++ .../Fixtures/pre-cut2/directory-v4/store.cc | Bin 0 -> 1742 bytes ...8abb8d7c46b93d1641c5376058c7791ed6.msgpack | 1 + ...f6d4c01a23593138a2eab02d710e79d6f8.msgpack | 1 + ...115819fc978c9ea677ebb76d69505a26e1.msgpack | 2 + .../pre-cut2/single-file-v1/store.msgpack | Bin 0 -> 1651 bytes .../GameCult.Caching.Tests.csproj | 4 + .../PreCut2FixtureDocuments.cs | 23 ++++ .../PreCut2StoreFormatTests.cs | 120 ++++++++++++++++++ 9 files changed, 180 insertions(+) create mode 100644 tests/GameCult.Caching.Tests/Fixtures/pre-cut2/README.md create mode 100644 tests/GameCult.Caching.Tests/Fixtures/pre-cut2/directory-v4/store.cc create mode 100644 tests/GameCult.Caching.Tests/Fixtures/pre-cut2/directory-v4/store.cc.records/26abbda63fe4c502d2ec3ec61481d08abb8d7c46b93d1641c5376058c7791ed6.msgpack create mode 100644 tests/GameCult.Caching.Tests/Fixtures/pre-cut2/directory-v4/store.cc.records/538952c2d5f600e672b4184d9fc00cf6d4c01a23593138a2eab02d710e79d6f8.msgpack create mode 100644 tests/GameCult.Caching.Tests/Fixtures/pre-cut2/directory-v4/store.cc.records/7724612992b5cda71fd6a663e30c5e115819fc978c9ea677ebb76d69505a26e1.msgpack create mode 100644 tests/GameCult.Caching.Tests/Fixtures/pre-cut2/single-file-v1/store.msgpack create mode 100644 tests/GameCult.Caching.Tests/PreCut2FixtureDocuments.cs create mode 100644 tests/GameCult.Caching.Tests/PreCut2StoreFormatTests.cs diff --git a/tests/GameCult.Caching.Tests/Fixtures/pre-cut2/README.md b/tests/GameCult.Caching.Tests/Fixtures/pre-cut2/README.md new file mode 100644 index 00000000..2ba005f2 --- /dev/null +++ b/tests/GameCult.Caching.Tests/Fixtures/pre-cut2/README.md @@ -0,0 +1,29 @@ +# Pre-Cut 2 store fixtures + +Bytes written by CultLib commit `0db1fe5` ("Apply Soul fixes to the store +composition docs and routing tests"), the last commit before Cut 2 changed the +MessagePack stores. They prove stores written before Cut 2 still open. + +Produced from a temporary git worktree at `0db1fe5`: a throwaway NUnit fixture +in that worktree's `tests/GameCult.Caching.Tests`, referencing its own Caching +projects and generator, upserted three records into a fresh `CultCache` and +called `FlushAllBackingStores()`. The worktree was removed afterwards. + +- `directory-v4/store.cc` plus `directory-v4/store.cc.records/*.msgpack`: + `new DirectoryMessagePackBackingStore(manifest)`, format + `cultcache.store.v4.directory-content-addressed-pages`. The empty + `.commit.lock` lease file was not copied. +- `single-file-v1/store.msgpack`: `new SingleFileMessagePackBackingStore(file)`, + format `cultcache.store.v1`. + +Both stores hold the same records. Document types are defined identically in +`../../PreCut2FixtureDocuments.cs`: + +| Key | Type (schema) | Values | +| --- | --- | --- | +| `item:anvil` | `PreCut2FixtureItem` (`fixtures.precut2.item.v1`) | `Name = "anvil"`, `Count = 3` | +| `item:bellows` | `PreCut2FixtureItem` (`fixtures.precut2.item.v1`) | `Name = "bellows"`, `Count = 42` | +| `note:origin` | `PreCut2FixtureNote` (`fixtures.precut2.note.v1`) | `Text = "written before cut 2"` | + +Do not regenerate these from a newer commit; their value is that they predate +Cut 2. Tests copy them to a temp directory before opening. diff --git a/tests/GameCult.Caching.Tests/Fixtures/pre-cut2/directory-v4/store.cc b/tests/GameCult.Caching.Tests/Fixtures/pre-cut2/directory-v4/store.cc new file mode 100644 index 0000000000000000000000000000000000000000..8dda080c70f95f0d48f70a0c02c1faab68ce70d9 GIT binary patch literal 1742 zcmcJPPiRy}9LJ+)DHNp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ODMCyYx}&Ku2@7C?zm+7ju6_23or30Iov z&M|-k=O~?Lw(duqXLh`Lo>?O$0|8!IVuh3e1h-rR<5YNN6xB|<+;fG3BWeuHduqT@ zk@yYB<;m}VAv;z~Lpxo z*m|R^{u`Pn4;f)FLoxh?HG_^;FX(Jx&e%)-!7_nY-7}DFam|lQI F_6Kf|BH#c3 literal 0 HcmV?d00001 diff --git a/tests/GameCult.Caching.Tests/GameCult.Caching.Tests.csproj b/tests/GameCult.Caching.Tests/GameCult.Caching.Tests.csproj index 6e8ec411..4b3d92d3 100644 --- a/tests/GameCult.Caching.Tests/GameCult.Caching.Tests.csproj +++ b/tests/GameCult.Caching.Tests/GameCult.Caching.Tests.csproj @@ -14,6 +14,10 @@ ReferenceOutputAssembly="false" /> + + + + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/tests/GameCult.Caching.Tests/PreCut2FixtureDocuments.cs b/tests/GameCult.Caching.Tests/PreCut2FixtureDocuments.cs new file mode 100644 index 00000000..4598b7a5 --- /dev/null +++ b/tests/GameCult.Caching.Tests/PreCut2FixtureDocuments.cs @@ -0,0 +1,23 @@ +using GameCult.Caching; +using MessagePack; + +namespace GameCult.Caching.Tests +{ + [CultDocument("fixtures.precut2.item", "fixtures.precut2.item.v1")] + internal sealed class PreCut2FixtureItem + { + [Key(0)] + [CultName] + public string Name = string.Empty; + + [Key(1)] + public int Count; + } + + [CultDocument("fixtures.precut2.note", "fixtures.precut2.note.v1")] + internal sealed class PreCut2FixtureNote + { + [Key(0)] + public string Text = string.Empty; + } +} diff --git a/tests/GameCult.Caching.Tests/PreCut2StoreFormatTests.cs b/tests/GameCult.Caching.Tests/PreCut2StoreFormatTests.cs new file mode 100644 index 00000000..3b442cf3 --- /dev/null +++ b/tests/GameCult.Caching.Tests/PreCut2StoreFormatTests.cs @@ -0,0 +1,120 @@ +#nullable enable +using System; +using System.IO; +using System.Threading.Tasks; +using GameCult.Caching; +using GameCult.Caching.MessagePack; +using NUnit.Framework; + +namespace GameCult.Caching.Tests +{ + public class PreCut2StoreFormatTests + { + private static string FixtureRoot => + Path.Combine(TestContext.CurrentContext.TestDirectory, "Fixtures", "pre-cut2"); + + private static string CopyFixture(string name) + { + var target = Path.Combine(Path.GetTempPath(), $"cultlib-precut2-{Guid.NewGuid():N}"); + var source = Path.Combine(FixtureRoot, name); + foreach (var file in Directory.GetFiles(source, "*", SearchOption.AllDirectories)) + { + var destination = Path.Combine(target, Path.GetRelativePath(source, file)); + Directory.CreateDirectory(Path.GetDirectoryName(destination)!); + File.Copy(file, destination); + } + return target; + } + + private static void AssertFixtureRecords(CultCache cache) + { + Assert.That(cache.Get(new CultRecordKey("item:anvil")), Is.Not.Null); + Assert.That(cache.Get(new CultRecordKey("item:anvil"))!.Name, Is.EqualTo("anvil")); + Assert.That(cache.Get(new CultRecordKey("item:anvil"))!.Count, Is.EqualTo(3)); + Assert.That(cache.Get(new CultRecordKey("item:bellows"))?.Name, Is.EqualTo("bellows")); + Assert.That(cache.Get(new CultRecordKey("item:bellows"))?.Count, Is.EqualTo(42)); + Assert.That(cache.Get(new CultRecordKey("note:origin"))?.Text, + Is.EqualTo("written before cut 2")); + Assert.That(cache.GetAll(), Has.Length.EqualTo(2)); + Assert.That(cache.GetAll(), Has.Length.EqualTo(1)); + } + + [Test] + public async Task DirectoryStoreOpensV4ManifestWrittenBeforeCut2() + { + var root = CopyFixture("directory-v4"); + try + { + var manifest = Path.Combine(root, "store.cc"); + Assert.That(CultDocumentMessagePackSerialization.DeserializeSnapshot(File.ReadAllBytes(manifest)).FormatVersion, + Is.EqualTo("cultcache.store.v4.directory-content-addressed-pages")); + + using var cache = new CultCache(); + cache.AddBackingStore(new DirectoryMessagePackBackingStore(manifest)); + await cache.PullAllBackingStoresAsync(); + + AssertFixtureRecords(cache); + } + finally + { + if (Directory.Exists(root)) Directory.Delete(root, recursive: true); + } + } + + [Test] + public async Task SingleFileOpensV1SnapshotWrittenBeforeCut2() + { + var root = CopyFixture("single-file-v1"); + try + { + var file = Path.Combine(root, "store.msgpack"); + Assert.That(CultDocumentMessagePackSerialization.DeserializeSnapshot(File.ReadAllBytes(file)).FormatVersion, + Is.EqualTo("cultcache.store.v1")); + + using var cache = new CultCache(); + cache.AddBackingStore(new SingleFileMessagePackBackingStore(file)); + await cache.PullAllBackingStoresAsync(); + + AssertFixtureRecords(cache); + } + finally + { + if (Directory.Exists(root)) Directory.Delete(root, recursive: true); + } + } + + // Format strings taken from DirectoryMessagePackBackingStore.cs at 0db1fe5. + [TestCase("cultcache.store.v1")] + [TestCase("cultcache.store.v1.directory")] + [TestCase("cultcache.store.v2.directory-indexed")] + [TestCase("cultcache.store.v3.directory-immutable-pages")] + public void DirectoryStoreRefusesNonV4Manifest(string formatVersion) + { + var root = Path.Combine(Path.GetTempPath(), $"cultlib-refuse-{Guid.NewGuid():N}"); + var manifest = Path.Combine(root, "store.cc"); + Directory.CreateDirectory(root); + try + { + var bytes = CultDocumentMessagePackSerialization.SerializeSnapshot(new CultPersistedStoreSnapshot + { + FormatVersion = formatVersion, + SchemaCatalog = Array.Empty(), + Records = Array.Empty() + }); + File.WriteAllBytes(manifest, bytes); + + using var cache = new CultCache(); + var store = new DirectoryMessagePackBackingStore(manifest); + cache.AddBackingStore(store); + + Assert.That(() => store.PullAll(), + Throws.TypeOf().With.Message.Contains(formatVersion)); + Assert.That(File.ReadAllBytes(manifest), Is.EqualTo(bytes)); + } + finally + { + if (Directory.Exists(root)) Directory.Delete(root, recursive: true); + } + } + } +}