CultNet selection cut1, commit 2 fix batch: door, shard-via-evaluator, Mesh v0 refusal, dead Reconcile code, mutation harness crash handling

Soul found commit 2 didn't pass (docs/cultnet-selection-cut.md, 2026-09-22):
empty/blank schemas-keys still reached the evaluator, the shard snapshot ran
its own loop instead of the evaluator, Mesh's v0 wire silently dropped v1-only
selection terms, the Mesh one-pass read could return the wrong schema's
record at a shared key, two decode rules for a foreign schema id disagreed,
dead identity-comparison code from the _projectRecord removal was still live,
and a disposed-socket race could abort a mutation run instead of recording
NO VERDICT. This is Self's fix batch for all of it.

- CultNetSelection.Validate now refuses a blank/whitespace entry inside
  schemas or keys, not just an empty array. CultNetSelectionEvaluator no
  longer treats [] as "no filter" (the door already refuses it before
  evaluation). CultNetV0SelectionLowering is the one place that lowers an
  empty or all-blank v0 list to null; CreateRawSnapshotResponse and
  CreateShardSnapshotResponse both route through it, and CultMesh's own
  Clean() now delegates to it instead of duplicating the rule.
- CreateShardSnapshotResponse no longer carries a private loop or its own
  schema/key matching: it builds a CultNetSelection and answers through
  CultNetDocumentRegistry.SelectPage (the same evaluator path as the
  non-shard snapshot), with the shard's own membership check as a row
  filter. Binding-alias expansion now runs on both paths identically.
- ResolveDefaultSelection decides "no schema filter" from the cleaned
  recordKeys, not the raw array length. OverlaySelection stops deciding what
  a missing override means: any explicit schemaIds/recordKeys override
  replaces the default selection wholesale; no override keeps the default
  untouched.
- CultMeshSnapshotRequestOptions.Selection is now checked by
  EnsureV0Compatible before every send: fields, cites, cited, limit, cursor,
  descending, and any non-default projection are refused typed
  (CultNetSelectionInvalidException), never silently dropped from the v0
  wire message. Mesh sending v1 is FU-Mesh-v1, not this cut.
- CultMeshHotBodySubscription.Selection returns a defensive copy on every
  read so its arrays can't be mutated out from under the stored selection.
- ReadDocumentFromSnapshotResponse now searches candidates at one recordKey
  in one order - exact schema, then alias, then a foreign schema id decoded
  from the payload - instead of one OR'd condition where a case-insensitive
  or structurally-lucky candidate could win first. The foreign-id decode
  reads the payload's embedded schema version with the registry's shared
  CultNetDocumentRegistry.TryReadSchemaVersion and alias-matches it against
  the caller's own descriptor directly, rather than resolving to "whichever
  registered type owns this schema string" - that resolution is ambiguous
  when two document types alias the same schema id (MeshNoteDocument and
  MeshNoteAliasDocument in the existing fixtures), which is what broke on
  the first pass; TryResolveDescriptorByPayloadSchema stays for its existing
  caller (ResolveDescriptorForRawDocument) with a note on when not to use it.
  DecodeSnapshotDocuments and the Mesh copy of the payload-schema decode
  (RawSnapshotPayloadMatchesSchema/TryReadSchemaVersion) are deleted in
  favour of the shared one.
- CultNetDatabaseSubscriptionServer: the dead RecordKey/SchemaId identity
  comparisons in Reconcile and ApplyProjectedChange, and the duplicate-key
  throw in CreateProjectedSnapshot, are deleted - they can no longer fire
  now that a projection's dictionary key is always the record's own key.
  A new test flips authorizeRecord per key while the whole request stays
  authorized (so DemandActive never toggles) and proves both halves of the
  remaining diff: the removal of a now-unauthorized key and the add loop
  picking up a newly-authorized one.
- Every NetworkingTests.cs test that starts an IsBackground poll thread now
  joins it before its server disposes (about 20 tests; one already did).
