refactor(opcua): FB-7 review nits — model-event SourceNode=Server, dataType guard, shape tests

Code-review follow-ups on the FB-7 surgical shape-write commit:
- GeneralModelChangeEvent now sets SourceNode=Server + SourceName (Part 3 §8.7.4)
  so clients filtering events by SourceNode match it (report still uses source:null).
- UpdateTagAttributes adds an explicit dataType null/empty guard (widened surface).
- Tighten the ArrayLengthDiffers doc comment.
- Add array→scalar transition test + null-arrayLength zero-default test (coverage
  symmetry). 275/275 OpcUaServer.Tests green.
This commit is contained in:
Joseph Doherty
2026-06-19 03:30:29 -04:00
parent fb094fa566
commit 7a8ae9600b
2 changed files with 59 additions and 4 deletions
@@ -1417,6 +1417,7 @@ public sealed class OtOpcUaNodeManager : CustomNodeManager2
public bool UpdateTagAttributes(string variableNodeId, bool writable, string? historianTagname, string dataType, bool isArray, uint? arrayLength)
{
ArgumentException.ThrowIfNullOrEmpty(variableNodeId);
ArgumentException.ThrowIfNullOrEmpty(dataType); // widened surface ⇒ explicit contract (unknown names still map to BaseDataType)
BaseDataVariableState? shapeChangedNode = null;
lock (Lock)
{
@@ -1457,13 +1458,14 @@ public sealed class OtOpcUaNodeManager : CustomNodeManager2
return true;
}
/// <summary>True when the node's current 1-D array length differs from the requested one (both must be
/// arrays for the comparison to matter — a scalar↔array transition is already caught by the ValueRank
/// check in <see cref="UpdateTagAttributes"/>, so this only fires for an array-to-array length edit).</summary>
/// <summary>True when an array target's requested 1-D length differs from the node's current one. This is
/// the array-to-array length-edit case: the caller's <c>ValueRank != newValueRank</c> check already catches
/// any scalar↔array transition, so this runs to decide whether an already-array node's dimension changed
/// (and treats absent/empty current dimensions as "differs", forcing the in-place update).</summary>
private static bool ArrayLengthDiffers(BaseDataVariableState v, bool isArray, uint? arrayLength)
{
if (!isArray) return false; // scalar target ⇒ ValueRank check owns the diff
if (v.ArrayDimensions is not { Count: > 0 }) return true; // was scalar/empty ⇒ shape differs
if (v.ArrayDimensions is not { Count: > 0 }) return true; // no current dimension ⇒ shape differs
return v.ArrayDimensions[0] != (arrayLength ?? 0u);
}
@@ -1483,6 +1485,11 @@ public sealed class OtOpcUaNodeManager : CustomNodeManager2
source: null,
severity: EventSeverity.Medium,
message: new LocalizedText($"Node {variable.NodeId} definition changed (DataType/ValueRank)"));
// Part 3 §8.7.4: a GeneralModelChangeEvent is emitted by the Server object — set SourceNode/SourceName
// to Server explicitly (we report with source:null since this manager has no Server NodeState handle),
// so conformant clients that filter events by SourceNode still match this one.
e.SetChildValue(SystemContext, BrowseNames.SourceNode, ObjectIds.Server, false);
e.SetChildValue(SystemContext, BrowseNames.SourceName, "Server", false);
var change = new ModelChangeStructureDataType
{
Affected = variable.NodeId,