From 682ab3413793959cf5d39761803152be396eb5fb Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Thu, 3 Dec 2026 14:57:44 -0500 Subject: [PATCH] fix(uns): #1040 every effective-name computation goes through EquipmentReferenceMap.EffectiveName The two sites the issue named (DataConnectionValidator, LocalExportCatalog line 56) were already converted by #1002; the remaining inline copies were not. EquipmentReferenceMap.EffectiveNames itself used '??', so an empty override dropped the reference instead of naming it after its tag; the artifact-side ACL resolver used IsNullOrWhiteSpace. Both now agree with the one rule, as do the UnsTreeService rows, the composer and the local-export alarm reservation. --- .../Types/EquipmentReferenceMap.cs | 3 +- .../Uns/UnsTreeService.cs | 9 +++-- .../AddressSpaceComposer.cs | 2 +- .../LocalExportCatalog.Compilation.cs | 3 +- .../Drivers/DeploymentArtifact.cs | 5 ++- ...EquipmentReferenceMapEffectiveNameTests.cs | 35 +++++++++++++++++++ 6 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 tests/Core/ZB.MOM.WW.OtOpcUa.Commons.Tests/EquipmentReferenceMapEffectiveNameTests.cs diff --git a/src/Core/ZB.MOM.WW.OtOpcUa.Commons/Types/EquipmentReferenceMap.cs b/src/Core/ZB.MOM.WW.OtOpcUa.Commons/Types/EquipmentReferenceMap.cs index 9dc797509..06d1f2606 100644 --- a/src/Core/ZB.MOM.WW.OtOpcUa.Commons/Types/EquipmentReferenceMap.cs +++ b/src/Core/ZB.MOM.WW.OtOpcUa.Commons/Types/EquipmentReferenceMap.cs @@ -97,8 +97,7 @@ public static class EquipmentReferenceMap var names = new HashSet(StringComparer.Ordinal); foreach (var r in references) { - var effectiveName = r.DisplayNameOverride - ?? (tagNameById.TryGetValue(r.TagId, out var n) ? n : null); + var effectiveName = EffectiveName(r.DisplayNameOverride, tagNameById.TryGetValue(r.TagId, out var n) ? n : null); if (!string.IsNullOrEmpty(effectiveName)) names.Add(effectiveName); } return names; diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Uns/UnsTreeService.cs b/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Uns/UnsTreeService.cs index 39b1ed0e5..f81467b1c 100644 --- a/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Uns/UnsTreeService.cs +++ b/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Uns/UnsTreeService.cs @@ -139,13 +139,13 @@ public sealed class UnsTreeService( // Backing tag missing (should not happen — raw-tag delete is reference-blocked); surface a // clearly-degraded row rather than dropping it so the operator can remove the dangling ref. rows.Add(new EquipmentReferenceRow( - r.UnsTagReferenceId, r.DisplayNameOverride ?? "(missing tag)", "(missing tag)", + r.UnsTagReferenceId, EquipmentReferenceMap.EffectiveName(r.DisplayNameOverride, "(missing tag)")!, "(missing tag)", "", TagAccessLevel.Read, r.DisplayNameOverride, r.SortOrder, r.RowVersion)); continue; } var rawPath = resolver?.TryBuildTagPath(tag.DeviceId, tag.TagGroupId, tag.Name) ?? tag.Name; - var effectiveName = string.IsNullOrEmpty(r.DisplayNameOverride) ? tag.Name : r.DisplayNameOverride; + var effectiveName = EquipmentReferenceMap.EffectiveName(r.DisplayNameOverride, tag.Name)!; rows.Add(new EquipmentReferenceRow( r.UnsTagReferenceId, effectiveName, rawPath, tag.DataType, tag.AccessLevel, r.DisplayNameOverride, r.SortOrder, r.RowVersion)); @@ -1412,9 +1412,8 @@ public sealed class UnsTreeService( var effectiveNames = new HashSet(StringComparer.Ordinal); foreach (var r in refs) { - var eff = string.IsNullOrEmpty(r.DisplayNameOverride) - ? (tagNameById.TryGetValue(r.TagId, out var n) ? n : null) - : r.DisplayNameOverride; + var eff = EquipmentReferenceMap.EffectiveName( + r.DisplayNameOverride, tagNameById.TryGetValue(r.TagId, out var n) ? n : null); if (!string.IsNullOrEmpty(eff)) effectiveNames.Add(eff!); } return effectiveNames; diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer/AddressSpaceComposer.cs b/src/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer/AddressSpaceComposer.cs index e890af330..23f3d73dc 100644 --- a/src/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer/AddressSpaceComposer.cs +++ b/src/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer/AddressSpaceComposer.cs @@ -958,7 +958,7 @@ public static class AddressSpaceComposer if (!equipFolderPath.TryGetValue(r.EquipmentId, out var equipPath)) continue; var rawPath = topology.Resolver.TryBuildTagPath(tag.DeviceId, tag.TagGroupId, tag.Name); if (rawPath is null) continue; - var effectiveName = string.IsNullOrEmpty(r.DisplayNameOverride) ? tag.Name : r.DisplayNameOverride!; + var effectiveName = EquipmentReferenceMap.EffectiveName(r.DisplayNameOverride, tag.Name)!; string nodeId; try 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 2f92944b5..6c32fe544 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 @@ -217,8 +217,7 @@ public sealed partial class LocalExportCatalog || !equipmentById.TryGetValue(reference.EquipmentId, out var owner) || !lineById.TryGetValue(owner.UnsLineId, out var line) || !areaById.TryGetValue(line.UnsAreaId, out var area)) continue; - var effectiveName = string.IsNullOrEmpty(reference.DisplayNameOverride) ? tagById[reference.TagId].Name - : reference.DisplayNameOverride!; + var effectiveName = EquipmentReferenceMap.EffectiveName(reference.DisplayNameOverride, tagById[reference.TagId].Name)!; string reserved; try { reserved = V3NodeIds.UnsChild(V3NodeIds.Uns(area.Name, line.Name, owner.Name), effectiveName); } catch (ArgumentException) { continue; } // an invalid name segment: the deploy gate rejects it; never listed diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/Drivers/DeploymentArtifact.cs b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/Drivers/DeploymentArtifact.cs index 1f097376e..ac07a95b8 100644 --- a/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/Drivers/DeploymentArtifact.cs +++ b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/Drivers/DeploymentArtifact.cs @@ -1240,9 +1240,8 @@ internal sealed partial class ParsedDeploymentArtifact : IDisposable // Effective name = the override when present, else the backing raw tag's own name. This is the // same rule the address space materializes UNS variables under; a reference whose tag is // missing from the artifact has no resolvable name and is skipped. - var effective = ReadNullableString(el, "DisplayNameOverride"); - if (string.IsNullOrWhiteSpace(effective)) - effective = tags.TryGetValue(tagId, out var t) ? t.Name : null; + var effective = EquipmentReferenceMap.EffectiveName( + ReadNullableString(el, "DisplayNameOverride"), tags.TryGetValue(tagId, out var t) ? t.Name : null); if (effective is null) continue; references.Add((equipmentId, tagId, effective)); diff --git a/tests/Core/ZB.MOM.WW.OtOpcUa.Commons.Tests/EquipmentReferenceMapEffectiveNameTests.cs b/tests/Core/ZB.MOM.WW.OtOpcUa.Commons.Tests/EquipmentReferenceMapEffectiveNameTests.cs new file mode 100644 index 000000000..9b0bbccc9 --- /dev/null +++ b/tests/Core/ZB.MOM.WW.OtOpcUa.Commons.Tests/EquipmentReferenceMapEffectiveNameTests.cs @@ -0,0 +1,35 @@ +using Shouldly; +using Xunit; +using ZB.MOM.WW.OtOpcUa.Commons.Types; + +namespace ZB.MOM.WW.OtOpcUa.Commons.Tests; + +/// +/// lmxopcua#1040 (#978 follow-up): the effective-name rule is stated once +/// () — an EMPTY override means "no override". Every other +/// helper on the map must agree with it, including , which +/// used ?? and so dropped an empty-override reference instead of naming it after its tag. +/// +public sealed class EquipmentReferenceMapEffectiveNameTests +{ + [Theory] + [InlineData(null, "Speed", "Speed")] + [InlineData("", "Speed", "Speed")] + [InlineData("Rate", "Speed", "Rate")] + public void EffectiveName_empty_override_is_no_override(string? displayNameOverride, string tagName, string expected) => + EquipmentReferenceMap.EffectiveName(displayNameOverride, tagName).ShouldBe(expected); + + [Fact] + public void EffectiveNames_agrees_with_EffectiveName_for_an_empty_override() + { + var names = EquipmentReferenceMap.EffectiveNames( + [ + new EquipmentReferenceMap.ReferenceRow("R1", "EQ-1", "T1", ""), + new EquipmentReferenceMap.ReferenceRow("R2", "EQ-1", "T2", null), + new EquipmentReferenceMap.ReferenceRow("R3", "EQ-1", "T3", "Override"), + ], + new Dictionary { ["T1"] = "Speed", ["T2"] = "Temp", ["T3"] = "Level" }); + + names.ShouldBe(["Speed", "Temp", "Override"], ignoreOrder: true); + } +}