- scripts/mutate-dotnet.ps1: a dotnet-test-host crash writing to stderr no
  longer throws the whole run away under PowerShell 5.1's
  $ErrorActionPreference = 'Stop' (2>&1 on a native command wraps stderr in
  a terminating NativeCommandError); Run-Tests catches it and the entry loop
  records NO VERDICT instead of aborting every remaining entry.
- Two probe tests: CultNetDatabase_ShardAndNonShardSnapshot_Agree{On
  UnfilteredRequest,OnBindingSchemaIdOverride} prove the shard and non-shard
  snapshot paths agree, including shard-membership exclusion of a document
  outside the shard's key prefix and a binding schema-id override matching
  on both paths.
- Mutation entries updated/added to match: the stale NET-D4-FourthMatcher
  entry (its anchor was the private loop this batch deleted, not refactored)
  is replaced by NET-D4-ShardMembership-Revert; the Mesh entries file's
  header miscount ("two of three" loosening entries when there are only
  two) is corrected and both previously-surviving loosening mutants
  (MESH-DEFAULT-Loosening, MESH-KEY-Loosening) now have killing fixtures;
  scripts/mutate-cultnet-selection-fixbatch2.entries.ps1 is new, covering
  Reconcile's remaining two mutants.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-22 06:12:49 +02:00
commit 568e8e356f
14 changed files with 586 additions and 174 deletions

View file

@ -0,0 +1,33 @@
# Entries for scripts/mutate-dotnet.ps1: CultNet typed selection, Cut 1, commit 2 fix batch
# (docs/cultnet-selection-cut.md, Self's rulings 2026-09-22). Targets the dead-identity-code deletion
# in src/GameCult.Networking/CultNetDatabaseSubscriptionServer.cs (S2-2): Reconcile must still walk
# its diff when the request stays authorized (not gated on DemandActive changing), and its add loop
# must still fire. Test project: tests/GameCult.Networking.Tests.
@(
@{
Id = 'NET-RECONCILE-EarlyReturn-Loosening'
Rule = 'Reconcile walks the delivered/added diff whenever it runs; it must not early-return merely because request-level authorization (and so DemandActive) has not changed - per-record authorization can still have moved.'
Mutant = 'loosening'
File = 'src/GameCult.Networking/CultNetDatabaseSubscriptionServer.cs'
Killer = 'FullyQualifiedName=GameCult.Networking.Tests.NetworkingTests.DatabaseSubscriptionServer_Reconcile_FlipsPerRecordAuthorizationWithoutChangingRequestAuthority'
Old = 'if (!_projections.TryGetValue(key, out var projection)) return;
var authorized = _authorizeRequest?.Invoke(request, key.Peer) != false;'
New = 'if (!_projections.TryGetValue(key, out var projection)) return;
var authorized = _authorizeRequest?.Invoke(request, key.Peer) != false;
if (projection.DemandActive == authorized) return;'
},
@{
Id = 'NET-RECONCILE-AddLoop-Revert'
Rule = 'Reconcile''s add loop sends an upsert (added: true) for every key in the new snapshot that was not already delivered.'
Mutant = 'revert'
File = 'src/GameCult.Networking/CultNetDatabaseSubscriptionServer.cs'
Killer = 'FullyQualifiedName=GameCult.Networking.Tests.NetworkingTests.DatabaseSubscriptionServer_Reconcile_FlipsPerRecordAuthorizationWithoutChangingRequestAuthority'
Old = 'foreach (var current in next.BySourceRecordKey)
{
if (!projection.DeliveredBySourceRecordKey.ContainsKey(current.Key))
SendUpsert(key.Peer, key.Id, current.Value, added: true);
}'
New = ''
}
)

View file

