fix(grpc-data): #916/#917 review r1 — mapper never encodes/decodes stable_source_id (proto field deprecated); browse skip does not consume the scan bound (no empty incomplete pages); unsupported nodes never writable; comment fixes
This commit is contained in:
+54
-3
@@ -64,12 +64,30 @@ public sealed class GrpcDataV1CompatibilityTests
|
||||
Hex(V1Requests.Bytes(rpc)).ShouldBe(GrpcDataV1Goldens.Requests[rpc], $"recorded {rpc} request");
|
||||
}
|
||||
|
||||
/// <summary>#916: the only correction of the fake-origin goldens is field 10, and the recording really carried it.</summary>
|
||||
[Fact]
|
||||
public void V1_correction_916_clears_only_stable_source_id()
|
||||
{
|
||||
foreach (var rpc in RpcNames.Where(r => r != "Subscribe"))
|
||||
{
|
||||
var golden = GrpcDataV1Goldens.Responses[rpc];
|
||||
if (GrpcDataV1Corrections.Corrected.Contains(rpc))
|
||||
{
|
||||
GrpcDataV1Corrections.Expected(rpc).ShouldNotBe(golden, $"{rpc}: the recorded fake metadata carried field 10");
|
||||
IMessage parsed = rpc == "Browse" ? W.BrowseResponse.Parser.ParseFrom(Convert.FromHexString(golden))
|
||||
: W.MetadataResponse.Parser.ParseFrom(Convert.FromHexString(golden));
|
||||
Hex(parsed.ToByteArray()).ShouldBe(golden, $"{rpc}: re-serialising a golden is byte-identical");
|
||||
}
|
||||
else GrpcDataV1Corrections.Expected(rpc).ShouldBe(golden);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Rpcs))]
|
||||
public async Task V1_client_without_feature_header_gets_the_recorded_v1_response_bytes(string rpc)
|
||||
{
|
||||
var actual = await V1CompatibilityHarness.DriveAsync(rpc, new Metadata());
|
||||
actual.ShouldBe(GrpcDataV1Goldens.Responses[rpc], $"{rpc} response diverged from the recorded v1 bytes");
|
||||
actual.ShouldBe(GrpcDataV1Corrections.Expected(rpc), $"{rpc} response diverged from the recorded v1 bytes");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -79,9 +97,9 @@ public sealed class GrpcDataV1CompatibilityTests
|
||||
// H2 supports history, but this origin advertises none (and conditions are A2): the effective set is empty.
|
||||
var headers = new Metadata { { "x-otopcua-data-features", "history,conditions" } };
|
||||
var actual = await V1CompatibilityHarness.DriveAsync(rpc, headers, history: false, conditions: false);
|
||||
actual.ShouldBe(GrpcDataV1Goldens.Responses[rpc], $"{rpc} response must not change when nothing requested is servable");
|
||||
actual.ShouldBe(GrpcDataV1Corrections.Expected(rpc), $"{rpc} response must not change when nothing requested is servable");
|
||||
(await V1CompatibilityHarness.DriveAsync(rpc, new Metadata { { "x-otopcua-data-features", "conditions" } }, conditions: false))
|
||||
.ShouldBe(GrpcDataV1Goldens.Responses[rpc], $"{rpc}: conditions on an origin that cannot serve them change nothing");
|
||||
.ShouldBe(GrpcDataV1Corrections.Expected(rpc), $"{rpc}: conditions on an origin that cannot serve them change nothing");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -254,6 +272,39 @@ public sealed class GrpcDataV1CompatibilityTests
|
||||
internal static IMessage Normalise(IMessage message) => message;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// #916 (pre-deploy, never re-recorded): <c>DataProtoMapper</c> no longer encodes <c>Metadata.stable_source_id</c>
|
||||
/// (field 10), so the fake origin's metadata loses it on the wire. The expected bytes are the recorded golden with field 10
|
||||
/// cleared on every Metadata of Browse and GetMetadata. That is the only edit. The real-origin variant has its own corrections
|
||||
/// (<see cref="GrpcDataV1RealOriginCorrections"/>).
|
||||
/// </summary>
|
||||
internal static class GrpcDataV1Corrections
|
||||
{
|
||||
internal static readonly string[] Corrected = ["Browse", "GetMetadata"];
|
||||
|
||||
internal static string Expected(string rpc)
|
||||
{
|
||||
var golden = GrpcDataV1Goldens.Responses[rpc];
|
||||
if (!Corrected.Contains(rpc)) return golden;
|
||||
var bytes = Convert.FromHexString(golden);
|
||||
IMessage corrected;
|
||||
if (rpc == "Browse")
|
||||
{
|
||||
var response = W.BrowseResponse.Parser.ParseFrom(bytes);
|
||||
foreach (var item in response.Items) item.ClearStableSourceId();
|
||||
corrected = response;
|
||||
}
|
||||
else
|
||||
{
|
||||
var response = W.MetadataResponse.Parser.ParseFrom(bytes);
|
||||
foreach (var item in response.Items) item.Value?.ClearStableSourceId();
|
||||
corrected = response;
|
||||
}
|
||||
return Convert.ToHexString(corrected.ToByteArray());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The recorded v1 client requests. Changing any value here invalidates the goldens.</summary>
|
||||
internal static class V1Requests
|
||||
{
|
||||
|
||||
+6
-4
@@ -46,7 +46,7 @@ public sealed class GrpcDataConditionPlacementTests
|
||||
Devices = [new() { DeviceId = "device", DriverInstanceId = "driver-id-7f3", Name = "Device", DeviceConfig = "{}" }],
|
||||
TagGroups = [new() { TagGroupId = "group", DeviceId = "device", Name = "Group" }],
|
||||
Tags = [new() { TagId = "tag", DeviceId = "device", Name = "Speed", DataType = "Int32", AccessLevel = TagAccessLevel.ReadWrite, TagConfig = "{}" },
|
||||
new() { TagId = "alarm-tag", DeviceId = "device", TagGroupId = "group", Name = "OverTemp", DataType = "Boolean", AccessLevel = TagAccessLevel.Read,
|
||||
new() { TagId = "alarm-tag", DeviceId = "device", TagGroupId = "group", Name = "OverTemp", DataType = "Boolean", AccessLevel = TagAccessLevel.ReadWrite,
|
||||
TagConfig = withAlarms ? AlarmConfig : "{}" }],
|
||||
UnsAreas = [new() { UnsAreaId = "area-id", ClusterId = "cluster", Name = "Area" }],
|
||||
UnsLines = [new() { UnsLineId = "line-id", UnsAreaId = "area-id", Name = "Line" }],
|
||||
@@ -345,9 +345,10 @@ public sealed class GrpcDataConditionPlacementTests
|
||||
|
||||
/// <summary>
|
||||
/// #917: an alarm-bearing raw tag gets no value (DriverHostActor keeps it out of the value fan-out, and #896 gives it
|
||||
/// no UNS variable), so v1 exports it as the pre-existing explicit <c>UnsupportedVariable</c> kind: browsable, with
|
||||
/// no Read/Subscribe/Write/HistoryRead bit, and Unsupported on every value operation — never a Variable that waits
|
||||
/// forever. Its condition placements (A1) are untouched, and an export rooted at it still compiles.
|
||||
/// no UNS variable), so v1 compiles it as an unsupported value node: kind <c>UnsupportedVariable</c>, never writable
|
||||
/// (the fixture tag is ReadWrite), Unsupported on every value operation, and NOT listed by Browse — never a Variable
|
||||
/// that waits forever. Its condition placements (A1) are untouched. An export rooted at it still compiles (the
|
||||
/// deploy is not broken) but grants nothing: its values are unsupported and its condition is not under the root.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void An_alarm_bearing_raw_tag_is_an_UnsupportedVariable_and_keeps_its_condition_placements_917()
|
||||
@@ -370,6 +371,7 @@ public sealed class GrpcDataConditionPlacementTests
|
||||
plain.Supported.ShouldBeTrue();
|
||||
plain.Metadata.NodeKind.ShouldBe("Variable");
|
||||
plain.Metadata.ValueKind.ShouldBe(DataValueKind.Boolean);
|
||||
plain.Metadata.Writable.ShouldBeTrue(); // the same ReadWrite tag without its alarm IS writable
|
||||
|
||||
// Condition forwarding is unaffected: the Raw placement at its RawPath and both UNS placements remain.
|
||||
catalog.PlacementsOf(new(AddressSpaceRealm.Raw, "Plant/Driver/Device/Group/OverTemp")).Count.ShouldBe(3);
|
||||
|
||||
+50
-1
@@ -33,6 +33,43 @@ public sealed class GrpcDataLocalConnectionTests
|
||||
expired.Items.ShouldBeEmpty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// #917 review: Browse skips unsupported value nodes across page boundaries. With a page size of 2 and children
|
||||
/// <c>[Speed, u, u, u, v, u, v]</c>, every supported child appears exactly once, no unsupported one appears, the walk
|
||||
/// completes, and no page is empty: a skipped node does not count against the page's scan bound, so the skip
|
||||
/// never produces an empty <c>Complete = false</c> page.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task Browse_skips_unsupported_value_nodes_across_page_boundaries_917()
|
||||
{
|
||||
using var fixture = new LocalDataFixture(siblingPattern: "uuuvuv");
|
||||
await using var connection = fixture.Connection();
|
||||
var budget = LocalDataFixture.Budget with { MaxItems = 2 };
|
||||
var seen = new List<string>();
|
||||
var pages = 0;
|
||||
string? continuation = null;
|
||||
while (true)
|
||||
{
|
||||
var page = await connection.BrowseAsync(new(fixture.Root, null, continuation, budget), TestContext.Current.CancellationToken);
|
||||
page.Status.ShouldBe(DataItemStatus.Good);
|
||||
page.Items.ShouldNotBeEmpty($"page {pages}");
|
||||
page.Items.Count.ShouldBeLessThanOrEqualTo(2);
|
||||
seen.AddRange(page.Items.Select(x => x.BrowseName));
|
||||
pages++;
|
||||
if (page.Complete) { page.Continuation.ShouldBeNull(); break; }
|
||||
page.Continuation.ShouldNotBeNull();
|
||||
continuation = page.Continuation;
|
||||
pages.ShouldBeLessThan(10);
|
||||
}
|
||||
seen.ShouldBe(["Speed", "c3", "c5"]);
|
||||
pages.ShouldBe(2);
|
||||
// Positive control: the unsupported siblings are in the catalog and addressable (Unsupported, not NotFound).
|
||||
fixture.Catalog.Nodes.Count(n => !n.Supported).ShouldBe(4);
|
||||
var metadata = await connection.GetMetadataAsync(new([fixture.Root with { Address = fixture.Root.Address with { Identifier = "Plant/c0" },
|
||||
Subject = "Plant/c0" }], LocalDataFixture.Budget), TestContext.Current.CancellationToken);
|
||||
metadata.ShouldHaveSingleItem().Status.ShouldBe(DataItemStatus.Unsupported);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Metadata_bootstrap_resolves_address_and_never_uses_the_claimed_subject_as_authority()
|
||||
{
|
||||
@@ -136,7 +173,8 @@ internal sealed class LocalDataFixture : IDisposable
|
||||
bool advanceAuthority = false, string role = "Primary", long servingGeneration = 0, bool nestedCatalog = false, bool nestedUnsCatalog = false,
|
||||
Func<DataAuthenticatedContext, IDataWriteService>? writes = null, bool denyReadExport = false,
|
||||
ManualTimeProvider? clock = null, string servingNode = "node-a", string servingIncarnation = "serving-1",
|
||||
IOriginHistoryPort? history = null, DataValueKind rawValueKind = DataValueKind.Int32, int maxBatchItems = 100)
|
||||
IOriginHistoryPort? history = null, DataValueKind rawValueKind = DataValueKind.Int32, int maxBatchItems = 100,
|
||||
string? siblingPattern = null)
|
||||
{
|
||||
if (clock is not null) Clock = clock;
|
||||
Serving = Serving with { NodeId = servingNode, Incarnation = servingIncarnation, Role = role, ServingGeneration = servingGeneration };
|
||||
@@ -191,6 +229,17 @@ internal sealed class LocalDataFixture : IDisposable
|
||||
nodes.Add(new("RawTag", "extra-" + i, rawMetadata with { View = view, BrowseName = "Speed" + i },
|
||||
new() { ClusterId = "cluster", Kind = NodeHierarchyKind.Raw, Segments = ["Plant", "Driver", "Device", "Speed" + i] }, Root, Ticket.Key));
|
||||
}
|
||||
// #917: "u" = an unsupported value node (as an alarm-bearing tag compiles), "v" = a supported one, named c0, c1, ...
|
||||
// in order (they sort after "Speed"), all under Root.
|
||||
for (var i = 0; i < (siblingPattern?.Length ?? 0); i++)
|
||||
{
|
||||
var name = "c" + i.ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||
var view = Raw with { Address = Raw.Address with { Identifier = "Plant/" + name }, Subject = "Plant/" + name };
|
||||
var supported = siblingPattern![i] == 'v';
|
||||
nodes.Add(new("RawTag", "sibling-" + name, supported ? rawMetadata with { View = view, BrowseName = name }
|
||||
: rawMetadata with { View = view, BrowseName = name, NodeKind = "UnsupportedVariable", ValueKind = DataValueKind.Null, Writable = false },
|
||||
new() { ClusterId = "cluster", Kind = NodeHierarchyKind.Raw, Segments = ["Plant", name] }, Root, Ticket.Key, Supported: supported));
|
||||
}
|
||||
Catalog = new LocalExportCatalog("cluster", Serving, Activation.CaptureAuthority(), nodes,
|
||||
[new() { DataExportId = "raw-export", ClusterId = "cluster", Enabled = true, Realm = DataRealm.Raw, RootKind = "RawFolder", RootEntityId = "folder", PrincipalId = "peer", AllowedOperations = operations },
|
||||
new() { DataExportId = "uns-export", ClusterId = "cluster", Enabled = true, Realm = DataRealm.Uns, RootKind = nestedUnsCatalog ? "UnsArea" : "UnsTagReference", RootEntityId = nestedUnsCatalog ? "area" : "reference", PrincipalId = "peer", AllowedOperations = operations }]);
|
||||
|
||||
Reference in New Issue
Block a user