test(grpc-data): A3 extends the recorded-v1-client gate — fake origin emits begin/total, info record, snapshot_complete, removed delta

This commit is contained in:
Joseph Doherty
2026-11-24 16:42:13 -05:00
parent 855f725660
commit bdc29ac25a
@@ -115,6 +115,32 @@ public sealed class GrpcDataV1CompatibilityTests
else cases.ShouldNotContain(W.SubscriptionFrame.FrameOneofCase.ConditionStates);
}
/// <summary>
/// A3: the fake origin now emits what the consumer registry consumes (begin with <c>total</c>, an info-carrying record,
/// <c>snapshot_complete</c>, a <c>removed</c> delta). A header-less caller — even one whose item carries a condition
/// scope — still gets the golden v1 bytes; the negotiated stream carries all three condition frames.
/// </summary>
[Fact]
[Trait("Phase", "A3")]
public async Task A3_consumer_condition_shapes_reach_only_a_negotiated_stream_and_v1_bytes_are_unchanged()
{
var open = W.SubscriptionCommand.Parser.ParseFrom(Convert.FromHexString(GrpcDataV1Goldens.Requests["Subscribe"]));
open.Open.Items[0].ConditionScope = new W.ConditionScope { IncludeInfo = true };
(await V1CompatibilityHarness.DriveAsync("Subscribe", new Metadata(), request: open.ToByteArray()))
.ShouldBe(GrpcDataV1Goldens.Responses["Subscribe"]);
(await V1CompatibilityHarness.DriveAsync("Subscribe", new Metadata(), request: Convert.FromHexString(GrpcDataV1Goldens.Requests["Subscribe"])))
.ShouldBe(GrpcDataV1Goldens.Responses["Subscribe"]);
var negotiated = (await V1CompatibilityHarness.DriveAsync("Subscribe", new Metadata { { "x-otopcua-data-features", "conditions" } },
request: open.ToByteArray())).Split('|').Select(f => W.SubscriptionFrame.Parser.ParseFrom(Convert.FromHexString(f)))
.Where(f => f.FrameCase == W.SubscriptionFrame.FrameOneofCase.ConditionStates)
.Select(ZB.MOM.WW.OtOpcUa.Commons.DataConnections.DataConditionProtoMapper.DecodeFrame).ToArray();
negotiated.Length.ShouldBe(3);
negotiated[0].Total.ShouldBe(1);
negotiated[1].SnapshotComplete.ShouldBeTrue();
negotiated[1].Items.Single().Info!.Placements.Single().Address.Identifier.ShouldBe("Plant/dev1/HR200");
negotiated[2].Items.Single().Removed.ShouldBeTrue();
}
[Fact]
public async Task H2_a_history_capable_origin_shows_history_shapes_only_with_the_header()
{
@@ -432,7 +458,21 @@ internal static class V1CompatibilityHarness
[new(0, 3)], 1, 1, "done"), token);
// A2a new-shape data: a condition-scoped item gets a snapshot-begin condition frame (arm 9).
if (open.Items[0].ConditionScope is not null)
await Emit(sink, new DataSubscriptionConditions(open.SubscriptionId, open.StreamEpoch, 5, handle, true, 0, [], true), token);
{
// A3 new-shape data (what the consumer registry consumes): begin with `total`, a record with info and a
// placement, snapshot_complete, then a delta `removed` record at the hub watermark.
await Emit(sink, new DataSubscriptionConditions(open.SubscriptionId, open.StreamEpoch, 5, handle, true, 1, [], false), token);
var placement = new DataView(new DataAddress("origin", "https://zb.com/otopcua/raw", "string", "Plant/dev1/HR200"),
DataRealm.Raw, null, 0, "Plant/dev1/HR200");
var key = new string('A', 43);
await Emit(sink, new DataSubscriptionConditions(open.SubscriptionId, open.StreamEpoch, 6, handle, true, null,
[new DataConditionState(key, 3, false, true, new DataConditionInfo("AlarmConditionType", "HR200",
DataConditionSourceKind.Native, [placement], 3), true, false, true, true, 0, 777, "high", 0, null, 0,
Source, true, new DataActivationMarker("inc", 1))], true), token);
await Emit(sink, new DataSubscriptionConditions(open.SubscriptionId, open.StreamEpoch, 7, handle, false, null,
[new DataConditionState(key, 3, true, false, null, false, false, false, false, 0, 0, "", 0, null, 0, null, false, null)],
false), token);
}
}
private static async Task Emit(IDataSubscriptionDeliverySink sink, DataSubscriptionFrame frame, CancellationToken token)
{