Started as an allocation pass over `StepCache` and grew into a cleanup of the surrounding pathing engine. Four commits, each independently reviewable; net **−560 lines**. Build clean (0 warnings). All 122 `Server.Tests.Pathfinding` tests pass. --- ## 1. `perf`: pool the strata buffer, cut a hot-path dictionary lookup **The headline is that `TryGetMask` — the actual hot path — was already allocation-free.** `StepMask` is a readonly struct, `StaticTileEnumerable` is a `ref struct`, `ChunkMissState` is a struct in a `Dictionary`. So most of this is a bake-throughput and GC-churn win, with one exception noted below. `BuildChunk` accumulated packed multi-Z strata into a `List<byte>` that grew by doubling (256 → 512 → 1024 → …) and then paid a final `ToArray()`. A full map bake runs it ~114k times. It now writes into a `byte[]` rented from `STArrayPool<byte>.Shared` through a span writer, and hands the chunk one exact-size copy. **This required fixing a latent out-of-bounds guard.** The record-fit check reserved headroom for **8** strata (`StratumByteLength * 8`) while `ComputeStandableSurfaceZs` can return up to **16** — so a cell could write 305 bytes starting from a 65,383-byte offset. Against a `List` that was benign (it just grew past 64 KB, and emitted offsets stayed under the `NoStrata` sentinel). Against a fixed-size rented buffer it is an out-of-bounds write, so tightening it was a *prerequisite* for the pooling, not a drive-by. The guard is now exact, which additionally proves no emitted offset can collide with `NoStrata == ushort.MaxValue`. **One genuine query-path win:** `ShouldPromoteAfterMiss` did *two* dictionary lookups per miss — a `TryGetValue`, then an indexer assignment that re-hashes and re-probes. It now mutates in place via `CollectionsMarshal.GetValueRefOrNullRef`. This runs on every uncached chunk touch during A* expansion. The window-expiry branch keeps its explicit early return, so `MissPromotionThreshold == 1` still resets rather than promoting. Also dropped `StepProbe.ComputeStrataAt` / `ComputedStratum` (dead code, zero callers) and collapsed six 18-argument `new StepMask(0, 0, …, kind)` blocks into `Fallthrough(kind)`. **Considered and rejected:** pooling the `Direction[]` that `Find` returns. It *escapes* the call — `MovementPath` holds it across ticks while `PathFollower` walks `m_Index` through it — so it cannot be rented-and-returned, and it cannot be borrowed from the shared `BitmapAStarAlgorithm.Instance` without one creature clobbering another's in-flight path. `CheckPath` rate-limits repaths to one per 2s per creature, putting this at roughly 60 KB/sec at 1,000 pathing creatures. Not worth a public API break plus a use-after-return footgun. ## 2. `docs`: rewrite the comments for publication The comments had accumulated as development notes: internal phase jargon (`Tier 4`, `the Phase-2 synthesizer`), change narration aimed at a reviewer (`which the old ComputeStandingZ anchor missed`, `legacy behavior`), benchmark anecdotes (`benchmarked as near-optimal`, `a ~20 ns lookup`), and paragraphs restating the code. Rewritten to keep the rationale you cannot recover by reading the code — why the source-Z guard cannot be widened, why multis fall through with a halo, why the promotion gate counts Finds rather than calls, why `ComputeFingerprint` must hash the *files* and not the live tile tables — and drop the history that got us there. Three comments were **factually wrong**, not just wordy: - `CacheEvictionTimer` and `CacheStats` documented a class called `StaticWalkabilityCache`. No such class exists — it is `StepCache`. - `StepCacheFile` declared `File layout v8` while `FormatVersion` is 9, and called the current record layout "the v6 layout" in four places. The layout descriptions are now unversioned so they cannot drift again. - `StepProbe.ComputeStandingZ` claimed `StepCache` uses it to bake `SourceZ`. It has not since the baker moved to the clearance-aware `ComputeStandableSurfaceZs`; only a parity test calls it. ## 3. `refactor`: simplify `StepCacheFile.Write`, consolidate the format tests `SaveToFile` walked `_keysList` **twice** — once to count the map's chunks, then again through a `ChunkEnumerator` closure to emit them — because `Write` needed the count up front to size its index array. Both loops had the same root cause. Passing a **span** collapses them: the count is just `span.Length`. That deletes the `ChunkEnumerator` delegate, the closure over the list enumerator, and **both `InvalidOperationException` throws**, which existed only to police the delegate's "yield exactly `chunkCount` chunks" contract — a contract a span makes unrepresentable. `Write` now patches the header's `IndexOffset` by seeking back to it rather than reaching into the writer's live buffer with `BinaryPrimitives`. That also retires `IndexOffsetFieldPosition`, a hand-maintained byte offset that had to track the header layout, and sidesteps the stale-array hazard that motivated the manual patch (`BufferWriter` reallocates on growth). **Tests:** `StepCacheFileV6/V7/V8Tests` were named for the format version that introduced each transform — and the format is now **v9**, so all three names described formats the loader rejects outright. Beyond triplicated builders and plumbing, two things were actually broken: - The three near-identical rejection tests each cited a `MinSupportedVersion` that had since moved (`"version 5 < MinSupportedVersion 6"`, `"6 < 7"`, `"7 < 8"`). They passed for the wrong reason. - `AssertBaseEqual` (used by V7 and V8) **silently skipped the swim and strata trailers**. A regression dropping either would not have failed those tests. Now one `StepCacheFileFormatTests`, named for behavior — predictive-Z elision, compression, compact index — with a single `AssertIdentical` that does check both trailers, the three rejection tests folded into one theory that also covers a future version, and a zero-chunk case the delegate-based writer never had coverage for. ## 4. `test`: consolidate the parity and lifecycle tests Three files tested "parity" and none of the names said *which*. They were three different layers, and the seams are the useful part, so they are now one `StepCacheParityTests` that names them: | Test | Compares | Answers | |---|---|---| | `ProbeMatchesSlowPath` | StepProbe vs MovementImpl | Is the bake right? | | `CacheMatchesProbe` | StepCache vs StepProbe | Is it stored and returned intact? | | `CacheServesReachableWalkStates` | StepCache vs MovementImpl | End to end, over the states A* visits | Merging removed a duplicated stub `Mobile`, duplicated region seeds, and a filename/class mismatch (`StepProbeParityTests.cs` declared `StaticWalkabilityParityTests`). `SwimBake_ProducesWetCells` moved with it — it lived in the cache parity file but never touched the cache. Tests reached into `StepCache._chunks` via `GetField` in **9 places**, each rebuilding the key encoding and cell-index arithmetic by hand. `StepCache` now exposes `GetResidentChunk` and `ResidentIndexInSync` alongside the internal test hooks it already had (`LazyReaderHasChunk`, `CurrentFindGeneration`), and the shared arithmetic moved to `PathingTestSupport`. All 9 reflection blocks are gone. `StepCacheLifecycleTests` is regrouped by what it covers — promotion gate, fallthrough routes, strata, swim layer, eviction — with the `Tier4*` names dropped. Removed `Singleton_IsAvailable`, which asserted an inline-initialized static property was not null; that is the entire 123 → 122 test-count delta. --- ## Verification Tests were mutation-checked rather than just run, since round-trip and parity tests can pass while a transform silently no-ops: - Injecting an off-by-one into the `IndexOffset` patch fails **15 of 123** — the format tests are load-bearing. - Offsetting the cache's cell index by one fails **7 of 10** parity cases, and the 3 that stay green are exactly the ones that do not touch the cache. The layering localizes a fault rather than just reporting one.
406 lines
14 KiB
C#
406 lines
14 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using Server.Engines.Pathing.Cache;
|
|
using Xunit;
|
|
|
|
namespace Server.Tests.Pathfinding;
|
|
|
|
/// <summary>
|
|
/// The .swb encoding, exercised through Write → OpenForLazy → TryReadChunk. Three transforms stack
|
|
/// in a record and each can silently corrupt the ones under it, so every chunk shape here is
|
|
/// asserted byte-identical after a round trip:
|
|
///
|
|
/// predictive-Z — a directional-Z array that matches its prediction is omitted entirely,
|
|
/// compression — each record deflates independently, or stores raw when that doesn't shrink it,
|
|
/// compact index — the trailer carries no file offsets; the reader sums record lengths instead.
|
|
///
|
|
/// Several tests assert on file size, because a round trip alone cannot tell you a transform ran:
|
|
/// an encoder that elided nothing and compressed nothing would still round-trip perfectly.
|
|
/// </summary>
|
|
[Collection("Sequential Pathfinding Tests")]
|
|
public class StepCacheFileFormatTests
|
|
{
|
|
// ---- chunk builders ----
|
|
|
|
/// <summary>
|
|
/// Per-cell varying masks and Zs. Nothing about it is uniform or predictable, so it exercises
|
|
/// the Full record with residual arrays present.
|
|
/// </summary>
|
|
private static StepChunk VariedChunk(int seed = 0)
|
|
{
|
|
var c = new StepChunk();
|
|
for (var i = 0; i < StepChunk.CellsPerChunk; i++)
|
|
{
|
|
c.WalkMask[i] = (byte)((i + seed) & 0xFF);
|
|
c.WetMask[i] = (byte)((i * 7 + seed) & 0xFF);
|
|
c.SourceZ[i] = (sbyte)((i + seed) % 40 - 20);
|
|
c.WalkZN[i] = (sbyte)(c.SourceZ[i] + i % 3);
|
|
c.SwimZS[i] = (sbyte)(c.SourceZ[i] - i % 2);
|
|
}
|
|
|
|
return c;
|
|
}
|
|
|
|
/// <summary>Every cell identical — the Uniform record, ~28 bytes on disk.</summary>
|
|
private static StepChunk UniformChunk(sbyte z = 10)
|
|
{
|
|
var c = new StepChunk();
|
|
Array.Fill(c.WalkMask, (byte)0xC1);
|
|
Array.Fill(c.SourceZ, z);
|
|
foreach (var arr in AllBaseZArrays(c))
|
|
{
|
|
Array.Fill(arr, z);
|
|
}
|
|
|
|
return c;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Flat terrain, but NOT uniform: masks and SourceZ vary per cell while every directional Z
|
|
/// equals its masked prediction. That is the exact shape predictive-Z is built for, so all 16
|
|
/// arrays must elide. It doubles as the coastline case — partial walkability, non-zero SourceZ,
|
|
/// and 0 in every blocked direction, which is where a naive (unmasked) predictor would emit a
|
|
/// -SourceZ residual on every blocked direction and elide nothing.
|
|
/// </summary>
|
|
private static StepChunk FlatFullChunk(sbyte baseZ = 10)
|
|
{
|
|
var c = new StepChunk();
|
|
for (var i = 0; i < StepChunk.CellsPerChunk; i++)
|
|
{
|
|
c.WalkMask[i] = (byte)(i & 0xFF);
|
|
c.WetMask[i] = (byte)(~i & 0xFF);
|
|
c.SourceZ[i] = (sbyte)(baseZ + i % 7 - 3);
|
|
}
|
|
|
|
var walk = new[] { c.WalkZN, c.WalkZNE, c.WalkZE, c.WalkZSE, c.WalkZS, c.WalkZSW, c.WalkZW, c.WalkZNW };
|
|
var swim = new[] { c.SwimZN, c.SwimZNE, c.SwimZE, c.SwimZSE, c.SwimZS, c.SwimZSW, c.SwimZW, c.SwimZNW };
|
|
for (var i = 0; i < StepChunk.CellsPerChunk; i++)
|
|
{
|
|
for (var b = 0; b < 8; b++)
|
|
{
|
|
walk[b][i] = (sbyte)((c.WalkMask[i] >> b & 1) != 0 ? c.SourceZ[i] : 0);
|
|
swim[b][i] = (sbyte)((c.WetMask[i] >> b & 1) != 0 ? c.SourceZ[i] : 0);
|
|
}
|
|
}
|
|
|
|
return c;
|
|
}
|
|
|
|
private static StepChunk WithSwimLayer(StepChunk c)
|
|
{
|
|
c.AllocateSwimLayer();
|
|
for (var i = 0; i < StepChunk.CellsPerChunk; i++)
|
|
{
|
|
c.SwimSourceZ[i] = (sbyte)(i % 30 - 15);
|
|
c.SwimMask[i] = (byte)(i * 5 & 0xFF);
|
|
c.SwimZN_Layer[i] = (sbyte)(i % 7);
|
|
c.SwimZNW_Layer[i] = (sbyte)-(i % 4);
|
|
}
|
|
|
|
return c;
|
|
}
|
|
|
|
private static StepChunk WithStrataAt(StepChunk c, int cell)
|
|
{
|
|
var offsets = new ushort[StepChunk.CellsPerChunk];
|
|
Array.Fill(offsets, StepChunk.NoStrata);
|
|
offsets[cell] = 0;
|
|
|
|
var data = new byte[1 + StepChunk.StratumByteLength];
|
|
data[0] = 1;
|
|
c.SetStrata(offsets, data);
|
|
|
|
return c;
|
|
}
|
|
|
|
private static sbyte[][] AllBaseZArrays(StepChunk c) =>
|
|
[
|
|
c.WalkZN, c.WalkZNE, c.WalkZE, c.WalkZSE, c.WalkZS, c.WalkZSW, c.WalkZW, c.WalkZNW,
|
|
c.SwimZN, c.SwimZNE, c.SwimZE, c.SwimZSE, c.SwimZS, c.SwimZSW, c.SwimZW, c.SwimZNW
|
|
];
|
|
|
|
private static sbyte[][] AllSwimLayerArrays(StepChunk c) =>
|
|
[
|
|
c.SwimZN_Layer, c.SwimZNE_Layer, c.SwimZE_Layer, c.SwimZSE_Layer,
|
|
c.SwimZS_Layer, c.SwimZSW_Layer, c.SwimZW_Layer, c.SwimZNW_Layer
|
|
];
|
|
|
|
// ---- round-trip plumbing ----
|
|
|
|
private static string Write(params (int cx, int cy, StepChunk c)[] chunks)
|
|
{
|
|
var path = Path.Combine(Path.GetTempPath(), $"swb_{Guid.NewGuid():N}.swb");
|
|
StepCacheFile.Write(path, 1u, chunks);
|
|
return path;
|
|
}
|
|
|
|
private static StepChunk RoundTrip(StepChunk src, out long fileLength, int cx = 3, int cy = 4)
|
|
{
|
|
var path = Write((cx, cy, src));
|
|
try
|
|
{
|
|
fileLength = new FileInfo(path).Length;
|
|
|
|
using var reader = StepCacheFile.OpenForLazy(path);
|
|
Assert.NotNull(reader);
|
|
|
|
var rt = reader!.TryReadChunk(cx, cy);
|
|
Assert.NotNull(rt);
|
|
return rt!;
|
|
}
|
|
finally
|
|
{
|
|
File.Delete(path);
|
|
}
|
|
}
|
|
|
|
private static StepChunk RoundTrip(StepChunk src) => RoundTrip(src, out _);
|
|
|
|
private static void AssertIdentical(StepChunk expected, StepChunk actual)
|
|
{
|
|
Assert.True(expected.WalkMask.AsSpan().SequenceEqual(actual.WalkMask), "WalkMask differs");
|
|
Assert.True(expected.WetMask.AsSpan().SequenceEqual(actual.WetMask), "WetMask differs");
|
|
Assert.True(expected.SourceZ.AsSpan().SequenceEqual(actual.SourceZ), "SourceZ differs");
|
|
|
|
var ez = AllBaseZArrays(expected);
|
|
var az = AllBaseZArrays(actual);
|
|
for (var i = 0; i < ez.Length; i++)
|
|
{
|
|
Assert.True(ez[i].AsSpan().SequenceEqual(az[i]), $"base Z array {i} differs");
|
|
}
|
|
|
|
Assert.Equal(expected.HasSwimLayer, actual.HasSwimLayer);
|
|
if (expected.HasSwimLayer)
|
|
{
|
|
Assert.True(expected.SwimSourceZ.AsSpan().SequenceEqual(actual.SwimSourceZ), "SwimSourceZ differs");
|
|
Assert.True(expected.SwimMask.AsSpan().SequenceEqual(actual.SwimMask), "SwimMask differs");
|
|
|
|
var el = AllSwimLayerArrays(expected);
|
|
var al = AllSwimLayerArrays(actual);
|
|
for (var i = 0; i < el.Length; i++)
|
|
{
|
|
Assert.True(el[i].AsSpan().SequenceEqual(al[i]), $"swim-layer Z array {i} differs");
|
|
}
|
|
}
|
|
|
|
Assert.True(expected.StrataData.SequenceEqual(actual.StrataData), "StrataData differs");
|
|
}
|
|
|
|
// ---- predictive-Z transform ----
|
|
|
|
[Theory]
|
|
[InlineData((sbyte)0, (sbyte)0)]
|
|
[InlineData((sbyte)10, (sbyte)10)]
|
|
[InlineData((sbyte)0, (sbyte)10)]
|
|
[InlineData((sbyte)10, (sbyte)0)]
|
|
[InlineData((sbyte)-20, (sbyte)15)]
|
|
[InlineData(sbyte.MinValue, sbyte.MaxValue)]
|
|
[InlineData(sbyte.MaxValue, sbyte.MinValue)]
|
|
[InlineData(sbyte.MinValue, (sbyte)1)]
|
|
[InlineData((sbyte)127, (sbyte)-1)]
|
|
public void Residual_RoundTripsLosslessly_AcrossTheFullSByteRange(sbyte z, sbyte predict)
|
|
{
|
|
var residual = StepCacheFile.EncodeResidual(z, predict);
|
|
Assert.Equal(z, StepCacheFile.DecodeZ(predict, residual));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData((byte)0b0000_0001, 0, (sbyte)42, (sbyte)42)] // passable -> predict SourceZ
|
|
[InlineData((byte)0b0000_0000, 0, (sbyte)42, (sbyte)0)] // blocked -> predict 0
|
|
[InlineData((byte)0b1000_0000, 7, (sbyte)-13, (sbyte)-13)]
|
|
[InlineData((byte)0b0111_1111, 7, (sbyte)-13, (sbyte)0)]
|
|
public void Predict_IsSourceZWherePassable_ZeroWhereBlocked(byte maskByte, int bit, sbyte sourceZ, sbyte expected)
|
|
{
|
|
Assert.Equal(expected, StepCacheFile.Predict(maskByte, bit, sourceZ));
|
|
}
|
|
|
|
[Fact]
|
|
public void FlatChunk_ElidesEveryZArray()
|
|
{
|
|
var src = FlatFullChunk();
|
|
var rt = RoundTrip(src, out var fileLength);
|
|
|
|
AssertIdentical(src, rt);
|
|
|
|
// A Full record carrying all 16 Z arrays runs past 5 KB. Landing under 1100 bytes is only
|
|
// possible if every one of them elided.
|
|
Assert.True(fileLength < 1100, $"expected every base Z array to elide; file was {fileLength} bytes");
|
|
}
|
|
|
|
[Fact]
|
|
public void CoastlineChunk_ElidesEveryZArray()
|
|
{
|
|
// Partial walkability with a non-zero SourceZ: the shape that defeats an unmasked predictor.
|
|
var src = FlatFullChunk(baseZ: 25);
|
|
var rt = RoundTrip(src, out var fileLength);
|
|
|
|
AssertIdentical(src, rt);
|
|
Assert.True(fileLength < 1100, $"masked predictor should elide every array; file was {fileLength} bytes");
|
|
}
|
|
|
|
[Fact]
|
|
public void SlopeInOneDirection_StoresOnlyThatZArray()
|
|
{
|
|
var flat = FlatFullChunk();
|
|
RoundTrip(flat, out var flatLength);
|
|
|
|
// Raise WalkZN on cells walkable to the north. Exactly one array (WalkZN) now disagrees
|
|
// with its prediction; the other 15 must still elide.
|
|
var sloped = FlatFullChunk();
|
|
for (var i = 0; i < StepChunk.CellsPerChunk; i++)
|
|
{
|
|
if ((sloped.WalkMask[i] & 1) != 0)
|
|
{
|
|
sloped.WalkZN[i]++;
|
|
}
|
|
}
|
|
|
|
var rt = RoundTrip(sloped, out var slopedLength);
|
|
|
|
AssertIdentical(sloped, rt);
|
|
Assert.True(slopedLength > flatLength, "a present Z array should grow the record");
|
|
Assert.True(
|
|
slopedLength <= flatLength + StepChunk.CellsPerChunk,
|
|
$"only one 256-byte residual array should have been added; grew by {slopedLength - flatLength}"
|
|
);
|
|
}
|
|
|
|
// ---- compression ----
|
|
|
|
[Fact]
|
|
public void VariedChunk_Compresses_AndRoundTrips()
|
|
{
|
|
var src = VariedChunk(seed: 4);
|
|
var rt = RoundTrip(src, out var fileLength);
|
|
|
|
AssertIdentical(src, rt);
|
|
|
|
// The uncompressed Full record for a varied chunk exceeds 5 KB.
|
|
Assert.True(fileLength < 4000, $"expected compression to shrink the record; file was {fileLength} bytes");
|
|
}
|
|
|
|
[Fact]
|
|
public void UniformChunk_StoredRaw_RoundTrips()
|
|
{
|
|
// A Uniform body is ~28 bytes and deflate cannot shrink it, so the writer stores it raw and
|
|
// the reader has to notice that from the payload length alone.
|
|
var src = UniformChunk(z: 12);
|
|
var rt = RoundTrip(src, out var fileLength);
|
|
|
|
AssertIdentical(src, rt);
|
|
Assert.True(fileLength < 200, $"uniform record should stay tiny; file was {fileLength} bytes");
|
|
}
|
|
|
|
// ---- optional trailers ----
|
|
|
|
[Fact]
|
|
public void SwimLayer_RoundTrips() => AssertIdentical(
|
|
WithSwimLayer(VariedChunk()),
|
|
RoundTrip(WithSwimLayer(VariedChunk()))
|
|
);
|
|
|
|
[Fact]
|
|
public void Strata_RoundTrips()
|
|
{
|
|
var src = WithStrataAt(VariedChunk(), cell: 10);
|
|
var rt = RoundTrip(src);
|
|
|
|
AssertIdentical(src, rt);
|
|
Assert.True(rt.IsCellMultiZ(10));
|
|
}
|
|
|
|
[Fact]
|
|
public void SwimLayerAndStrata_RoundTripTogether()
|
|
{
|
|
// Both trailers present at once, which is the only case that pins their relative order.
|
|
var src = WithStrataAt(WithSwimLayer(VariedChunk()), cell: 20);
|
|
var rt = RoundTrip(src);
|
|
|
|
AssertIdentical(src, rt);
|
|
Assert.True(rt.HasSwimLayer);
|
|
Assert.True(rt.IsCellMultiZ(20));
|
|
}
|
|
|
|
// ---- compact index ----
|
|
|
|
[Fact]
|
|
public void MultipleChunks_ResolveIndividually_FromDerivedOffsets()
|
|
{
|
|
// The index stores no offsets, so a reader that mis-sums record lengths would hand back a
|
|
// neighbouring chunk's bytes. Distinct content per coordinate is what catches that. The mix
|
|
// of record sizes matters: a raw-stored Uniform sits between two compressed Full records,
|
|
// and one coordinate is large enough to exercise the packed key's high 16 bits.
|
|
var chunks = new List<(int cx, int cy, StepChunk c)>
|
|
{
|
|
(1, 1, VariedChunk(seed: 3)),
|
|
(2, 5, UniformChunk(z: 14)),
|
|
(10, 3, VariedChunk(seed: 99)),
|
|
(300, 200, VariedChunk(seed: 17))
|
|
};
|
|
|
|
var path = Write(chunks.ToArray());
|
|
try
|
|
{
|
|
using var reader = StepCacheFile.OpenForLazy(path);
|
|
Assert.NotNull(reader);
|
|
Assert.Equal((uint)chunks.Count, reader!.ChunkCount);
|
|
|
|
foreach (var (cx, cy, src) in chunks)
|
|
{
|
|
Assert.True(reader.Has(cx, cy), $"missing chunk ({cx},{cy})");
|
|
|
|
var rt = reader.TryReadChunk(cx, cy);
|
|
Assert.NotNull(rt);
|
|
AssertIdentical(src, rt!);
|
|
}
|
|
|
|
Assert.Null(reader.TryReadChunk(7, 7)); // never written
|
|
}
|
|
finally
|
|
{
|
|
File.Delete(path);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void EmptyChunkSet_WritesAReadableFile()
|
|
{
|
|
var path = Write();
|
|
try
|
|
{
|
|
using var reader = StepCacheFile.OpenForLazy(path);
|
|
Assert.NotNull(reader);
|
|
Assert.Equal(0u, reader!.ChunkCount);
|
|
Assert.Null(reader.TryReadChunk(0, 0));
|
|
}
|
|
finally
|
|
{
|
|
File.Delete(path);
|
|
}
|
|
}
|
|
|
|
// ---- version gate ----
|
|
|
|
[Theory]
|
|
[InlineData(0u)]
|
|
[InlineData(5u)]
|
|
[InlineData(8u)]
|
|
[InlineData(StepCacheFile.FormatVersion + 1)]
|
|
public void UnsupportedVersion_IsRejected(uint version)
|
|
{
|
|
var path = Write((0, 0, UniformChunk()));
|
|
try
|
|
{
|
|
var bytes = File.ReadAllBytes(path);
|
|
BitConverter.GetBytes(version).CopyTo(bytes, 4); // Version sits right after Magic
|
|
File.WriteAllBytes(path, bytes);
|
|
|
|
Assert.Null(StepCacheFile.OpenForLazy(path));
|
|
}
|
|
finally
|
|
{
|
|
File.Delete(path);
|
|
}
|
|
}
|
|
}
|