Auto: focas-f2d — PMC range coalescing

Closes #266
This commit is contained in:
Joseph Doherty
2026-04-25 20:02:10 -04:00
parent 9ebe5bd523
commit 4d3ee47235
7 changed files with 836 additions and 0 deletions

View File

@@ -80,6 +80,33 @@ internal class FakeFocasClient : IFocasClient
return Task.CompletedTask;
}
/// <summary>
/// Per-letter / per-path byte storage the coalesced range path reads from. Tests
/// populate <c>PmcByteRanges[("R", 1)] = new byte[size]</c> + the corresponding values to
/// drive both the per-tag <see cref="ReadAsync"/> + the coalesced
/// <see cref="ReadPmcRangeAsync"/> path against the same source of truth (issue #266).
/// </summary>
public Dictionary<(string Letter, int PathId), byte[]> PmcByteRanges { get; } = new();
/// <summary>
/// Ordered log of <c>pmc_rdpmcrng</c>-shaped range calls observed on this fake
/// session — one entry per coalesced wire call. Tests assert this count to verify
/// coalescing actually collapsed N per-byte reads into one range read (issue #266).
/// </summary>
public List<(string Letter, int PathId, int StartByte, int ByteCount)> RangeReadLog { get; } = new();
public virtual Task<(byte[]? buffer, uint status)> ReadPmcRangeAsync(
string letter, int pathId, int startByte, int byteCount, CancellationToken ct)
{
RangeReadLog.Add((letter, pathId, startByte, byteCount));
if (!PmcByteRanges.TryGetValue((letter.ToUpperInvariant(), pathId), out var src))
return Task.FromResult<(byte[]?, uint)>((new byte[byteCount], FocasStatusMapper.Good));
var buf = new byte[byteCount];
var copy = Math.Min(byteCount, Math.Max(0, src.Length - startByte));
if (copy > 0) Array.Copy(src, startByte, buf, 0, copy);
return Task.FromResult<(byte[]?, uint)>((buf, FocasStatusMapper.Good));
}
public virtual void Dispose()
{
DisposeCount++;