@ -1,17 +1,19 @@
# Entries for scripts/mutate-dotnet.ps1: CultNet typed selection, Cut 1, commit 2d - the CultMesh
# collapse (docs/cultnet-selection-cut.md, sections 4/7/11). Targets: src/GameCult.Mesh/CultMesh.cs
# Entries for scripts/mutate-dotnet.ps1: CultNet typed selection, Cut 1, commit 2 fix batch
# (docs/cultnet-selection-cut.md, sections 4/7/11). Targets: src/GameCult.Mesh/CultMesh.cs
# (ReadDocumentFromSnapshotResponse's one exact read) and src/GameCult.Mesh/CultMeshSnapshots.cs
# (ResolveDefaultSelection's "no schema filter when keys are given" rule). Test project:
# tests/GameCult.Mesh.Tests.
#
# Every entry below carries its own File, so this runs as one invocation with both -Target paths.
#
# Two of the three loosening entries here SURVIVED against the current fixtures (recorded, not
# swapped for an easier mutant): MESH-DEFAULT-Loosening and MESH-KEY-Loosening. Both are genuine
# weaker readings of the rule they sit beside; no test in tests/GameCult.Mesh.Tests exercises an
# explicit empty (non-null) recordKeys array or a record-key case variation, so nothing currently
# distinguishes the loosened behavior from the correct one. That is a fixture gap in
# CultMeshStreamingTests.cs, not evidence the mutant is unreachable in principle.
# There are two loosening entries here (MESH-DEFAULT-Loosening and MESH-KEY-Loosening); the header
# above this line previously miscounted them as "two of three" (S2-9/S2-10). Both were genuine
# weaker readings of the rule they sit beside and both SURVIVED against the pre-fix-batch fixtures,
# because nothing in tests/GameCult.Mesh.Tests exercised an explicit empty (non-null) recordKeys
# array or a record-key case variation. CultMeshStreamingTests.cs now carries
# FetchDocumentsAsync_WithExplicitEmptyRecordKeys_StillDefaultsToOwnSchema (MESH-DEFAULT) and the
# case-variant-key block appended to DocumentHandle_ReadsRemotePeerSnapshotsAsTypedDocuments
# (MESH-KEY); both mutants below now die.
@(
@{
@ -20,18 +22,20 @@
Mutant = 'revert'
File = 'src/GameCult.Mesh/CultMeshSnapshots.cs'
Killer = 'FullyQualifiedName=GameCult.Mesh.Tests.CultMeshStreamingTests.SnapshotEndpoint_ProvidesTypedHandlesAndSchemaAliases'
Old = 'var schemas = schemaIds != null
Old = 'var cleanedKeys = Clean(recordKeys);
var schemas = schemaIds != null
? Clean(schemaIds)
: (recordKeys is { Count: > 0 } ? null : new[] { descriptor.SchemaId });'
New = 'var schemas = schemaIds != null ? Clean(schemaIds) : new[] { descriptor.SchemaId };'
: (cleanedKeys != null ? null : new[] { descriptor.SchemaId });'
New = 'var cleanedKeys = Clean(recordKeys);
var schemas = schemaIds != null ? Clean(schemaIds) : new[] { descriptor.SchemaId };'
},
@{
Id = 'MESH-DEFAULT-Loosening'
Rule = 'ResolveDefaultSelection: the no-schema-filter branch triggers on a non-empty recordKeys, not merely a non-null one.'
Rule = 'ResolveDefaultSelection: the no-schema-filter branch triggers on a non-empty (post-cleaning) recordKeys, not merely a non-null one - an explicit empty recordKeys array still defaults to the document type''s own schema (docs/cultnet-selection-cut.md, S2-7/rule 1''s v0 lowering).'
Mutant = 'loosening'
File = 'src/GameCult.Mesh/CultMeshSnapshots.cs'
Killer = 'FullyQualifiedName=GameCult.Mesh.Tests.CultMeshStreamingTests.SnapshotEndpoint_ProvidesTypedHandlesAndSchemaAliases'
Old = 'recordKeys is { Count: > 0 } ? null : new[] { descriptor.SchemaId }'
Killer = 'FullyQualifiedName=GameCult.Mesh.Tests.CultMeshStreamingTests.FetchDocumentsAsync_WithExplicitEmptyRecordKeys_StillDefaultsToOwnSchema'
Old = 'cleanedKeys != null ? null : new[] { descriptor.SchemaId }'
New = 'recordKeys != null ? null : new[] { descriptor.SchemaId }'
},
@{
@ -55,14 +59,14 @@
},
@{
Id = 'MESH-FOREIGN-Revert'
Rule = 'ReadDocumentFromSnapshotResponse: a foreign/runtime-generated schema id at the right recordKey still matches when its payload decodes as TDocument.'
Rule = 'ReadDocumentFromSnapshotResponse: a foreign/runtime-generated schema id at the right recordKey still matches when its payload''s embedded schema (read by the registry''s shared TryReadSchemaVersion) alias-matches the caller''s own descriptor.'
Mutant = 'revert'
File = 'src/GameCult.Mesh/CultMesh.cs'
Killer = 'FullyQualifiedName=GameCult.Mesh.Tests.CultMeshStreamingTests.DocumentHandle_ReadsRemotePeerSnapshotsAsTypedDocuments'
Old = 'if (string.Equals(candidate.SchemaId, schemaId, StringComparison.Ordinal) ||
CultNetSchemaAliasMatching.Matches(candidate.SchemaId, descriptor) ||
TryDecodeAsMessagePack<TDocument>(candidate, out _))'
New = 'if (string.Equals(candidate.SchemaId, schemaId, StringComparison.Ordinal) ||
CultNetSchemaAliasMatching.Matches(candidate.SchemaId, descriptor))'
Old = 'else if (byPayload == null &&
CultNetDocumentRegistry.TryReadSchemaVersion(candidate.Payload) is { } payloadSchemaVersion &&
CultNetSchemaAliasMatching.Matches(payloadSchemaVersion, descriptor))
byPayload = candidate;'
New = ''
}
)

