From 10d012186a0928cfd5cabf9b64011d2ff78859bb Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 27 Oct 2026 06:15:10 +0100 Subject: [PATCH] Test: owned drift variants run on the single-file store with a codec Co-Authored-By: Claude Sonnet 5.5 --- .../RestampOnWriteTests.cs | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/tests/GameCult.Caching.Tests/RestampOnWriteTests.cs b/tests/GameCult.Caching.Tests/RestampOnWriteTests.cs index cf72b7e9..c3de7dc6 100644 --- a/tests/GameCult.Caching.Tests/RestampOnWriteTests.cs +++ b/tests/GameCult.Caching.Tests/RestampOnWriteTests.cs @@ -328,56 +328,62 @@ namespace GameCult.Caching.Tests return cache; } - // A base and a variant of it, written by a writer that knew Narrow; Grown then reads the variant whole as compatible drift. - private string SeedNarrowVariant(bool directory) + private string StoredIdOfVariantStore(string path, CultDocumentRegistry registry, CultRecordKey key) { - var path = Path.Combine(_directory, directory ? "store" : "store.cc"); - using var cache = OpenWithCodec(path, directory, NarrowRegistry); + using var cache = OpenWithCodec(path, false, registry); + return cache.GetStored(key)!.StoredSchemaId; + } + + // A base and a variant of it, written by a writer that knew Narrow; Grown then reads the variant whole as compatible drift. + private string SeedNarrowVariant() + { + var path = Path.Combine(_directory, "store.cc"); + using var cache = OpenWithCodec(path, false, NarrowRegistry); Assert.That(cache.Commit(batch => batch.Upsert(new NoteNarrow { Name = "base", Value = 1 }, new CultRecordHandle(Base))), Is.True); Assert.That(cache.Commit(batch => batch.UpsertVariant(Delta, Base, new[] { cache.Override("Name", "delta"), cache.Override("Value", 5) })), Is.True); return path; } - // The staging half asks the flag ToStoredDocument set on a loaded variant, and Resolved and Flatten carry it on: an owned + // Variants live in a single file (the directory store refuses them). The staging half asks the flag ToStoredDocument set on a loaded variant, and Resolved and Flatten carry it on: an owned // drift variant is rewritten, flattened and removed like a plain drift record, restamping only what is written. - [TestCaseSource(nameof(StoreKinds))] - public async Task AnOwnedDriftVariantIsRewritten(bool directory) + [Test] + public async Task AnOwnedDriftVariantIsRewritten() { - var path = SeedNarrowVariant(directory); - using (var cache = OpenWithCodec(path, directory, GrownRegistry)) + var path = SeedNarrowVariant(); + using (var cache = OpenWithCodec(path, false, GrownRegistry)) { await cache.PullAllBackingStoresAsync(); Assert.That(cache.Commit(batch => batch.UpsertVariant(Delta, Base, new[] { cache.Override("Name", "delta"), cache.Override("Value", 6) })), Is.True); } - Assert.That(StoredIdOf(path, directory, GrownRegistry, Delta), Is.EqualTo(GrownRegistry.GetRequired().SchemaId)); - Assert.That(StoredIdOf(path, directory, NarrowRegistry, Base), Is.EqualTo(NarrowRegistry.GetRequired().SchemaId), "the base was not written"); + Assert.That(StoredIdOfVariantStore(path, GrownRegistry, Delta), Is.EqualTo(GrownRegistry.GetRequired().SchemaId)); + Assert.That(StoredIdOfVariantStore(path, NarrowRegistry, Base), Is.EqualTo(NarrowRegistry.GetRequired().SchemaId), "the base was not written"); } - [TestCaseSource(nameof(StoreKinds))] - public async Task AnOwnedDriftVariantIsFlattened(bool directory) + [Test] + public async Task AnOwnedDriftVariantIsFlattened() { - var path = SeedNarrowVariant(directory); - using (var cache = OpenWithCodec(path, directory, GrownRegistry)) + var path = SeedNarrowVariant(); + using (var cache = OpenWithCodec(path, false, GrownRegistry)) { await cache.PullAllBackingStoresAsync(); Assert.That(cache.Commit(batch => batch.Flatten(Delta)), Is.True); } - Assert.That(StoredIdOf(path, directory, GrownRegistry, Delta), Is.EqualTo(GrownRegistry.GetRequired().SchemaId)); + Assert.That(StoredIdOfVariantStore(path, GrownRegistry, Delta), Is.EqualTo(GrownRegistry.GetRequired().SchemaId)); } - [TestCaseSource(nameof(StoreKinds))] - public async Task AnOwnedDriftVariantIsRemoved(bool directory) + [Test] + public async Task AnOwnedDriftVariantIsRemoved() { - var path = SeedNarrowVariant(directory); - using (var cache = OpenWithCodec(path, directory, GrownRegistry)) + var path = SeedNarrowVariant(); + using (var cache = OpenWithCodec(path, false, GrownRegistry)) { await cache.PullAllBackingStoresAsync(); Assert.That(cache.Commit(batch => batch.Remove(Delta)), Is.True); } - using var reopened = OpenWithCodec(path, directory, GrownRegistry); + using var reopened = OpenWithCodec(path, false, GrownRegistry); await reopened.PullAllBackingStoresAsync(); Assert.That(reopened.GetStored(Delta), Is.Null); Assert.That(reopened.GetStored(Base), Is.Not.Null);