CultLib/scripts/mutate-cultnet-selection-networking.entries.ps1
Meta Vens e5348d3d57 CultNet selection cut1, commit 2f: the Q-J fix (canonical decimal numbers)
Corrects commit 1's Number field: docs/cultnet-selection-cut.md section 2
"Numbers" (added 2026-09-22, superseding the map's own stale float64 text)
specifies canonical decimal strings per the operator's Q-J ruling, and
commits 0/1 shipped double instead - the Rust Hands caught the conflict
before writing a line and stopped; this is the correction the map's
Progress block calls for before Rust starts.

- CultNetFieldPredicate.Number: double? -> string?. New CultNetCanonicalNumber
  (CultNetSelection.cs) is the wire's canonical grammar and comparator:
  IsCanonical validates ^-?(0|[1-9][0-9]*)(\.[0-9]*[1-9])?$ and excludes "-0"
  (the regex alone matches it); Compare orders by sign, then the integer
  part's length, then its digits, then the fraction padded on the right to
  equal length - a pure string function, no double anywhere on the path.
  ValidateField refuses a non-canonical number at the door
  (selection_invalid) rather than normalising it.
- CultNetSelectionEvaluator.CompareNumber now takes two canonical strings and
  switches on CultNetCanonicalNumber.Compare's sign instead of comparing
  doubles directly.
- CultCache.cs: CultDocumentDescriptor.TryGetIndexNumber and
  PersistedMember.NumberOf render a member's exact canonical decimal instead
  of a double. An integer renders exact (no 2^53 limit); decimal strips
  trailing fractional zeros; float/double use .NET's shortest round-trip
  ToString(), rewritten out of exponent notation to positional digits
  (ExpandScientificNotation) before the shared CanonicalizeDecimalDigits
  strips zeros and collapses a negative-zero result to "0"; NaN and infinity
  render null (TryGetIndexNumber returns false, matching "matches no
  comparison").
- contracts/cultnet/cultnet.selection.schema.json: "number" is now a string
  with the canonical pattern (a defence-in-depth (?!-0$) lookahead beyond
  what the door enforces in code), not a JSON number.
- Tests: CultNetCanonicalNumberTests (new) pins IsCanonical/Compare directly,
  including the door's five named non-canonical spellings, magnitude vs.
  lexicographic ordering, sign, integer-part length, and a long past 2^53
  against its float64 rounding. CultNetSelectionEvaluatorTests gains
  ValidationRefusesNonCanonicalNumberSpellings (+1, 1.0, 01, 1e3, -0) and its
  existing Number literals become canonical strings.
  CultDocumentSelectionSurfaceTests gains a dedicated FixtureLeafNumbers
  fixture and four tests: the 2^53+1 long rendering exactly, a decimal's
  trailing zeros stripped, a double's exponent notation rewritten to
  positional digits (1e21, 1e-7), and NaN/Infinity answering false.

Mutation entries (scripts/mutate-dotnet.ps1): four new Caching entries
(integer-through-float64, decimal trailing zeros, exponent expansion,
NaN/Infinity) and five new Networking entries (the door's regex, the door's
explicit "-0" exclusion, the comparator's integer-length check, a
lexicographic-whole-string mutant, and the comparator's sign check) - all
KILLED. The two pre-existing S16 (le/ge boundary) entries had to be
re-anchored: their Old text quoted CompareNumber's previous double-based
`left <= right`/`left >= right` spelling, which no longer exists now that
CompareNumber switches on Compare's int result: `cmp <= 0`/`cmp >= 0`.

Verification: dotnet test - GameCult.Networking.Tests 192/192 (was 183 before
these additions), GameCult.Caching.Tests 192/192 (was 188), GameCult.Mesh.Tests
252/253 (one pre-existing unrelated skip, unaffected by this commit - no Mesh
source touched). Caching mutation run: 10/10 KILLED (6 pre-existing + 4 new),
M0 and final both green. Networking mutation run: 15/15 KILLED (10
pre-existing + 5 new, across CultNetSelectionEvaluator.cs, CultNetDatabase.cs
and CultNetSelection.cs), M0 and final both green.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-22 04:18:22 +02:00

161 lines
9.8 KiB
PowerShell

# Entries for scripts/mutate-dotnet.ps1: CultNet typed selection, Cut 1, commits 1-2 - the evaluator
# and D4's schema-identity collapse. Targets:
# src/GameCult.Networking/CultNetSelectionEvaluator.cs (S3/S5/S7/S16/S18) and
# src/GameCult.Networking/CultNetDatabase.cs (D4's fourth matcher). Every entry below carries its own
# File now, so this runs as one invocation with both -Target paths. Test project:
# tests/GameCult.Networking.Tests.
#
# Not exhaustive of S1-S23: this covers order, cursor freshness, the one negation, numeric boundaries
# and the reference_outside_target refusal. S1/S2/S6/S23 are pinned by tests but not yet mutation-run
# here; S9/S10-S15 (subscription reconcile, v0 lowering, cross-runtime) and S19/S21/S22 (cache layer)
# are covered elsewhere or not yet (see the Hands report for commit 1).
@(
@{
Id = 'NET-S3-Revert'
Rule = 'S3: order reverses under descending.'
Mutant = 'revert'
File = 'src/GameCult.Networking/CultNetSelectionEvaluator.cs'
Killer = 'FullyQualifiedName=GameCult.Networking.Tests.CultNetSelectionEvaluatorTests.EvaluatorOrdersByOrdinalThenIdentityAndReverses'
Old = 'var ordered = (selection.Descending'
New = 'var ordered = (false'
},
@{
Id = 'NET-S5-Stale-Revert'
Rule = 'S5: a cursor from a moved asOf is refused cursor_stale.'
Mutant = 'revert'
File = 'src/GameCult.Networking/CultNetSelectionEvaluator.cs'
Killer = 'FullyQualifiedName=GameCult.Networking.Tests.CultNetSelectionEvaluatorTests.EvaluatorRefusesAStaleCursorAndAMismatchedSelection'
Old = 'if (cursor.AsOf != asOf)'
New = 'if (false)'
},
@{
Id = 'NET-S5-Stale-Loosening'
Rule = 'S5: staleness compares equality, not only "cursor is newer than the current asOf".'
Mutant = 'loosening'
File = 'src/GameCult.Networking/CultNetSelectionEvaluator.cs'
Killer = 'FullyQualifiedName=GameCult.Networking.Tests.CultNetSelectionEvaluatorTests.EvaluatorRefusesAStaleCursorAndAMismatchedSelection'
Old = 'if (cursor.AsOf != asOf)'
New = 'if (cursor.AsOf > asOf)'
},
@{
Id = 'NET-S5-Invalid-Revert'
Rule = 'S5: a cursor whose digest does not match this selection is refused cursor_invalid.'
Mutant = 'revert'
File = 'src/GameCult.Networking/CultNetSelectionEvaluator.cs'
Killer = 'FullyQualifiedName=GameCult.Networking.Tests.CultNetSelectionEvaluatorTests.EvaluatorRefusesAStaleCursorAndAMismatchedSelection'
Old = "if (cursor.Digest != CultNetSelectionCursor.ComputeDigest(selection))`n throw new CultNetSelectionCursorException(`"cursor_invalid`", `"The cursor's selection digest does not match this selection.`");"
New = ''
},
@{
Id = 'NET-S7-Revert'
Rule = 'S7: cited { exists } is honoured, not ignored.'
Mutant = 'revert'
File = 'src/GameCult.Networking/CultNetSelectionEvaluator.cs'
Killer = 'FullyQualifiedName=GameCult.Networking.Tests.CultNetSelectionEvaluatorTests.EvaluatorNegatedIncomingEdgeIsTheOnlyNegation'
Old = 'candidates = candidates.Where(row => incoming.Contains(row.Key.Value) == exists);'
New = 'candidates = candidates.Where(row => incoming.Contains(row.Key.Value) || true);'
},
@{
Id = 'NET-S7-Loosening'
Rule = 'S7: exists:true and exists:false must answer opposite sets, not the same test inverted twice.'
Mutant = 'loosening'
File = 'src/GameCult.Networking/CultNetSelectionEvaluator.cs'
Killer = 'FullyQualifiedName=GameCult.Networking.Tests.CultNetSelectionEvaluatorTests.EvaluatorNegatedIncomingEdgeIsTheOnlyNegation'
Old = 'candidates = candidates.Where(row => incoming.Contains(row.Key.Value) == exists);'
New = 'candidates = candidates.Where(row => incoming.Contains(row.Key.Value) != exists);'
},
@{
Id = 'NET-S16-Le-Revert'
Rule = 'S16: le includes the equal boundary.'
Mutant = 'revert'
File = 'src/GameCult.Networking/CultNetSelectionEvaluator.cs'
Killer = 'FullyQualifiedName=GameCult.Networking.Tests.CultNetSelectionEvaluatorTests.EvaluatorComparesNumbersAtTheBoundaryForEachOfTheFourOperators'
Old = 'CultNetSelectionOperator.Le => cmp <= 0,'
New = 'CultNetSelectionOperator.Le => cmp < 0,'
},
@{
Id = 'NET-S16-Ge-Revert'
Rule = 'S16: ge includes the equal boundary.'
Mutant = 'revert'
File = 'src/GameCult.Networking/CultNetSelectionEvaluator.cs'
Killer = 'FullyQualifiedName=GameCult.Networking.Tests.CultNetSelectionEvaluatorTests.EvaluatorComparesNumbersAtTheBoundaryForEachOfTheFourOperators'
Old = 'CultNetSelectionOperator.Ge => cmp >= 0,'
New = 'CultNetSelectionOperator.Ge => cmp > 0,'
},
@{
Id = 'NET-S18-Revert'
Rule = 'D9/S18: an edge naming a row outside its reference''s declared target refuses the selection.'
Mutant = 'revert'
File = 'src/GameCult.Networking/CultNetSelectionEvaluator.cs'
Killer = 'FullyQualifiedName=GameCult.Networking.Tests.CultNetSelectionEvaluatorTests.EvaluatorRefusesAnEdgeOutsideItsDeclaredTarget'
Old = 'throw new CultNetSelectionReferenceOutsideTargetException(from.Descriptor.SchemaId, from.Key.Value, role, to.Descriptor.SchemaId, to.Key.Value);'
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.'
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) ||'
}
# 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
# CompareNumber, via CultNetCanonicalNumber.Compare). CultNetCanonicalNumberTests pins Compare
# directly with more cases than the entries below exercise; every entry here is one the map named.
@{
Id = 'NET-QJ-Door-Regex-Revert'
Rule = 'Q-J: the door refuses a non-canonical number spelling (+1, 1.0, 01, 1e3) rather than accepting it.'
Mutant = 'revert'
File = 'src/GameCult.Networking/CultNetSelection.cs'
Killer = 'FullyQualifiedName~CultNetSelectionEvaluatorTests.ValidationRefusesNonCanonicalNumberSpellings'
Old = 'if (!CultNetCanonicalNumber.IsCanonical(field.Number))'
New = 'if (false)'
},
@{
Id = 'NET-QJ-Door-NegativeZero-Revert'
Rule = 'Q-J: "-0" is excluded even though the regex alone matches it - IsCanonical checks it explicitly.'
Mutant = 'revert'
File = 'src/GameCult.Networking/CultNetSelection.cs'
Killer = 'FullyQualifiedName~CultNetSelectionEvaluatorTests.ValidationRefusesNonCanonicalNumberSpellings'
Old = 'value != null && value != "-0" && CanonicalRegex.IsMatch(value);'
New = 'value != null && CanonicalRegex.IsMatch(value);'
},
@{
Id = 'NET-QJ-Compare-IntegerLength-Revert'
Rule = 'Q-J: the comparator checks the integer part''s length before its digits - "100" > "99" even though ''1'' < ''9'' as a bare character.'
Mutant = 'revert'
File = 'src/GameCult.Networking/CultNetSelection.cs'
Killer = 'FullyQualifiedName=GameCult.Networking.Tests.CultNetCanonicalNumberTests.CompareOrdersByIntegerPartLengthBeforeDigits'
Old = " if (integerLeft.Length != integerRight.Length)`n return sign * (integerLeft.Length < integerRight.Length ? -1 : 1);`n`n"
New = ''
},
@{
Id = 'NET-QJ-Compare-Lexicographic-Revert'
Rule = 'Q-J: the comparator is not a lexicographic compare of the whole string ("10" must not be less than "9").'
Mutant = 'revert'
File = 'src/GameCult.Networking/CultNetSelection.cs'
Killer = 'FullyQualifiedName=GameCult.Networking.Tests.CultNetCanonicalNumberTests.CompareOrdersByMagnitudeNotLexicographically'
Old = 'var (negativeLeft, integerLeft, fractionLeft) = Decompose(left);'
New = 'return string.CompareOrdinal(left, right); var (negativeLeft, integerLeft, fractionLeft) = Decompose(left);'
},
@{
Id = 'NET-QJ-Compare-Sign-Revert'
Rule = 'Q-J: the comparator orders a negative value below a positive one of the same magnitude.'
Mutant = 'revert'
File = 'src/GameCult.Networking/CultNetSelection.cs'
Killer = 'FullyQualifiedName=GameCult.Networking.Tests.CultNetCanonicalNumberTests.CompareOrdersNegativeBelowPositive'
Old = 'if (negativeLeft != negativeRight)'
New = 'if (false)'
}
)