From f91e30eded8822e25518365f54c7b723ff6142cb Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 22 Oct 2026 15:39:40 +0200 Subject: [PATCH] Caching tests: a store stamped with a newer format version is refused and never rewritten Pins the release-now-c2a-bumps-format ruling's premise for 2.0.0. Co-Authored-By: Claude Sonnet 5.5 --- .../PreCut2StoreFormatTests.cs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/GameCult.Caching.Tests/PreCut2StoreFormatTests.cs b/tests/GameCult.Caching.Tests/PreCut2StoreFormatTests.cs index e9d8797d..0f64f3ff 100644 --- a/tests/GameCult.Caching.Tests/PreCut2StoreFormatTests.cs +++ b/tests/GameCult.Caching.Tests/PreCut2StoreFormatTests.cs @@ -123,6 +123,39 @@ namespace GameCult.Caching.Tests Assert.That(Refusal("unknown-header.msgpack"), Does.Contain("cultcache.store.v9")); } + // The release-now-c2a-bumps-format ruling rests on this: a store stamped with a newer format version is refused at + // open, so this runtime cannot rewrite it. The file stays byte-identical through the refusal and through later + // writes to the cache, whose refused store was never attached. + [TestCase("cultcache.store.v3")] + [TestCase("cultcache.store.v9")] + public async Task SingleFileStampedWithANewerFormatIsRefusedAndNeverRewritten(string newerFormat) + { + var root = CopyFixture("single-file-v1"); + try + { + var file = Path.Combine(root, "store.msgpack"); + var snapshot = CultDocumentMessagePackSerialization.DeserializeSnapshot(File.ReadAllBytes(file)); + snapshot.FormatVersion = newerFormat; + File.WriteAllBytes(file, CultDocumentMessagePackSerialization.SerializeSnapshot(snapshot)); + var before = File.ReadAllBytes(file); + + using var cache = new CultCache(); + var error = Assert.Throws(() => + cache.AddBackingStore(new SingleFileMessagePackBackingStore(file)))!; + Assert.That(error.Message, Does.Contain(newerFormat)); + Assert.That(cache.BackingStores, Is.Empty); + + await cache.AddAsync(new PreCut2FixtureNote { Text = "written after the refusal" }); + await cache.FlushAsync(); + + Assert.That(File.ReadAllBytes(file), Is.EqualTo(before)); + } + finally + { + if (Directory.Exists(root)) Directory.Delete(root, recursive: true); + } + } + [Test] public void SingleFileRefusesExtraRecordSlotNamingTheRecord() {