diff --git a/docs/DataConnections.md b/docs/DataConnections.md index 07fc7c2db..83f75db09 100644 --- a/docs/DataConnections.md +++ b/docs/DataConnections.md @@ -170,11 +170,32 @@ advertisement and a per-call request header, `x-otopcua-data-features`, whose va - The new RPCs (`HistoryRead`, `CallConditionMethod`) answer `FailedPrecondition("feature not negotiated")`. A history-only call is also refused `CallConditionMethod`. - Header-less goldens (`*Goldens.cs`) and the recorded-v1-client gates (`GrpcDataV1CompatibilityTests`, - `GrpcDataV1RealOriginCompatibilityTests`) pin the v1 bytes. Every phase ran them with an empty goldens diff. + `GrpcDataV1RealOriginCompatibilityTests`) pin the v1 bytes. Every phase ran them with an empty goldens diff. The two + pre-deploy corrections below are the only deliberate differences. The real-origin gate applies them to the recorded + goldens in `GrpcDataV1RealOriginCorrections`; the goldens are never re-recorded. -Fix two v1 defects before any v1 deploy. #916: `stable_source_id` leaks the driver id and RawPath to UNS-only peers. -#917: v1 exports alarm-bearing raw tags as variables that never get a value. G0, the v1 deploy and soak (#915), is still -open; see the plan's §1.1. +### What an origin exports (v1 corrections #916, #917) + +v1 was merged but not deployed (#915), so two defects were fixed in v1 itself. Header-less callers get the fix too. +Neither change alters the wire shape. Evidence: `docs/plans/evidence/grpc-data-ext/V1-916-917.md`. + +- **No `Metadata.stable_source_id` (#916).** The origin never sends field 10. It used to carry the internal acquisition key, + which for a driver tag is `:`. That disclosed driver ids and RawPaths to peers holding + only a UNS export. + - No consumer used the field except for byte accounting, so it was dropped rather than replaced by an opaque id. A + stable opaque id would only let a peer correlate Raw and UNS nodes. + - The field is `optional`. Old consumers decode its absence as null, so every version mix works. + - Conditions dedupe on the keyed `condition_key` instead. + - Internally the origin still keys acquisition on the unchanged `BackingSourceKey`. +- **Alarm-bearing raw tags are `UnsupportedVariable` (#917).** A tag with an alarm config never gets a value: the driver + host keeps it out of the value fan-out, and #896 gives it no UNS variable. + - It is still browsable, so exports rooted at it and its folder's condition placement still work. + - Its node kind is `UnsupportedVariable` and its value kind `NULL`, with Browse as the only operation. Read, Subscribe, + GetMetadata and HistoryRead answer `Unsupported`, and writes are refused. + - Consumers already skip that kind, so nothing waits on a value that never comes. + - The alarm itself is forwarded as a **condition** (A1–A4, see "Condition forwarding end to end"). + +G0, the v1 deploy and soak (#915), is still open; see the plan's §1.1. ## Remote history (runtime consumers) diff --git a/docs/plans/2026-11-23-grpc-data-connections-history-alarms-plan.md b/docs/plans/2026-11-23-grpc-data-connections-history-alarms-plan.md index 9c518385b..e74c7c34d 100644 --- a/docs/plans/2026-11-23-grpc-data-connections-history-alarms-plan.md +++ b/docs/plans/2026-11-23-grpc-data-connections-history-alarms-plan.md @@ -614,7 +614,9 @@ per-origin-cluster `${secret:}` of at least 32 UTF-8 bytes, identical on both pa - It cannot be dictionary-reversed from guessable paths. An unkeyed hash was rejected for that reason. - If the secret is absent, the origin advertises no `conditions` capability (fail closed, with a diagnostic). -> **Pre-existing v1 findings (not fixed here; filed as #916 and #917):** +> **Pre-existing v1 findings (not fixed here; filed as #916 and #917).** *Update 2026-11-28: both are fixed in v1 before +> deploy. `stable_source_id` is no longer sent, and alarm-bearing raw tags are exported as `UnsupportedVariable`. See +> `docs/plans/evidence/grpc-data-ext/V1-916-917.md`.* > 1. #916 — `type:review-finding`, security: v1 already sends `stable_source_id` = driver id + RawPath on **UNS reference variables** > to UNS-only principals (same code path). > 2. #917 — `type:bug`: v1 exports alarm-bearing raw tags as `Variable` (`LocalExportCatalog.Compilation.cs:120-130` has no Alarm diff --git a/docs/plans/evidence/grpc-data-ext/V1-916-917.md b/docs/plans/evidence/grpc-data-ext/V1-916-917.md new file mode 100644 index 000000000..c5b2d73f6 --- /dev/null +++ b/docs/plans/evidence/grpc-data-ext/V1-916-917.md @@ -0,0 +1,111 @@ +# v1 pre-deploy corrections: #916 and #917 + +Two defects in gRPC data connections v1 (merged `95c5e484`, never deployed, #915), found while planning remote history and +alarm forwarding (plan §5.2, "Pre-existing v1 findings"; N3). Both are fixed in the v1 origin catalog +(`LocalExportCatalog.Compilation.cs`), so header-less v1 callers get the fix too. Neither changes the wire shape. + +## #916: `Metadata.stable_source_id` disclosed driver ids and RawPaths + +**Defect.** `Compile` put `BackingSourceKey.StableSourceId` into `Metadata.stable_source_id` (proto field 10) on every value +node, in every realm. For a driver source that key is `SourceKey.ForDriver`'s `:`, +and the reference is the RawPath. So a peer holding only a UNS export learned the origin's driver instance ids and RawPaths. +The recorded real-origin golden shows the leak: `Browse/uns` carries `8:driver-1Plant/Modbus/dev1/Speed` on the UNS Speed +reference. + +**Consumer-side uses of the field (all of them).** Every read of `DataMetadata.StableSourceId` / `Metadata.stable_source_id` +in `src/`: + +| Site | Use | +|---|---| +| `DataProtoMapper.EncodeMetadata` / `DecodeMetadata` | Copies it when present. Decodes absence as `null` (`HasStableSourceId`). | +| `ProjectedProofSize.cs:21` | Byte accounting of a proof. | +| `OtOpcUaNodeManager.cs:4439` | Byte accounting of a projected definition. | + +Nothing dedupes on it, compares it, keys on it, or exposes it to the consumer's own OPC UA clients. It is not an OPC UA +property, not shown in the AdminUI and not logged. `DataSourceIdentity.StableSourceId` (Core.Abstractions) has no users. +A1–A4 dedupe conditions by the keyed `condition_key` (`ConditionKeys`), never by this field. + +**Decision: omit the field on every export, in every realm.** We considered two alternatives: + +- *A keyed opaque id* (HMAC like `condition_key`). Rejected. No consumer uses the field, so an opaque value would only be a + stable cross-realm correlator: it would tell a peer holding both a Raw and a UNS export that two nodes share a source. + It would also depend on `DataConnections:ConditionKeySecret`, which is optional, so the field would come and go with an + unrelated setting. +- *Omit only where the realm differs.* Rejected. A Raw export also does not need the internal key, and keeping one rule + is simpler to audit. + +**Mixed versions.** Field 10 is `optional`. An old consumer decodes its absence as `null` and uses it for nothing but size +accounting, so an upgraded origin works with old consumers, and a new consumer works with an old origin (it ignores +the value). + +One effect to know about: consumers compare whole `DataMetadata` records, field 10 included, when they renew a +projection (`ProjectedCatalogCache.SameMetadata`, `OtOpcUaNodeManager` projected-variable reuse). An origin pair running a +pre-fix build on one member and this build on the other would therefore look like a metadata change at failover, and the +node would be re-projected once. No pre-fix build was ever deployed (#915), so this cannot happen in the field. + +The internal `BackingSourceKey` (on `LocalDataNode.Source`) is unchanged: acquisition, sample routing, +partitioning, write routes and `SourceKey.TryDriver` still use it. + +## #917: alarm-bearing raw tags were exported as Variables that never get a value + +**Defect.** `Compile` added every raw tag plan as a `Variable` with Read/Subscribe/HistoryRead. An alarm-bearing tag +(`RawTagPlan.Alarm != null`) never receives a value, because `DriverHostActor` keeps it out of the value fan-out and #896 +gives it no UNS variable. So a consumer that imported one read `BadWaitingForInitialData` forever. + +**Are these tags now forwarded as conditions?** Yes. Since A1–A4, every alarm-bearing raw tag gets a native condition +placement at its RawPath in Raw (parented at its device or group folder). Every UNS reference to one gets a placement at +the reserved `Area/Line/Equipment/EffectiveName` id, parented at the equipment. Both are listed through root-scoped +condition items and keyed by `condition_key`, and the consumer materialises them in its `mapped/conditions` namespace. +The alarm is therefore served as a condition, never as a value. + +**Decision: export the tag as the existing explicit `UnsupportedVariable` kind** (`supported = plan.Alarm is null && …`). +We did not remove the node, for three reasons: + +- `UnsupportedVariable` is already a v1 kind (used for unmapped data types). Old consumers already treat it as "not a + value node" (`ProjectedCatalogCache.IsValueNode`, `OtOpcUaNodeManager.cs:4988`), so no consumer materialises or waits on + it. +- Every value gate already keys on `LocalDataNode.Supported`. Read, Subscribe and GetMetadata answer `Unsupported`. + History requires `Supported`. Writes are refused by `DataWriteDispatchGate`. Browse masks the operations to Browse. +- Removing the node would turn a deployable `DataExport` rooted at that tag (`RootKind = RawTag` is valid) into a catalog + compile failure ("Export has no valid origin root") for the whole cluster. + +Condition placements are independent of the value node. They need only their parent folder or equipment, so condition +forwarding is unchanged. + +## The v1 gate: goldens not re-recorded + +`GrpcDataV1RealOriginGoldens` (recorded on `1086593a`) captured both defects. The goldens stay as recorded. The new +`GrpcDataV1RealOriginCorrections.Expected(scenario)` applies exactly two edits to the parsed golden message and +re-serialises it: + +- it clears `stable_source_id` on every Metadata; +- it makes HighTemp `UnsupportedVariable` / `VALUE_KIND_NULL` / `allowed_operations = 1` in Browse pages, and + `status = Unsupported` with no value and no lease in GetMetadata. + +The test then compares the real origin's header-less bytes with the result. Only Browse, Browse/uns and GetMetadata are +corrected. GetCapabilities, Read, Write, Write/no-write-grant and Subscribe are compared with the raw goldens, unchanged. +`V1_corrections_916_917_are_exact_and_the_recorded_leak_was_real` pins the method: + +- an unedited golden re-serialises byte-identically, so an edit is the only possible difference; +- the corrected scenarios really differ from the goldens, and the others really do not; +- the recorded UNS browse really contains the leaked `driver-1Plant/Modbus/dev1/`, and no corrected scenario does; +- HighTemp is the single Unsupported item in GetMetadata. + +The fake-origin gate `GrpcDataV1CompatibilityTests` is untouched and green. + +Before the fix, the decoded diff of real-origin output against the goldens was exactly these edits: field 10 on every +value node of Browse, Browse/uns and GetMetadata, plus the HighTemp entries. + +## Red/green + +| Test | Before the fix (master behaviour) | After | +|---|---|---| +| `GrpcDataConditionPlacementTests.No_exported_metadata_carries_the_internal_source_key_916` (60 generated topologies; encoded metadata of every node; UNS bytes searched for every driver id and RawPath; positive control: the internal key still contains them) | **Failed**: `node.Metadata.StableSourceId should be null` | Pass | +| `GrpcDataConditionPlacementTests.An_alarm_bearing_raw_tag_is_an_UnsupportedVariable_and_keeps_its_condition_placements_917` (positive controls: a plain tag and the same tag without alarm config stay `Variable`; 3 placements and the Raw listing intact; an export rooted at the alarm tag compiles) | **Failed**: alarm tag `Supported` was true | Pass | +| `GrpcDataV1RealOriginCompatibilityTests` header-less + feature-header Browse, Browse/uns, GetMetadata vs the raw goldens | Pass on master; fail with the fix | Compared with `Expected(...)`: pass | + +## Gate runs (Release) + +- Runtime.Tests `Feature=GrpcData`: 1023/1023 passed. +- Host.Tests `Feature=GrpcData`: 210/210 passed. This includes `GrpcDataV1CompatibilityTests`, + `GrpcDataV1RealOriginCompatibilityTests` and `GrpcDataHistoryWireTests`. diff --git a/docs/plans/evidence/grpc-data-ext/X0.md b/docs/plans/evidence/grpc-data-ext/X0.md index 2c4d0035a..5a2ed7eac 100644 --- a/docs/plans/evidence/grpc-data-ext/X0.md +++ b/docs/plans/evidence/grpc-data-ext/X0.md @@ -220,6 +220,10 @@ pre-H2 master `1086593a`. 2. Still expect these exact bytes **without** the header. 3. Expect them **with** the header too, until the server advertises the feature in `SupportedFeatures`. 4. Never re-record. +- **Pre-deploy corrections (#916, #917; 2026-11-28).** Two deliberate v1 fixes change real-origin Browse, Browse/uns and + GetMetadata. `GrpcDataV1RealOriginCorrections.Expected` applies exactly those edits to the parsed, unre-recorded golden: + it clears `stable_source_id` and makes the alarm-bearing HighTemp `UnsupportedVariable` / `Unsupported`. A test pins that + the edits are the only difference. See `V1-916-917.md`. ## 3. Gate runs diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/ConditionKeys.cs b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/ConditionKeys.cs index 2ce9ca776..51c289d24 100644 --- a/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/ConditionKeys.cs +++ b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/ConditionKeys.cs @@ -19,7 +19,7 @@ namespace ZB.MOM.WW.OtOpcUa.Runtime.DataConnections; /// failover and re-deploys, identical on both pair members (the secret is a per-cluster ${secret:}), and /// equal across every listing and principal (m-T6), so a consumer dedupes a condition's Raw and UNS placements. /// Being keyed, it cannot be dictionary-reversed from guessable RawPaths, and it carries no RawPath or driver id -/// (unlike Metadata.stable_source_id, #916). +/// (the v1 Metadata.stable_source_id did, and is no longer sent, #916). /// /// /// Without a secret the origin advertises no conditions capability (fail closed): 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 887178e5a..f08ba1885 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 @@ -96,7 +96,11 @@ public sealed partial class LocalExportCatalog var metadata = new DataMetadata(view, name, source is null ? "Folder" : supported ? "Variable" : "UnsupportedVariable", array && supported ? DataValueKind.Array : valueKind, array && supported ? 1 : -1, array && supported ? Array.AsReadOnly(new[] { length is { } n ? checked((int)n) : 0 }) : [], - writable, operations, serving.CatalogEpoch, source?.StableSourceId, null, false, + // #916: Metadata.stable_source_id is never sent. The internal key of a driver source is + // ":" (SourceKey.ForDriver), which told a UNS-only peer the origin's driver ids + // and RawPaths; no consumer uses the field (it is optional on the wire and old consumers decode its absence as + // null). Acquisition keys on the LocalDataNode.Source BackingSourceKey, which is unchanged. + writable, operations, serving.CatalogEpoch, null, null, false, array && supported ? valueKind : null); nodes.Add(new(kind, id, metadata, scope, parent, source, supported, enabled)); views.Add((view.Realm, kind, id.ToUpperInvariant()), view); @@ -131,7 +135,13 @@ public sealed partial class LocalExportCatalog var enabled = deviceById[tagById[plan.TagId].DeviceId].Enabled && driverById[plan.DriverInstanceId].Enabled; rawSources.Add(plan.NodeId, (source, enabled)); var kind = ValueKind(plan.DataType); - var supported = kind != DataValueKind.Unspecified && (!plan.IsArray || DataValue.IsSupportedArrayElementKind(kind)); + // #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 exported as the explicit v1 UnsupportedVariable kind — browsable, Unsupported on + // every value operation — rather than a Variable a consumer would wait on forever. The node is KEPT (an export + // may be rooted at it, and its group folder still parents the A1 condition placement); its alarm is forwarded + // as a condition (A1–A4), never as a value. + var supported = plan.Alarm is null && kind != DataValueKind.Unspecified + && (!plan.IsArray || DataValue.IsSupportedArrayElementKind(kind)); var rawView = View(DataRealm.Raw, plan.NodeId, scope); Add("RawTag", plan.TagId, plan.Name, rawView, scope, RawParent(scope), source, supported ? kind : DataValueKind.Null, plan.Writable && (!plan.IsArray || plan.ArrayWritable), diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.Host.Tests/DataConnections/GrpcDataHistoryWireTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.Host.Tests/DataConnections/GrpcDataHistoryWireTests.cs index e6d22dc68..f30877cde 100644 --- a/tests/Server/ZB.MOM.WW.OtOpcUa.Host.Tests/DataConnections/GrpcDataHistoryWireTests.cs +++ b/tests/Server/ZB.MOM.WW.OtOpcUa.Host.Tests/DataConnections/GrpcDataHistoryWireTests.cs @@ -69,7 +69,7 @@ public sealed class GrpcDataHistoryWireTests byId["Plant/Modbus/dev1/Speed"].History.Historizing.ShouldBeFalse(); (byId["Plant/Modbus/dev1/Speed"].AllowedOperations & 32u).ShouldBe(0u); // Header-less: the golden (no Metadata.history, no bit 32). - (await origin.DriveAsync("GetMetadata", new Metadata())).ShouldBe(GrpcDataV1RealOriginGoldens.Responses["GetMetadata"]); + (await origin.DriveAsync("GetMetadata", new Metadata())).ShouldBe(GrpcDataV1RealOriginCorrections.Expected("GetMetadata")); // A caller whose ACL lacks HistoryRead sees historizing=false on Flow: the same as an unhistorized node. await using var denied = new RealOrigin(permissions: NodePermissions.Operator & ~NodePermissions.HistoryRead); var deniedMeta = W.MetadataResponse.Parser.ParseFrom(Convert.FromHexString(await denied.DriveAsync("GetMetadata", History))); diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.Host.Tests/DataConnections/GrpcDataV1RealOriginCompatibilityTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.Host.Tests/DataConnections/GrpcDataV1RealOriginCompatibilityTests.cs index d5d70d4cb..2d2d06d7f 100644 --- a/tests/Server/ZB.MOM.WW.OtOpcUa.Host.Tests/DataConnections/GrpcDataV1RealOriginCompatibilityTests.cs +++ b/tests/Server/ZB.MOM.WW.OtOpcUa.Host.Tests/DataConnections/GrpcDataV1RealOriginCompatibilityTests.cs @@ -66,13 +66,47 @@ public sealed class GrpcDataV1RealOriginCompatibilityTests Hex(RealOriginRequests.Bytes(scenario)).ShouldBe(GrpcDataV1RealOriginGoldens.Requests[scenario], $"recorded {scenario} request"); } + /// + /// #916/#917: the corrections are exact and not vacuous — an unedited golden re-serialises byte-identically, the + /// uncorrected scenarios are the raw goldens, the recorded UNS browse really leaked the driver id + RawPath, and the + /// corrected bytes carry neither the leak nor a value-bearing HighTemp. + /// + [Fact] + public void V1_corrections_916_917_are_exact_and_the_recorded_leak_was_real() + { + foreach (var scenario in RealOriginRequests.Scenarios.Where(s => s != "Subscribe")) + { + var golden = GrpcDataV1RealOriginGoldens.Responses[scenario]; + IMessage parsed = scenario.Split('/')[0] switch + { + "GetCapabilities" => W.CapabilitiesResponse.Parser.ParseFrom(Convert.FromHexString(golden)), + "Browse" => W.BrowseResponse.Parser.ParseFrom(Convert.FromHexString(golden)), + "GetMetadata" => W.MetadataResponse.Parser.ParseFrom(Convert.FromHexString(golden)), + "Read" => W.ReadResponse.Parser.ParseFrom(Convert.FromHexString(golden)), + _ => W.WriteResponse.Parser.ParseFrom(Convert.FromHexString(golden)), + }; + Hex(parsed.ToByteArray()).ShouldBe(golden, $"{scenario}: re-serialising a golden is byte-identical"); + if (GrpcDataV1RealOriginCorrections.Corrected.Contains(scenario)) + GrpcDataV1RealOriginCorrections.Expected(scenario).ShouldNotBe(golden, $"{scenario} carries a corrected field"); + else + GrpcDataV1RealOriginCorrections.Expected(scenario).ShouldBe(golden); + } + var leak = Hex(System.Text.Encoding.UTF8.GetBytes("driver-1Plant/Modbus/dev1/")); + GrpcDataV1RealOriginGoldens.Responses["Browse/uns"].ShouldContain(leak, Case.Sensitive, "the recorded v1 UNS browse leaked it (#916)"); + foreach (var scenario in GrpcDataV1RealOriginCorrections.Corrected) + GrpcDataV1RealOriginCorrections.Expected(scenario).ShouldNotContain(leak, Case.Sensitive); + var metadata = W.MetadataResponse.Parser.ParseFrom(Convert.FromHexString(GrpcDataV1RealOriginCorrections.Expected("GetMetadata"))); + metadata.Items.Count(x => x.Status == (int)DataItemStatus.Unsupported).ShouldBe(1); + metadata.Items.ShouldNotContain(x => x.Value != null && x.Value.View.Address.Identifier == RealOriginRequests.HighTemp.Address.Identifier); + } + [Theory] [MemberData(nameof(Scenarios))] public async Task V1_client_without_feature_header_gets_the_recorded_v1_response_bytes(string scenario) { await using var origin = new RealOrigin(); var actual = await origin.DriveAsync(scenario, new Metadata()); - actual.ShouldBe(GrpcDataV1RealOriginGoldens.Responses[scenario], $"{scenario} response diverged from the recorded v1 bytes"); + actual.ShouldBe(GrpcDataV1RealOriginCorrections.Expected(scenario), $"{scenario} response diverged from the recorded v1 bytes"); } [Theory] @@ -83,10 +117,10 @@ public sealed class GrpcDataV1RealOriginCompatibilityTests // effective set is empty and the bytes are v1. await using var origin = new RealOrigin(historian: false, conditions: false); var actual = await origin.DriveAsync(scenario, new Metadata { { "x-otopcua-data-features", "history,conditions" } }); - actual.ShouldBe(GrpcDataV1RealOriginGoldens.Responses[scenario], $"{scenario} response must not change when nothing requested is servable"); + actual.ShouldBe(GrpcDataV1RealOriginCorrections.Expected(scenario), $"{scenario} response must not change when nothing requested is servable"); await using var conditionsOnly = new RealOrigin(conditions: false); (await conditionsOnly.DriveAsync(scenario, new Metadata { { "x-otopcua-data-features", "conditions" } })) - .ShouldBe(GrpcDataV1RealOriginGoldens.Responses[scenario], $"{scenario}: conditions on an origin that cannot serve them change nothing"); + .ShouldBe(GrpcDataV1RealOriginCorrections.Expected(scenario), $"{scenario}: conditions on an origin that cannot serve them change nothing"); } [Fact] @@ -219,6 +253,59 @@ public sealed class GrpcDataV1RealOriginCompatibilityTests internal static IMessage Normalise(IMessage message) => message; } +/// +/// The deliberate pre-deploy v1 corrections (#916, #917; v1 was merged but never deployed, #915). The goldens in +/// are NOT re-recorded: the expected bytes are the recorded golden with exactly +/// these edits applied to its parsed message, and every other byte must still match. Re-serialising an unedited golden is +/// byte-identical (asserted), so the edit is the only difference. Nothing here changes the wire SHAPE — both corrections +/// use fields and values a v1 client already handles (an absent optional field; the existing UnsupportedVariable kind and +/// Unsupported status, which the consumer already treats as "not a value node"). +/// +/// #916 — Metadata.stable_source_id is never sent (it was <len>:<driverInstanceId><RawPath>, even on +/// UNS exports). Cleared on every Metadata of every Browse/GetMetadata response. +/// #917 — the alarm-bearing raw tag (HighTemp) is exported as UnsupportedVariable: in a Browse page it is +/// node_kind = "UnsupportedVariable", value_kind = NULL, allowed_operations = Browse (the existing +/// unsupported-node masking); a GetMetadata item for it is status = Unsupported with no value and no lease. +/// +/// +internal static class GrpcDataV1RealOriginCorrections +{ + internal static readonly string[] Corrected = ["Browse", "Browse/uns", "GetMetadata"]; + + internal static string Expected(string scenario) + { + var golden = GrpcDataV1RealOriginGoldens.Responses[scenario]; + if (!Corrected.Contains(scenario)) return golden; + var bytes = Convert.FromHexString(golden); + var alarm = RealOriginRequests.HighTemp.Address.Identifier; + IMessage corrected; + if (scenario == "GetMetadata") + { + var response = W.MetadataResponse.Parser.ParseFrom(bytes); + foreach (var item in response.Items) + { + if (item.Value is null) continue; + if (item.Value.View.Address.Identifier == alarm && item.Value.View.Realm == (int)DataRealm.Raw) + { item.Status = (int)DataItemStatus.Unsupported; item.Value = null; item.Lease = null; continue; } + item.Value.ClearStableSourceId(); + } + corrected = response; + } + else + { + var response = W.BrowseResponse.Parser.ParseFrom(bytes); + foreach (var item in response.Items) + { + item.ClearStableSourceId(); + if (item.View.Address.Identifier == alarm && item.View.Realm == (int)DataRealm.Raw) + { item.NodeKind = "UnsupportedVariable"; item.ValueKind = W.ValueKind.Null; item.AllowedOperations = (uint)DataOperations.Browse; } + } + corrected = response; + } + return GrpcDataV1RealOriginCompatibilityTests.Hex(corrected.ToByteArray()); + } +} + /// The recorded v1 client requests against 's catalog. Changing any value invalidates the goldens. internal static class RealOriginRequests { diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.Host.Tests/DataConnections/GrpcDataV1RealOriginGoldens.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.Host.Tests/DataConnections/GrpcDataV1RealOriginGoldens.cs index 68f1c8c46..10dd3780c 100644 --- a/tests/Server/ZB.MOM.WW.OtOpcUa.Host.Tests/DataConnections/GrpcDataV1RealOriginGoldens.cs +++ b/tests/Server/ZB.MOM.WW.OtOpcUa.Host.Tests/DataConnections/GrpcDataV1RealOriginGoldens.cs @@ -6,6 +6,8 @@ namespace ZB.MOM.WW.OtOpcUa.Host.Tests.DataConnections; /// NEVER re-record these to make a later phase (H2, A2, A3, ...) pass: a difference is a v1 wire regression of the /// real origin, not a stale golden. A later phase extends 's snapshot with its new-shape data /// and must still produce these exact bytes for a headerless (and, while unsupported, a feature-requesting) v1 call. +/// The only sanctioned differences are the pre-deploy corrections #916/#917, applied to these bytes (not re-recorded) by +/// . /// internal static class GrpcDataV1RealOriginGoldens { 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 b6b0bb006..2bda6602b 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 @@ -2,6 +2,7 @@ using System.Security.Cryptography; using System.Text.Json; using Shouldly; using Xunit; +using ZB.MOM.WW.OtOpcUa.Commons.DataConnections; using ZB.MOM.WW.OtOpcUa.Commons.OpcUa; using ZB.MOM.WW.OtOpcUa.Configuration.Entities; using ZB.MOM.WW.OtOpcUa.Configuration.Enums; @@ -306,6 +307,81 @@ public sealed class GrpcDataConditionPlacementTests listedNative.ShouldBeGreaterThan(20); // the generator really exercised native UNS placements } + /// + /// #916: no exported metadata carries stable_source_id — a driver source's internal key is + /// <len>:<driverInstanceId><RawPath>, so sending it told a UNS-only peer the origin's driver ids and + /// RawPaths. The internal is unchanged (positive control: it still holds both, so the + /// search below would see a leak). Checked on the encoded wire bytes of every node, every realm, 60 seeds. + /// + [Fact] + public void No_exported_metadata_carries_the_internal_source_key_916() + { + var checkedSources = 0; + for (var seed = 1; seed <= 60; seed++) + { + var (snapshot, rawPaths, driverIds, _) = Generate(seed); + using var fixture = new LocalDataFixture(); + var catalog = LocalExportCatalog.Compile(snapshot, fixture.Serving, fixture.Activation.CaptureAuthority()); + foreach (var node in catalog.Nodes) + { + node.Metadata.StableSourceId.ShouldBeNull($"seed {seed} {node.EntityKind} {node.EntityId}"); + var wire = DataProtoMapper.EncodeMetadata(node.Metadata); + wire.HasStableSourceId.ShouldBeFalse(); + if (node.Metadata.View.Realm != DataRealm.Uns) continue; + var text = wire.ToString(); + foreach (var rawPath in rawPaths) text.ShouldNotContain(rawPath, Case.Sensitive, $"seed {seed}"); + foreach (var driverId in driverIds) text.ShouldNotContain(driverId, Case.Sensitive, $"seed {seed}"); + // Positive control: the internal key of a driver-backed UNS reference still names its driver and RawPath. + if (node.Source is { SourceKind: "driver" } source) + { + driverIds.ShouldContain(d => source.StableSourceId.Contains(d, StringComparison.Ordinal)); + rawPaths.ShouldContain(r => source.StableSourceId.EndsWith(r, StringComparison.Ordinal)); + checkedSources++; + } + } + } + checkedSources.ShouldBeGreaterThan(20); // the generator really produced driver-backed UNS references + } + + /// + /// #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. + /// + [Fact] + public void An_alarm_bearing_raw_tag_is_an_UnsupportedVariable_and_keeps_its_condition_placements_917() + { + using var fixture = new LocalDataFixture(); + var catalog = LocalExportCatalog.Compile(Fixed(), fixture.Serving, fixture.Activation.CaptureAuthority()); + var alarm = catalog.Nodes.Single(n => n.EntityKind == "RawTag" && n.EntityId == "alarm-tag"); + alarm.Supported.ShouldBeFalse(); + alarm.Metadata.NodeKind.ShouldBe("UnsupportedVariable"); + alarm.Metadata.ValueKind.ShouldBe(DataValueKind.Null); + alarm.Metadata.Writable.ShouldBeFalse(); + // (Every value gate keys on Supported; the operations a caller sees are masked to Browse by LocalDataServices — + // pinned on the wire by GrpcDataV1RealOriginCompatibilityTests.) + // Positive controls: a plain tag is still a Variable, and the same tag without its alarm config is one too. + var speed = catalog.Nodes.Single(n => n.EntityKind == "RawTag" && n.EntityId == "tag"); + speed.Supported.ShouldBeTrue(); + speed.Metadata.NodeKind.ShouldBe("Variable"); + var plain = LocalExportCatalog.Compile(Fixed(withAlarms: false), fixture.Serving, fixture.Activation.CaptureAuthority()) + .Nodes.Single(n => n.EntityKind == "RawTag" && n.EntityId == "alarm-tag"); + plain.Supported.ShouldBeTrue(); + plain.Metadata.NodeKind.ShouldBe("Variable"); + plain.Metadata.ValueKind.ShouldBe(DataValueKind.Boolean); + + // 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); + catalog.ListConditions("raw-peer", LocalExportCatalog.RealmRoot("cluster", DataRealm.Raw), DataOperations.Subscribe, + ConditionKeys.FromSecret(Secret)).ShouldHaveSingleItem(); + + // A deployable export rooted at the alarm-bearing tag still compiles (the node is kept, not removed). + var b = Fixed(); + Should.NotThrow(() => LocalExportCatalog.Compile(With(b, exports: [.. b.DataExports, + Export("tag-root", DataRealm.Raw, "tag-peer", rootKind: "RawTag", rootId: "alarm-tag")]), fixture.Serving, fixture.Activation.CaptureAuthority())); + } + private static (DraftSnapshot Snapshot, string[] RawPaths, string[] DriverIds, int ExpectedUnsNative) Generate(int seed) { var random = new Random(seed);