R-Q3, R-R: v0 lowering preserves v0's pre-cut answers exactly
CultNetV0SelectionLowering.Lower collapsed a non-null-but-empty filter list to
null ("no filter"). That corrupted two pre-cut v0 behaviours the same
function feeds:
- CultNetDatabase.CreateShardSnapshotResponse and
CultNetDocumentRegistry.CreateRawSnapshotResponse (b3d9cf7) both test
`filter?.RecordKeys != null`, not a length, so `recordKeys: []` always
answered empty. Lowering the empty list to null made it answer every row
instead. This corrects the ruling from the commit-2 fix batch that lowered
an empty v0 list to "no filter".
- CultMesh.ResolveDefaultSelection used the same collapse to decide whether an
explicit empty recordKeys should still fall back to the document type's own
schema default; under the corrected Lower it must not.
Lower(null) still means "no filter"; Lower(non-null) is always a real
(possibly empty) array. The evaluator already treats a non-null empty Keys
array as "match nothing" (CultNetSelectionEvaluator.MatchesSchemaKeysFields);
only the v0 lowering was erasing that signal before selections reached it.
Also restores the pre-cut requested-key order for
CultNetDocumentRegistry.CreateRawSnapshotResponse: pre-cut, requested record
keys were iterated in the order the caller sent them (a HashSet<string> built
from the array, which enumerates in insertion order); the new shared
evaluator's constant ordinal fell back to schema-and-key sort order instead.
ordinalOf now ranks rows by their position in the requested key list when one
was given.
Rewrote CultMeshStreamingTests.FetchDocumentsAsync_WithExplicitEmptyRecordKeys
(renamed ...AnswersEmpty) to assert the corrected behaviour instead of the
ruling it used to pin. Added
CultNetDocumentRegistry_RawSnapshot_ExplicitEmptyRecordKeys_AnswersEmpty,
CultNetDocumentRegistry_RawSnapshot_KeepsRequestedRecordKeyOrder and
CultNetV0SelectionLowering_Lower_DistinguishesNullFromExplicitEmpty to
NetworkingTests.cs.
Not done in this commit: CultNetDatabase.CreateShardSnapshotResponse (the
shard-replication snapshot path) still orders by the evaluator's default
schema-and-key tiebreak. Its own pre-cut order was raw cache iteration order,
which the new evaluator has no equivalent for and shard replication does not
appear to depend on row order; flagged as a discrepancy rather than changed
without a test that would pin the "right" order. The side-by-side b3d9cf7 vs
HEAD comparison run the spec asks for was not executed in this pass; the
pre-cut behaviour above comes from reading CultNetDatabase.cs and
CultNetDocumentRegistry.cs at b3d9cf7 directly.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
8d7bee9346
commit
5e33d81e25
5 changed files with 108 additions and 22 deletions
|
|
@ -2746,9 +2746,8 @@ public sealed class CultMeshStreamingTests
|
|||
|
||||
(await mixedAliasSchemaHandle.LatestAsync()).Text.Should().Be("compatible-record-key");
|
||||
|
||||
// MESH-KEY-Loosening (docs/cultnet-selection-cut.md, section 4/S2-4): the recordKey match is
|
||||
// exact (ordinal), not case-insensitive. A case-variant key must not win even when it appears
|
||||
// first in the response.
|
||||
// The recordKey match is exact (ordinal), not case-insensitive. A case-variant key must not
|
||||
// win even when it appears first in the response.
|
||||
var caseVariantKey = key.Value.ToUpperInvariant();
|
||||
var caseVariantKeyHandle = CultMesh.DocumentFromPeerSnapshot<MeshNoteAliasDocument>(
|
||||
_ => Task.FromResult(new CultNetSnapshotResponseRawMessage
|
||||
|
|
@ -2794,13 +2793,14 @@ public sealed class CultMeshStreamingTests
|
|||
(await caseVariantKeyHandle.LatestAsync()).Text.Should().Be("right-case-key");
|
||||
}
|
||||
|
||||
// MESH-DEFAULT-Loosening (docs/cultnet-selection-cut.md, section 4/S2-7): ResolveDefaultSelection's
|
||||
// no-schema-filter branch must trigger on a non-empty recordKeys, not merely a non-null one. An
|
||||
// explicit empty recordKeys array is a v0-compatible list that lowers to null (rule 1's v0
|
||||
// lowering), so it does not suppress the type's own schema default - the wire must carry
|
||||
// [T.SchemaId], not schemas=null.
|
||||
// R-R (docs/cultnet-selection-cut.md, Self's rulings 2026-09-22) corrects the earlier commit-2
|
||||
// ruling this test used to pin: an explicit empty recordKeys array is a real filter, not "no
|
||||
// filter". ResolveDefaultSelection must not fall back to the type's own schema default just
|
||||
// because the caller's recordKeys happened to be empty - the wire must carry recordKeys=[] and
|
||||
// no schema default, and the answer is empty, exactly as v0 answered before this cut
|
||||
// (CultNetDatabase.CreateShardSnapshotResponse at b3d9cf7 tests RecordKeys != null, not a length).
|
||||
[Test]
|
||||
public async Task FetchDocumentsAsync_WithExplicitEmptyRecordKeys_StillDefaultsToOwnSchema()
|
||||
public async Task FetchDocumentsAsync_WithExplicitEmptyRecordKeys_AnswersEmpty()
|
||||
{
|
||||
var cache = new CultCache();
|
||||
var key = new CultRecordKey("mesh-note:empty-keys-default");
|
||||
|
|
@ -2828,11 +2828,11 @@ public sealed class CultMeshStreamingTests
|
|||
|
||||
var documents = await session.FetchDocumentsAsync<MeshNoteDocument>(recordKeys: Array.Empty<string>());
|
||||
|
||||
documents.Should().ContainSingle().Which.Text.Should().Be("empty-keys-default");
|
||||
documents.Should().BeEmpty();
|
||||
requests.Should().ContainSingle();
|
||||
requests[0].SchemaIds.Should().ContainSingle().Which
|
||||
.Should().Be(CultDocumentRegistry.Shared.GetRequired<MeshNoteDocument>().SchemaId);
|
||||
requests[0].RecordKeys.Should().BeNull();
|
||||
requests[0].SchemaIds.Should().BeNull();
|
||||
requests[0].RecordKeys.Should().NotBeNull();
|
||||
requests[0].RecordKeys.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
|
|
|||
|
|
@ -3284,6 +3284,63 @@ namespace GameCult.Networking.Tests
|
|||
Assert.That(SerializePlayerDataPayload(replicated!), Is.EqualTo(expectedPayload));
|
||||
}
|
||||
|
||||
// R-R (docs/cultnet-selection-cut.md, Self's rulings 2026-09-22): v0 lowering preserves v0's
|
||||
// pre-cut answers exactly. recordKeys: [] answers empty - it does not lower to "no filter".
|
||||
[Test]
|
||||
public async Task CultNetDocumentRegistry_RawSnapshot_ExplicitEmptyRecordKeys_AnswersEmpty()
|
||||
{
|
||||
var cache = new CultCache();
|
||||
var registry = new CultNetDocumentRegistry()
|
||||
.Register(CultNetDocumentBinding.ForDocument<PlayerData>(
|
||||
payloadSerializer: SerializePlayerDataPayload,
|
||||
payloadDeserializer: DeserializePlayerDataPayload));
|
||||
await cache.AddAsync(new PlayerData { PlayerId = Guid.NewGuid(), Email = "a@test", PasswordHash = "x", Username = "A" });
|
||||
|
||||
var request = registry.CreateSnapshotRequest("request-empty", recordKeys: Array.Empty<string>());
|
||||
var response = registry.CreateRawSnapshotResponse(cache, "snapshot-empty", request);
|
||||
|
||||
Assert.That(response.Documents, Is.Empty);
|
||||
}
|
||||
|
||||
// R-R: v0's pre-cut CreateRawSnapshotResponse iterated the requested record keys in the order
|
||||
// the caller sent them, not in schema-and-key sort order. This pins that order survives the
|
||||
// move to the shared evaluator.
|
||||
[Test]
|
||||
public async Task CultNetDocumentRegistry_RawSnapshot_KeepsRequestedRecordKeyOrder()
|
||||
{
|
||||
var cache = new CultCache();
|
||||
var registry = new CultNetDocumentRegistry()
|
||||
.Register(CultNetDocumentBinding.ForDocument<PlayerData>(
|
||||
payloadSerializer: SerializePlayerDataPayload,
|
||||
payloadDeserializer: DeserializePlayerDataPayload));
|
||||
|
||||
var players = new[] { "zeta", "alpha", "mid" }
|
||||
.Select(name => new PlayerData { PlayerId = Guid.NewGuid(), Email = $"{name}@test", PasswordHash = "x", Username = name })
|
||||
.ToArray();
|
||||
var handles = new List<CultRecordHandle<PlayerData>>();
|
||||
foreach (var player in players)
|
||||
handles.Add(await cache.AddAsync(player));
|
||||
|
||||
// Request in an order that matches neither the insertion order nor the ordinal-sorted
|
||||
// record-key order, so a schema-and-key sort would visibly reorder the response.
|
||||
var requestedOrder = new[] { handles[2].Key.Value, handles[0].Key.Value, handles[1].Key.Value };
|
||||
var request = registry.CreateSnapshotRequest("request-order", recordKeys: requestedOrder);
|
||||
var response = registry.CreateRawSnapshotResponse(cache, "snapshot-order", request);
|
||||
|
||||
Assert.That(response.Documents.Select(d => d.RecordKey), Is.EqualTo(requestedOrder));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CultNetV0SelectionLowering_Lower_DistinguishesNullFromExplicitEmpty()
|
||||
{
|
||||
Assert.That(CultNetV0SelectionLowering.Lower(null), Is.Null);
|
||||
Assert.That(CultNetV0SelectionLowering.Lower(Array.Empty<string>()), Is.Not.Null);
|
||||
Assert.That(CultNetV0SelectionLowering.Lower(Array.Empty<string>()), Is.Empty);
|
||||
Assert.That(CultNetV0SelectionLowering.Lower(new[] { "", " " }), Is.Not.Null);
|
||||
Assert.That(CultNetV0SelectionLowering.Lower(new[] { "", " " }), Is.Empty);
|
||||
Assert.That(CultNetV0SelectionLowering.Lower(new[] { "b", "a", "b" }), Is.EqualTo(new[] { "b", "a" }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task CultNetDatabase_PutGet_AndWatchByIndex_Uses_PrimaryShard()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue