One local schema id in cultmesh-py; catalog writers merge only the same schema; a compatible entry before its owner reads as the owner

cultnet-py's resolve_document_and_schema_id_for_raw_record is replaced by resolve_document_for_raw_record, which resolves the
document only; cultmesh-py keys previous values by the local schema id, so a snapshot under a compatible id or the schema name
reports an update with its previous value. Writers (C#, TypeScript, Python) merge same-id entries only when their schema names match;
another schema's entry is dropped or the record gets a default entry under its own id, and a record's own id is claimed before an
entry that lists it as compatible. The C# single-file writer prefers the entry being written now, as the directory writer does, so
name, content hash and members come from the registered schema and the compatible ids are the union. Vector:
compatible-before-owner-v3. A cultnet-py test's schema path no longer depends on the working directory.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-30 09:01:00 +02:00
commit 59f9e9aedb
15 changed files with 278 additions and 92 deletions

View file

@ -29,15 +29,18 @@ namespace GameCult.Caching
public CultSchemaMemberCatalogEntry[] Members { get; set; } = Array.Empty<CultSchemaMemberCatalogEntry>();
// One entry per schema id, whatever order the candidates come in: entries that share an id are one schema seen by different
// writers, so the entry written lists every id any of them lists, and its other fields are the first's (or the last's).
// One entry per schema id, whatever order the candidates come in. Entries that share an id and a schema name are one schema seen
// by different writers: the merged entry takes its name, content hash and members from the entry being written now (the
// last with preferLast, else the first) and lists every id any of them lists. An entry of another schema under the same id is
// dropped, never merged: its ids are not this schema's.
internal static IEnumerable<CultSchemaCatalogEntry> MergeById(IEnumerable<CultSchemaCatalogEntry> entries, bool preferLast = false)
{
foreach (var group in entries.GroupBy(entry => entry.SchemaId, StringComparer.Ordinal))
{
var members = group.ToArray();
var chosen = preferLast ? members[^1] : members[0];
if (members.Length == 1)
var sameSchema = members.Where(entry => string.Equals(entry.SchemaName, chosen.SchemaName, StringComparison.Ordinal)).ToArray();
if (sameSchema.Length == 1)
{
yield return chosen;
continue;
@ -50,7 +53,7 @@ namespace GameCult.Caching
SchemaVersion = chosen.SchemaVersion,
ContentHash = chosen.ContentHash,
CanonicalSchemaJson = chosen.CanonicalSchemaJson,
CompatibleSchemaIds = members.SelectMany(entry => entry.CompatibleSchemaIds).Distinct(StringComparer.Ordinal).ToArray(),
CompatibleSchemaIds = sameSchema.SelectMany(entry => entry.CompatibleSchemaIds).Distinct(StringComparer.Ordinal).ToArray(),
Members = chosen.Members
};
}
@ -3664,7 +3667,7 @@ namespace GameCult.Caching
var snapshot = new CultPersistedStoreSnapshot
{
FormatVersion = HeaderFor(holdsElementIds, existingHeader, wholeStore, directoryStore: false, holdsVariants: ordered.Any(record => record.Variant != null)),
SchemaCatalog = CultSchemaCatalogEntry.MergeById(catalog)
SchemaCatalog = CultSchemaCatalogEntry.MergeById(catalog, preferLast: true)
// An entry stays while it publishes a schema id some record carries, as its own id or a compatible one.
.Where(entry => used.Contains(entry.SchemaId) || entry.CompatibleSchemaIds.Any(used.Contains))
.OrderBy(entry => entry.SchemaName, StringComparer.Ordinal)