View file

@ -93,21 +93,24 @@
New = 'return;'
},
@{
Id = 'NET-D4-FourthMatcher-Revert'
Rule = 'D4/Self''s ruling 2026-09-22: CreateShardSnapshotResponse''s schema filter is the one alias matcher (CultNetSchemaAliasMatching.MatchesAny), not a private fourth copy.'
# S2-3 (docs/cultnet-selection-cut.md, Self's rulings 2026-09-22, commit 2 fix batch):
# CreateShardSnapshotResponse no longer carries its own schema/key filter at all - it went
# through CultNetSelectionEvaluator.SelectPage, with the shard's own row filter as the only
# thing this method still owns. NET-D4-FourthMatcher-Revert's original anchor
# ("requestedSchemaIds != null && !CultNetSchemaAliasMatching.MatchesAny(...)") was the private
# loop this fix batch deleted, not merely refactored; the schema-matching mutants it proved are
# now covered by this file's CultNetSelectionEvaluator.cs entries (NET-S1/S2 etc.) plus
# tests/GameCult.Networking.Tests.NetworkingTests.CultNetDatabase_ShardAndNonShardSnapshot_*.
# This entry now proves the one thing CreateShardSnapshotResponse still owns: the shard
# membership check.
Id = 'NET-D4-ShardMembership-Revert'
Rule = 'CreateShardSnapshotResponse''s row filter still enforces shard membership (shard.Matches), even though schema/key filtering is now entirely the evaluator''s.'
Mutant = 'revert'
File = 'src/GameCult.Networking/CultNetDatabase.cs'
Killer = 'FullyQualifiedName=GameCult.Networking.Tests.NetworkingTests.CultNetDatabase_Creates_ShardSnapshotResponse_ForCompatibleSchemaAlias'
Old = '(requestedSchemaIds != null && !CultNetSchemaAliasMatching.MatchesAny(requestedSchemaIds, descriptor)) ||'
New = '(requestedSchemaIds != null) ||'
Killer = 'FullyQualifiedName=GameCult.Networking.Tests.NetworkingTests.CultNetDatabase_ShardAndNonShardSnapshot_AgreeOnUnfilteredRequest'
Old = '!string.IsNullOrWhiteSpace(key.Value) && shard.Matches(descriptor.SchemaId, key);'
New = '!string.IsNullOrWhiteSpace(key.Value);'
}
# A loosening mutant here ('(requestedSchemaIds != null && requestedSchemaIds.Length == 0) ||',
# i.e. reject only an empty-but-non-null list rather than "no requested id matches") was run by
# hand against CultNetDatabase_Creates_ShardSnapshotResponse_ForCompatibleSchemaAlias and
# SURVIVED: the fixture puts exactly one document in the whole cache, so an over-permissive
# filter still returns the same single row. This is a finding about the fixture, not a defended
# rule - a second document of a different schema in the same shard is needed to make the
# loosening fail, and is not added here (no easier mutant substituted per the Hands brief).
#
# Q-J (docs/cultnet-selection-cut.md section 2 "Numbers", 2026-09-22): the door's canonical-decimal
# grammar (CultNetSelection.cs) and the comparator that reads it (CultNetSelectionEvaluator.cs's

