From daa645601abcf1f41f6b93691de4084d3c14b2c5 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 25 Sep 2026 12:05:47 +0200 Subject: [PATCH] Cut 2 Stryker fix batch: chunk-index bounds, respawn boundary, ChunkId equality Stryker over Zone.cs (concurrency 1, 111 mutants tested) surfaced four real gaps on this cut's own lines, all now killed: - ChunkExists's range check (`index < 0 || index >= length`) survived both an AND weakening and a `>` boundary weakening, because nothing tried an out-of-range index on either side alone. - The broken-until comparisons in ChunkExists/ChunkRadius and the pack-time pruning in IsExpired all survived a `>`/`<` vs `>=`/`<=` boundary flip, because every prior test advanced zone time well past BrokenUntil instead of landing on it exactly. - ChunkId.Equals survived an AND-to-OR weakening: the wear dictionary's own GetHashCode already separates same-field/different-index and same-index/different-field pairs into different buckets, so a bad Equals was never reached through a lookup. Testing equality directly closes that. Two survivors on this cut's lines are recorded as equivalent, not chased: ChunkRadius's `wear.Damage <= 0f` boundary (at damage == 0, DamagedSize and UndamagedSize evaluate the same curve at the same point, so no input distinguishes the two branches), and ChunkId.GetHashCode's exact formula (a hashcode's bit pattern isn't a contract; any deterministic function of the same two fields trivially keeps equal keys hashing equal, and this dictionary is too small for distribution to matter). The remaining survivors (lines 44, 75, 170, 200, 212, 216, 319, 336-412) sit in Update/GetOrbitPosition/GetSecurityLevel/GetHeight/GetNormal/PowerPulse, none of which this cut touches; they predate it and are out of scope here. Mutation score 38.62% -> 42.33% (78/111 killed, 2 timeout, 31 survived, all 31 either pre-existing or one of the two equivalents above). Co-Authored-By: Claude Opus 5.5 --- .../Aetheria.Shared.Tests/MiningCut2Tests.cs | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/tests/Aetheria.Shared.Tests/MiningCut2Tests.cs b/tests/Aetheria.Shared.Tests/MiningCut2Tests.cs index bf79a2d3d..6a37ae781 100644 --- a/tests/Aetheria.Shared.Tests/MiningCut2Tests.cs +++ b/tests/Aetheria.Shared.Tests/MiningCut2Tests.cs @@ -294,6 +294,63 @@ public sealed class MiningCut2Tests : IDisposable Assert.True(zone.ChunkExists(new ChunkId(f.BeltA, 0))); Assert.Equal(zone.AsteroidBelts[f.BeltA].UndamagedSize(0, f.Settings), zone.ChunkRadius(new ChunkId(f.BeltA, 0)), 4); } + + // Stryker gap (2026-09-25 pass on this cut): ChunkExists's range check reads `chunk.Index < 0 || + // chunk.Index >= length`; nothing exercised either side of that OR alone, or the >= boundary at exactly + // `length`, so a mutant weakening it to AND (which can never be true, since an index cannot be both + // negative and past the end at once) and a mutant weakening >= to > both survived. + [Fact] + public void OutOfRangeChunkIndicesDoNotExist() + { + var f = BuildFixture(); + Assert.False(f.Zone.ChunkExists(new ChunkId(f.BeltA, -1)), "a negative index alone must already fail"); + Assert.False(f.Zone.ChunkExists(new ChunkId(f.BeltA, f.AsteroidsA.Length)), + "the index exactly at the asteroid count is already past the end (0-based), not the first one out"); + } + + // Stryker gap: ChunkId.Equals was reachable only through the wear dictionary, whose GetHashCode already + // separates a same-field-different-index or same-index-different-field pair into different buckets, so a + // mutant weakening Equals from `&&` to `||` never got exercised by a lookup. This tests the value equality + // directly, the way the operator's ruling actually describes chunk identity: same field AND same index. + [Fact] + public void ChunkIdEqualityRequiresBothFieldAndIndex() + { + var f = BuildFixture(); + var a0 = new ChunkId(f.BeltA, 0); + var a0Again = new ChunkId(f.BeltA, 0); + var a1 = new ChunkId(f.BeltA, 1); + var b0 = new ChunkId(f.BeltB, 0); + + Assert.Equal(a0, a0Again); + Assert.NotEqual(a0, a1); + Assert.NotEqual(a0, b0); + } + + // Stryker gap: the broken-until comparisons (ChunkExists, ChunkRadius) and the pack-time pruning rule + // (IsExpired) all compare BrokenUntil against zone time at their own boundary, and no existing test landed + // exactly on it (ABrokenChunkReturnsAtItsRespawnTimeFullyHealed and APackOmitsExpiredWear both advance well + // past it). Breaking at time 0 and stepping by exactly the authored respawn time lands zone time on + // BrokenUntil bit-for-bit (0.0 + respawnTime, then 0.0 += respawnTime): the chunk must already read as + // respawned at that exact instant, not one tick later, and packing at that instant must already prune it. + [Fact] + public void RespawnAndPruneBoundaryIsInclusiveOfExactlyNow() + { + var f = BuildFixture(); + const int index = 7; + var chunk = new ChunkId(f.BeltA, index); + var hp = f.Settings.AsteroidHitpoints.Evaluate(f.AsteroidsA[index].Size); + var respawn = f.Settings.AsteroidRespawnTime.Evaluate(f.AsteroidsA[index].Size); + + Assert.True(f.Zone.Wear(chunk, hp + 1f)); + f.Zone.Update(respawn); // zone time now equals BrokenUntil exactly, not "respawn plus a margin". + + Assert.True(f.Zone.ChunkExists(chunk), "must read as respawned the instant zone time reaches BrokenUntil, not strictly after it"); + Assert.Equal(f.Zone.AsteroidBelts[f.BeltA].UndamagedSize(index, f.Settings), f.Zone.ChunkRadius(chunk), 4); + + var pack = f.Zone.PackZone(); + var stillPacked = pack.ChunkWear?.Exists(w => w.Field.Equals(chunk.Field) && w.Index == chunk.Index) ?? false; + Assert.False(stillPacked, "at exactly the respawn instant the entry already carries no live information"); + } } internal static class MiningCut2TestExtensions