From 053c69f1c845c6a13d284a9edfeca8090fab67c9 Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Sat, 28 Nov 2026 10:43:32 -0500 Subject: [PATCH] =?UTF-8?q?fix(grpc-data):=20#916/#917=20review=20r1=20?= =?UTF-8?q?=E2=80=94=20mapper=20never=20encodes/decodes=20stable=5Fsource?= =?UTF-8?q?=5Fid=20(proto=20field=20deprecated);=20browse=20skip=20does=20?= =?UTF-8?q?not=20consume=20the=20scan=20bound=20(no=20empty=20incomplete?= =?UTF-8?q?=20pages);=20unsupported=20nodes=20never=20writable;=20comment?= =?UTF-8?q?=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/DataConnections.md | 2 +- .../evidence/grpc-data-ext/V1-916-917.md | 21 +++++++ .../DataConnections/DataProtoMapper.cs | 7 ++- .../Protos/data_connection.proto | 2 + .../DataConnections/LocalDataServices.cs | 9 ++- .../LocalExportCatalog.Compilation.cs | 6 +- .../DataConnections/GrpcDataCodecTests.cs | 25 ++++++++ .../GrpcDataV1CompatibilityTests.cs | 57 ++++++++++++++++++- .../GrpcDataConditionPlacementTests.cs | 10 ++-- .../GrpcDataLocalConnectionTests.cs | 51 ++++++++++++++++- 10 files changed, 173 insertions(+), 17 deletions(-) diff --git a/docs/DataConnections.md b/docs/DataConnections.md index 32dd49e00..701144c35 100644 --- a/docs/DataConnections.md +++ b/docs/DataConnections.md @@ -194,7 +194,7 @@ Neither change alters the wire shape: one drops an optional field, the other dro - **Browse does not list it**, and the same holds for any unsupported value node, such as a data type v1 cannot carry. Every consumer build applies a browse page all or nothing and cannot materialise an `UnsupportedVariable`. Listing one made the whole folder unbrowsable on the consumer (`BadNoCommunication`); the live gate found this. - - The node stays in the catalog, so an export rooted at it still compiles. + - The node stays in the catalog, so an export rooted at it still compiles. Such a root grants nothing: the values are unsupported, and the condition sits under the tag's folder, not under the tag. - The alarm itself is forwarded as a **condition** (A1–A4, see "Condition forwarding end to end"). Condition placements do not depend on the value node. diff --git a/docs/plans/evidence/grpc-data-ext/V1-916-917.md b/docs/plans/evidence/grpc-data-ext/V1-916-917.md index f7cd51ef7..dbed3e40e 100644 --- a/docs/plans/evidence/grpc-data-ext/V1-916-917.md +++ b/docs/plans/evidence/grpc-data-ext/V1-916-917.md @@ -157,3 +157,24 @@ A Client.CLI browse of consumer-1 then showed `remote-opc` → `FastUInt1` only, The live run does not separately probe `stable_source_id` over gRPC. #916 is pinned by the wire-level real-origin gate and the 60-seed property test above. + +## Review round 1 (2026-11-28) + +| Finding | Fix | Red/green | +|---|---|---| +| #916 defence in depth: the mapper still encoded field 10 if anything set it | `DataProtoMapper.EncodeMetadata` never writes field 10. `DecodeMetadata` drops it, so a consumer of a pre-fix origin never retains it in `OriginMetadata`. The proto marks field 10 deprecated in a comment (not renumbered or removed) | `GrpcDataCodecTests.Stable_source_id_is_never_encoded_and_is_dropped_on_decode_916`: red with master's mapper, green with the fix. Engineering units (field 11) are the positive control | +| The fake-origin gate's goldens carry field 10 from its fake metadata, so the mapper change moves them | `GrpcDataV1Corrections.Expected` clears field 10 on the parsed Browse/GetMetadata goldens. That is the only edit, and the goldens are not re-recorded | `V1_correction_916_clears_only_stable_source_id`: the recording really carried field 10, an unedited golden re-serialises identically, and the other RPCs compare raw | +| Browse page boundaries | A skipped unsupported node no longer counts against the page's scan bound. The budget timeout still bounds the call. The skip therefore never yields an empty `Complete=false` page | `GrpcDataLocalConnectionTests.Browse_skips_unsupported_value_nodes_across_page_boundaries_917`, page size 2 over `[Speed, u, u, u, v, u, v]`. Red before the fix (an empty first-continuation page). Green after: `Speed, c3, c5` each exactly once, 2 non-empty pages, completes. Positive control: the skipped nodes are addressable (`Unsupported`) | +| Internal metadata still said an unsupported node was writable | `Add` compiles `writable &= supported` (raw tags, UNS references, virtual tags) | The #917 test fixture's alarm tag is now `ReadWrite`. `alarm.Metadata.Writable.ShouldBeFalse()` was red before the change and green after. Positive control: the same tag without its alarm is writable | +| Stale "browsable" test doc; "an export may still be rooted at it" | Both reworded. Such a root compiles, but grants nothing: the values are unsupported, and the condition placement sits under the tag's folder, not under the tag | — | + +A consumer receiving an empty `Complete=false` page is no longer produced by this change. It can still come from the +pre-existing name filter. Whether the consumer resolver tolerates one was not tested end to end; it is suggested as a +follow-up. + +Gates after the review, Release: + +- Commons.Tests: 513/513. +- Runtime.Tests `Feature=GrpcData`: 1024/1024. +- Host.Tests `Feature=GrpcData`: 211/211. This includes both v1 gates. +- `dotnet build -c Release`: 0 warnings, 0 errors. diff --git a/src/Core/ZB.MOM.WW.OtOpcUa.Commons/DataConnections/DataProtoMapper.cs b/src/Core/ZB.MOM.WW.OtOpcUa.Commons/DataConnections/DataProtoMapper.cs index ba7a6bc84..8d1e7b39a 100644 --- a/src/Core/ZB.MOM.WW.OtOpcUa.Commons/DataConnections/DataProtoMapper.cs +++ b/src/Core/ZB.MOM.WW.OtOpcUa.Commons/DataConnections/DataProtoMapper.cs @@ -258,8 +258,8 @@ public static class DataProtoMapper v.Dimensions.AddRange(x.Dimensions); if (x.ArrayElementKind is { } elementKind) v.ArrayElementKind = (W.ValueKind)elementKind; - if (x.StableSourceId is not null) - v.StableSourceId = x.StableSourceId; + // #916: field 10 (stable_source_id) is never encoded, whatever the caller set. It carried the origin's internal + // acquisition key (driver instance id + RawPath), and no consumer needs it. if (x.EngineeringUnits is not null) v.EngineeringUnits = x.EngineeringUnits; // H2: the service strips this (and the HistoryRead bit) from every response of a call that did not negotiate history. @@ -288,7 +288,8 @@ public static class DataProtoMapper // A2b method bits are condition grants, never node operations, so a metadata item carrying them is masked too. (DataOperations)(x.AllowedOperations & (uint)DataOperationSets.Understood & ~(uint)DataOperationSets.ConditionGrants), x.CatalogRevision, - x.HasStableSourceId ? x.StableSourceId : null, + // #916: dropped on decode too, so a consumer of a pre-fix origin never retains it in OriginMetadata. + null, x.HasEngineeringUnits ? x.EngineeringUnits : null, x.IsStale, x.HasArrayElementKind ? (DataValueKind)x.ArrayElementKind : null, diff --git a/src/Core/ZB.MOM.WW.OtOpcUa.Commons/Protos/data_connection.proto b/src/Core/ZB.MOM.WW.OtOpcUa.Commons/Protos/data_connection.proto index 188c4416f..de130c405 100644 --- a/src/Core/ZB.MOM.WW.OtOpcUa.Commons/Protos/data_connection.proto +++ b/src/Core/ZB.MOM.WW.OtOpcUa.Commons/Protos/data_connection.proto @@ -161,6 +161,8 @@ message Metadata { bool writable = 7; uint32 allowed_operations = 8; int64 catalog_revision = 9; + // DEPRECATED (#916): never sent and ignored on receipt. It carried the origin's internal acquisition key (driver + // instance id + RawPath). Kept so the field number is never reused. optional string stable_source_id = 10; optional string engineering_units = 11; bool is_stale = 12; diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/LocalDataServices.cs b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/LocalDataServices.cs index b708fef71..a1c001907 100644 --- a/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/LocalDataServices.cs +++ b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/LocalDataServices.cs @@ -394,16 +394,19 @@ public sealed partial class LocalDataServices : IDataConnectionFactory long bytes = 256; var maximum = Math.Min(request.Budget.MaxItems, limits.MaxPageItems); var scanned = 0; - while (offset < children.Count && page.Count < maximum && scanned++ < maximum) + while (offset < children.Count && page.Count < maximum && scanned < maximum) { cancellationToken.ThrowIfCancellationRequested(); if (Expired(start, request.Budget)) return Task.FromResult(Empty(DataItemStatus.Unavailable)); var child = children[offset++]; // #917: an unsupported value node (an alarm-bearing tag, or a data type v1 cannot carry) is never listed. Every // consumer build applies a browse page all-or-nothing and cannot materialise one, so listing it made the whole - // folder unbrowsable on the consumer (BadNoCommunication). It stays addressable: GetMetadata/Read/Subscribe on - // it answer Unsupported, and an export may still be rooted at it. + // folder unbrowsable on the consumer (BadNoCommunication). It stays addressable (GetMetadata/Read/Subscribe on it + // answer Unsupported). An export rooted at it still compiles but grants nothing. A skipped node is not counted + // against the scan bound (it costs one check; the budget timeout above still bounds the call), so the skip never + // yields an empty Complete=false page. if (child.Source is not null && !child.Supported) continue; + scanned++; if ((request.Filter is { Length: > 0 } filter && !child.Metadata.BrowseName.Contains(filter, StringComparison.Ordinal)) || !Allowed(catalog, context, child, DataOperations.Browse)) continue; var metadata = Metadata(catalog, context, target, child); diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/LocalExportCatalog.Compilation.cs b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/LocalExportCatalog.Compilation.cs index 498a510e3..36a9c876d 100644 --- a/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/LocalExportCatalog.Compilation.cs +++ b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/LocalExportCatalog.Compilation.cs @@ -92,6 +92,7 @@ public sealed partial class LocalExportCatalog BackingSourceKey? source = null, DataValueKind valueKind = DataValueKind.Null, bool writable = false, bool array = false, uint? length = null, bool supported = true, bool enabled = true) { + writable &= supported; // #917 review: an unsupported value node is never writable, not even in internal metadata var operations = source is null ? navigation : data | (writable ? DataOperations.Write : DataOperations.None); var metadata = new DataMetadata(view, name, source is null ? "Folder" : supported ? "Variable" : "UnsupportedVariable", array && supported ? DataValueKind.Array : valueKind, array && supported ? 1 : -1, @@ -137,8 +138,9 @@ public sealed partial class LocalExportCatalog var kind = ValueKind(plan.DataType); // #917: an alarm-bearing tag never gets a value (DriverHostActor keeps it out of the value fan-out; #896 gives it // no UNS variable), so it is an unsupported value node: Browse does not list it (LocalDataServices) and every - // value operation answers Unsupported, instead of a Variable a consumer would wait on forever. The node is KEPT - // (an export may be rooted at it); its alarm is forwarded as a condition (A1–A4), never as a value. + // value operation answers Unsupported, instead of a Variable a consumer would wait on forever. The node is KEPT so + // an export rooted at it still compiles, but such a root grants nothing: its values are unsupported and its + // condition placement sits under its folder, not under the tag. The alarm is forwarded as a condition (A1–A4). var supported = plan.Alarm is null && kind != DataValueKind.Unspecified && (!plan.IsArray || DataValue.IsSupportedArrayElementKind(kind)); var rawView = View(DataRealm.Raw, plan.NodeId, scope); diff --git a/tests/Core/ZB.MOM.WW.OtOpcUa.Commons.Tests/DataConnections/GrpcDataCodecTests.cs b/tests/Core/ZB.MOM.WW.OtOpcUa.Commons.Tests/DataConnections/GrpcDataCodecTests.cs index 514422142..1ee96c60d 100644 --- a/tests/Core/ZB.MOM.WW.OtOpcUa.Commons.Tests/DataConnections/GrpcDataCodecTests.cs +++ b/tests/Core/ZB.MOM.WW.OtOpcUa.Commons.Tests/DataConnections/GrpcDataCodecTests.cs @@ -148,6 +148,31 @@ public sealed class GrpcDataCodecTests } } + /// + /// #916 defence in depth: the mapper never encodes stable_source_id (field 10), whatever a caller sets, and + /// drops it on decode so a consumer of a pre-fix origin never retains it. Engineering units (field 11) are the + /// positive control: an optional string in the same message still round-trips. + /// + [Fact] + public void Stable_source_id_is_never_encoded_and_is_dropped_on_decode_916() + { + var view = new DataView(new DataAddress("c", "urn:test", "string", "x"), DataRealm.Uns, null, 0, "subject"); + var metadata = new DataMetadata(view, "x", "Variable", DataValueKind.Int32, -1, [], false, DataOperations.Read, 1, + "8:driver-1Plant/Modbus/dev1/Speed", "rpm", false); + + var wire = DataProtoMapper.EncodeMetadata(metadata); + wire.HasStableSourceId.ShouldBeFalse(); + ZB.MOM.WW.OtOpcUa.Commons.Protos.DataConnection.V1.Metadata.Parser.ParseFrom(wire.ToByteArray()).HasStableSourceId.ShouldBeFalse(); + wire.EngineeringUnits.ShouldBe("rpm"); + + // A pre-fix origin's bytes: field 10 present on the wire. + var legacy = wire.Clone(); + legacy.StableSourceId = "8:driver-1Plant/Modbus/dev1/Speed"; + var decoded = DataProtoMapper.DecodeMetadata(legacy); + decoded.StableSourceId.ShouldBeNull(); + decoded.EngineeringUnits.ShouldBe("rpm"); + } + [Fact] public void Array_metadata_rejects_missing_and_invalid_element_kind() { diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.Host.Tests/DataConnections/GrpcDataV1CompatibilityTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.Host.Tests/DataConnections/GrpcDataV1CompatibilityTests.cs index 0b24ef423..a3119ce88 100644 --- a/tests/Server/ZB.MOM.WW.OtOpcUa.Host.Tests/DataConnections/GrpcDataV1CompatibilityTests.cs +++ b/tests/Server/ZB.MOM.WW.OtOpcUa.Host.Tests/DataConnections/GrpcDataV1CompatibilityTests.cs @@ -64,12 +64,30 @@ public sealed class GrpcDataV1CompatibilityTests Hex(V1Requests.Bytes(rpc)).ShouldBe(GrpcDataV1Goldens.Requests[rpc], $"recorded {rpc} request"); } + /// #916: the only correction of the fake-origin goldens is field 10, and the recording really carried it. + [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; } + +/// +/// #916 (pre-deploy, never re-recorded): DataProtoMapper no longer encodes Metadata.stable_source_id +/// (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 +/// (). +/// +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()); + } +} + /// The recorded v1 client requests. Changing any value here invalidates the goldens. internal static class V1Requests { diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataConditionPlacementTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataConditionPlacementTests.cs index 2bda6602b..ef5f773ab 100644 --- a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataConditionPlacementTests.cs +++ b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataConditionPlacementTests.cs @@ -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 /// /// #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 UnsupportedVariable 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 UnsupportedVariable, 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. /// [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); diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataLocalConnectionTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataLocalConnectionTests.cs index d7338e99f..9b3b91ac2 100644 --- a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataLocalConnectionTests.cs +++ b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataLocalConnectionTests.cs @@ -33,6 +33,43 @@ public sealed class GrpcDataLocalConnectionTests expired.Items.ShouldBeEmpty(); } + /// + /// #917 review: Browse skips unsupported value nodes across page boundaries. With a page size of 2 and children + /// [Speed, u, u, u, v, u, v], 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 Complete = false page. + /// + [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(); + 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? 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 }]);