C# header: one function decides it for every writer; a store's own ids are the only source

CacheBackingStore.HeaderFor(holdsIds, existingHeader, wholeStore, directoryStore) replaces FormatFor,
DirectoryFormatFor and the writers' private marker logic. A writer that rewrites the whole store
decides by content; a writer that touches part of it keeps a header already marked. Flush,
unconditional and conditional commit, the directory store and CultMesh's single-file write all call
it. A typed CultMesh write replaces the file with a document it can see, so it decides by content;
a raw payload is opaque and keeps a marked file marked.

A record's HoldsIds is what its stored form persists: a load keeps a variant's delta as read, so
the ids a load mints in an override exist only in memory and no longer mark the store. A
conditional commit onto the file no longer reads this cache's view of what the file held, so a
stale view cannot over-mark it. IdPlan.HoldsIds is derived from HeldIds and the fills.

Reverts InternalsVisibleTo GameCult.Caching.MessagePack and the public DirectoryFormatV4/V5
constants: the directory store reaches the decision through the protected member it inherits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-29 21:54:01 +02:00
commit 41d0dd9bfb
7 changed files with 164 additions and 70 deletions

View file

@ -62,8 +62,9 @@ public sealed class CultMeshSingleFileElementIdTests
.Should().Equal(publication.Representations.Select(entry => entry.Id));
}
// A typed write replaces the whole file with a document it can see, so the ids that document holds decide the header.
[Test]
public void TypedWriteOfADocumentHoldingNoIdStaysV1AndAMarkedFileStaysMarked()
public void TypedWriteDecidesTheHeaderByTheDocumentItWritesEvenOverAMarkedFile()
{
var path = Path_("none.cc");
CultMesh.WriteSingleFileDocument(path, Key, Publication());
@ -72,7 +73,24 @@ public sealed class CultMeshSingleFileElementIdTests
CultMesh.WriteSingleFileDocument(path, Key, Publication(Descriptor()));
HeaderOf(path).Should().Be("cultcache.store.v3");
CultMesh.WriteSingleFileDocument(path, Key, Publication());
HeaderOf(path).Should().Be("cultcache.store.v3", "a file already marked on disk stays marked");
HeaderOf(path).Should().Be("cultcache.store.v1", "the whole file is replaced by a document that holds no id");
}
// A raw payload is opaque: the writer cannot see what it holds, so a marked file stays marked.
[Test]
public void RawPayloadWriteOverAMarkedFileKeepsItMarkedAndOverAnUnmarkedOneStaysV1()
{
var path = Path_("raw.cc");
var schema = new CultMeshSingleFileDocumentSchema("raw:schema", "RawSchema", "1");
var payload = new byte[] { 0x90 };
CultMesh.WriteSingleFileDocumentPayload(path, Key, schema, null, payload);
HeaderOf(path).Should().Be("cultcache.store.v1");
CultMesh.WriteSingleFileDocument(path, Key, Publication(Descriptor()));
HeaderOf(path).Should().Be("cultcache.store.v3");
CultMesh.WriteSingleFileDocumentPayload(path, Key, schema, null, payload);
HeaderOf(path).Should().Be("cultcache.store.v3", "the payload's ids are not the writer's to see");
}
[Test]