refactor(server): SparseArrayExpander throws a domain exception, mapped to InvalidArgument in the gRPC layer (mxaccessgw#190)

Adds SparseArrayException so the Sessions layer no longer throws Grpc.Core.RpcException;
MxAccessGatewayService.MapException maps it to StatusCode.InvalidArgument (client-visible
behaviour unchanged). Adds a service-level mapping test.
This commit is contained in:
Joseph Doherty
2026-11-09 12:08:36 -05:00
parent 8ba5667b7a
commit 0d156b56cc
6 changed files with 63 additions and 30 deletions
@@ -161,6 +161,28 @@ public sealed class MxAccessGatewayServiceTests
Assert.Equal(0, sessionManager.InvokeCount);
}
/// <summary>
/// Verifies that an invalid sparse-array write (a Sessions-layer <c>SparseArrayException</c>) surfaces
/// to gRPC clients as <c>InvalidArgument</c> rather than <c>Unavailable</c> (mxaccessgw#190).
/// </summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task Invoke_WhenSparseArrayInvalid_MapsToInvalidArgument()
{
FakeSessionManager sessionManager = new()
{
InvokeException = new SparseArrayException("Sparse array total_length must be greater than zero."),
};
sessionManager.SeedSession(CreateSession("session-1", processId: 1234));
MxAccessGatewayService service = CreateService(sessionManager);
RpcException exception = await Assert.ThrowsAsync<RpcException>(
async () => await service.Invoke(CreatePingRequest("session-1"), new TestServerCallContext()));
Assert.Equal(StatusCode.InvalidArgument, exception.StatusCode);
Assert.Contains("total_length", exception.Status.Detail);
}
/// <summary>Verifies that Invoke returns HResult status and method payload from worker reply.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]