View file

@ -58,7 +58,25 @@ function Get-SidecarPath([string]$path) { "$path.mutation-original" }
function Run-Tests([string]$filter) {
$args = @('test', $testProjectPath, '-c', 'Debug', '--nologo')
if ($filter) { $args += @('--filter', $filter) }
$output = & dotnet @args 2>&1 | Out-String
# A test-host crash (e.g. S2-1's disposed-socket race on a background poll thread) can write to
# stderr; under PowerShell 5.1, `2>&1` on a native command wraps each stderr line in a
# NativeCommandError, and with the script's own $ErrorActionPreference = 'Stop' that becomes a
# terminating error that would otherwise throw the whole run away. Run this one call under
# 'Continue' and catch anything that still throws, so a host crash is captured as output and
# classified as NO VERDICT by the caller instead of aborting every remaining entry.
$previousPreference = $ErrorActionPreference
$ErrorActionPreference = 'Continue'
$crashed = $false
try {
$output = & dotnet @args 2>&1 | Out-String
}
catch {
$output = "$_"
$crashed = $true
}
finally {
$ErrorActionPreference = $previousPreference
}
Write-Host $output
$passedMatch = [regex]::Match($output, 'Passed:\s+(\d+)')
$failedMatch = [regex]::Match($output, 'Failed:\s+(\d+)')
@ -67,7 +85,8 @@ function Run-Tests([string]$filter) {
$failedLine = $output -match 'Failed!'
[pscustomobject]@{
Compiled = $compiled
Green = $compiled -and $passedLine -and -not $failedLine -and $passedMatch.Success -and [int]$passedMatch.Groups[1].Value -ge 1
Crashed = $crashed
Green = (-not $crashed) -and $compiled -and $passedLine -and -not $failedLine -and $passedMatch.Success -and [int]$passedMatch.Groups[1].Value -ge 1
Passed = if ($passedMatch.Success) { [int]$passedMatch.Groups[1].Value } else { 0 }
Failed = if ($failedMatch.Success) { [int]$failedMatch.Groups[1].Value } else { 0 }
}
@ -169,10 +188,18 @@ foreach ($mutation in $mutations) {
try {
foreach ($file in $files) { Write-Text $targets[$file] $texts[$file] }
$run = Run-Tests $mutation.Killer
if (-not $run.Compiled) { $verdict = 'NO VERDICT (did not compile)' }
if ($run.Crashed) { $verdict = 'NO VERDICT (test host crashed)' }
elseif (-not $run.Compiled) { $verdict = 'NO VERDICT (did not compile)' }
elseif ($run.Failed -ge 1) { $verdict = 'KILLED' }
else { $verdict = 'SURVIVED' }
}
catch {
# Not yet reached by Run-Tests itself (it no longer throws on a host crash), but a defensive
# backstop: any other exception during this entry's run is recorded and the campaign continues
# rather than aborting every remaining entry, never labeled "unreachable".
Write-Host "NO VERDICT: $($mutation.Id) - test run threw: $_"
$verdict = 'NO VERDICT (harness exception)'
}
finally {
foreach ($file in $files) {
[System.IO.File]::WriteAllBytes($targets[$file], $originalBytes[$file])