feat(grpc-data): X0 server parses x-otopcua-data-features on every RPC and records requested/effective (effective always empty)

This commit is contained in:
Joseph Doherty
2026-11-23 17:16:24 -05:00
parent 984b1e122a
commit 331350e2f4
2 changed files with 66 additions and 1 deletions
@@ -53,6 +53,39 @@ public sealed class GrpcDataV1CompatibilityTests
actual.ShouldBe(GrpcDataV1Goldens.Responses[rpc], $"{rpc} response must not change in X0 when features are requested");
}
[Theory]
[MemberData(nameof(Rpcs))]
public async Task Every_rpc_records_the_requested_and_effective_feature_set(string rpc)
{
var (_, absent) = await V1CompatibilityHarness.DriveWithContextAsync(rpc, new Metadata());
DataConnectionGrpcService.CallFeatures(absent).ShouldBe(DataCallFeatures.None);
absent.UserState.ContainsKey(typeof(DataCallFeatures)).ShouldBeTrue();
var (_, requested) = await V1CompatibilityHarness.DriveWithContextAsync(rpc,
new Metadata { { "x-otopcua-data-features", "history" }, { "x-otopcua-data-features", " conditions, future" } });
// X0: the server supports no feature, so whatever is asked for, nothing is effective.
DataConnectionGrpcService.CallFeatures(requested).ShouldBe(new DataCallFeatures(DataFeatures.History | DataFeatures.Conditions, DataFeatures.None));
DataConnectionGrpcService.SupportedFeatures.ShouldBe(DataFeatures.None);
}
public static TheoryData<string, string> MalformedHeaders()
{
var data = new TheoryData<string, string>();
foreach (var rpc in RpcNames) { data.Add(rpc, "binary"); data.Add(rpc, "oversized"); }
return data;
}
[Theory]
[MemberData(nameof(MalformedHeaders))]
public async Task Binary_or_oversized_feature_header_is_rejected_invalid_argument(string rpc, string shape)
{
var headers = shape == "binary"
? new Metadata { { "x-otopcua-data-features-bin", new byte[] { 0x68 } } }
: new Metadata { { "x-otopcua-data-features", "history," + new string(' ', 256) } };
var failure = await Should.ThrowAsync<RpcException>(() => V1CompatibilityHarness.DriveAsync(rpc, headers));
failure.StatusCode.ShouldBe(StatusCode.InvalidArgument);
}
internal static string Hex(byte[] bytes) => Convert.ToHexString(bytes);
/// <summary>X0: no field varies. Add explicit, listed normalisations here only if a later phase needs one.</summary>
@@ -105,9 +138,16 @@ internal static class V1Requests
/// </summary>
internal static class V1CompatibilityHarness
{
internal static async Task<string> DriveAsync(string rpc, Metadata headers)
internal static async Task<string> DriveAsync(string rpc, Metadata headers) => (await DriveWithContextAsync(rpc, headers)).Bytes;
internal static async Task<(string Bytes, ServerCallContext Context)> DriveWithContextAsync(string rpc, Metadata headers)
{
var (service, context) = Create(rpc, headers);
return (await DriveAsync(service, context, rpc), context);
}
private static async Task<string> DriveAsync(DataConnectionGrpcService service, ServerCallContext context, string rpc)
{
var bytes = V1Requests.Bytes(rpc);
IMessage response = rpc switch
{