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 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-03 12:06:32 +02:00
commit 13401928b2

View file

@ -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)
{