From 13401928b2e7f473dcb3df614be7878e063b309e Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 3 Oct 2026 12:06:32 +0200 Subject: [PATCH] Tests: a staged record's catalog entry is the writer's encoding, not the file's slice The store chooses carried catalog slices by the entry object the read produced. Keyed by schema id instead, a type whose id is unchanged but whose entry changed (a compatible id added) would have the file's old entry written over its own. The test stages a WsItem over a file whose ItemId entry carries an unread slot and asserts the writer's encoding lands, in both store kinds. Closes variants:finding:cut-c2a-content-version.s3.catalog-writer-entry-unpinned. Co-Authored-By: Claude Opus 5.5 --- tests/GameCult.Caching.Tests/WriteSetTests.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/GameCult.Caching.Tests/WriteSetTests.cs b/tests/GameCult.Caching.Tests/WriteSetTests.cs index f00c192a..37217aef 100644 --- a/tests/GameCult.Caching.Tests/WriteSetTests.cs +++ b/tests/GameCult.Caching.Tests/WriteSetTests.cs @@ -1032,6 +1032,24 @@ namespace GameCult.Caching.Tests Assert.That(StoreSlices.CatalogEntry(path, ItemId), Is.EqualTo(entry)); } + // The catalog entry for a staged record's id is the writer's, encoded from its object, even where the file publishes another + // entry under that id: a type that adds a compatible id keeps its id, and only the writer's entry carries the change. Here the + // file's ItemId entry differs from the writer's by a slot this runtime does not read, and a WsItem is staged. + [Test] + public void ACatalogEntryForAStagedRecordsIdIsTheWritersEncodingNotTheFilesSlice([Values] bool directory, [Values] bool commit) + { + var path = PathOf("catalog-writer-entry.cc"); + Seed(path, directory, "a"); + var writers = StoreSlices.CatalogEntry(path, ItemId); + File.WriteAllBytes(path, AddAnUnreadSlotToEveryCatalogEntry(File.ReadAllBytes(path))); + Assert.That(StoreSlices.CatalogEntry(path, ItemId), Is.Not.EqualTo(writers)); + using var cache = Open(path, directory); + + Land(cache, commit, typeof(WsItem), new WsItem { Name = "name-x" }, X); + + Assert.That(StoreSlices.CatalogEntry(path, ItemId), Is.EqualTo(writers)); + } + // The same store with every catalog entry one slot longer than this runtime reads, as a newer writer's would be. private static byte[] AddAnUnreadSlotToEveryCatalogEntry(byte[] bytes) {