Renames all 11 projects (5 src + 6 tests), the .slnx solution file, all source-file namespaces, all axaml namespace references, and all v1 documentation references in CLAUDE.md and docs/*.md (excluding docs/v2/ which is already in OtOpcUa form). Also updates the TopShelf service registration name from "LmxOpcUa" to "OtOpcUa" per Phase 0 Task 0.6.
Preserves runtime identifiers per Phase 0 Out-of-Scope rules to avoid breaking v1/v2 client trust during coexistence: OPC UA `ApplicationUri` defaults (`urn:{GalaxyName}:LmxOpcUa`), server `EndpointPath` (`/LmxOpcUa`), `ServerName` default (feeds cert subject CN), `MxAccessConfiguration.ClientName` default (defensive — stays "LmxOpcUa" for MxAccess audit-trail consistency), client OPC UA identifiers (`ApplicationName = "LmxOpcUaClient"`, `ApplicationUri = "urn:localhost:LmxOpcUaClient"`, cert directory `%LocalAppData%\LmxOpcUaClient\pki\`), and the `LmxOpcUaServer` class name (class rename out of Phase 0 scope per Task 0.5 sed pattern; happens in Phase 1 alongside `LmxNodeManager → GenericDriverNodeManager` Core extraction). 23 LmxOpcUa references retained, all enumerated and justified in `docs/v2/implementation/exit-gate-phase-0.md`.
Build clean: 0 errors, 30 warnings (lower than baseline 167). Tests at strict improvement over baseline: 821 passing / 1 failing vs baseline 820 / 2 (one flaky pre-existing failure passed this run; the other still fails — both pre-existing and unrelated to the rename). `Client.UI.Tests`, `Historian.Aveva.Tests`, `Client.Shared.Tests`, `IntegrationTests` all match baseline exactly. Exit gate compliance results recorded in `docs/v2/implementation/exit-gate-phase-0.md` with all 7 checks PASS or DEFERRED-to-PR-review (#7 service install verification needs Windows service permissions on the reviewer's box).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
209 lines
7.9 KiB
C#
209 lines
7.9 KiB
C#
using System.Collections.Generic;
|
|
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.Host.Domain;
|
|
using ZB.MOM.WW.OtOpcUa.Host.OpcUa;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Tests.OpcUa
|
|
{
|
|
public class AddressSpaceDiffTests
|
|
{
|
|
private static GalaxyObjectInfo Obj(int id, string tag, int parent = 0, bool isArea = false)
|
|
{
|
|
return new GalaxyObjectInfo
|
|
{
|
|
GobjectId = id, TagName = tag, BrowseName = tag, ContainedName = tag, ParentGobjectId = parent,
|
|
IsArea = isArea
|
|
};
|
|
}
|
|
|
|
private static GalaxyAttributeInfo Attr(int gobjectId, string name, string tagName = "Obj", int mxDataType = 5)
|
|
{
|
|
return new GalaxyAttributeInfo
|
|
{
|
|
GobjectId = gobjectId, AttributeName = name, FullTagReference = $"{tagName}.{name}",
|
|
MxDataType = mxDataType, TagName = tagName
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifies that identical Galaxy hierarchy and attribute snapshots produce no incremental rebuild work.
|
|
/// </summary>
|
|
[Fact]
|
|
public void NoChanges_ReturnsEmptySet()
|
|
{
|
|
var h = new List<GalaxyObjectInfo> { Obj(1, "A") };
|
|
var a = new List<GalaxyAttributeInfo> { Attr(1, "X") };
|
|
|
|
var changed = AddressSpaceDiff.FindChangedGobjectIds(h, a, h, a);
|
|
changed.ShouldBeEmpty();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifies that newly deployed Galaxy objects are flagged for OPC UA subtree creation.
|
|
/// </summary>
|
|
[Fact]
|
|
public void AddedObject_Detected()
|
|
{
|
|
var oldH = new List<GalaxyObjectInfo> { Obj(1, "A") };
|
|
var newH = new List<GalaxyObjectInfo> { Obj(1, "A"), Obj(2, "B") };
|
|
var a = new List<GalaxyAttributeInfo>();
|
|
|
|
var changed = AddressSpaceDiff.FindChangedGobjectIds(oldH, a, newH, a);
|
|
changed.ShouldContain(2);
|
|
changed.ShouldNotContain(1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifies that removed Galaxy objects are flagged so their OPC UA subtree can be torn down.
|
|
/// </summary>
|
|
[Fact]
|
|
public void RemovedObject_Detected()
|
|
{
|
|
var oldH = new List<GalaxyObjectInfo> { Obj(1, "A"), Obj(2, "B") };
|
|
var newH = new List<GalaxyObjectInfo> { Obj(1, "A") };
|
|
var a = new List<GalaxyAttributeInfo>();
|
|
|
|
var changed = AddressSpaceDiff.FindChangedGobjectIds(oldH, a, newH, a);
|
|
changed.ShouldContain(2);
|
|
changed.ShouldNotContain(1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifies that browse-name changes are treated as address-space changes for the affected Galaxy object.
|
|
/// </summary>
|
|
[Fact]
|
|
public void ModifiedObject_BrowseNameChange_Detected()
|
|
{
|
|
var oldH = new List<GalaxyObjectInfo> { Obj(1, "A") };
|
|
var newH = new List<GalaxyObjectInfo>
|
|
{ new() { GobjectId = 1, TagName = "A", BrowseName = "A_Renamed", ContainedName = "A" } };
|
|
var a = new List<GalaxyAttributeInfo>();
|
|
|
|
var changed = AddressSpaceDiff.FindChangedGobjectIds(oldH, a, newH, a);
|
|
changed.ShouldContain(1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifies that parent changes are treated as subtree moves that require rebuilding the affected object.
|
|
/// </summary>
|
|
[Fact]
|
|
public void ModifiedObject_ParentChange_Detected()
|
|
{
|
|
var oldH = new List<GalaxyObjectInfo> { Obj(1, "A"), Obj(2, "B", 1) };
|
|
var newH = new List<GalaxyObjectInfo>
|
|
{
|
|
Obj(1, "A"),
|
|
new() { GobjectId = 2, TagName = "B", BrowseName = "B", ContainedName = "B", ParentGobjectId = 0 }
|
|
};
|
|
var a = new List<GalaxyAttributeInfo>();
|
|
|
|
var changed = AddressSpaceDiff.FindChangedGobjectIds(oldH, a, newH, a);
|
|
changed.ShouldContain(2);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifies that adding a Galaxy attribute marks the owning object for OPC UA variable rebuild.
|
|
/// </summary>
|
|
[Fact]
|
|
public void AttributeAdded_Detected()
|
|
{
|
|
var h = new List<GalaxyObjectInfo> { Obj(1, "A") };
|
|
var oldA = new List<GalaxyAttributeInfo> { Attr(1, "X") };
|
|
var newA = new List<GalaxyAttributeInfo> { Attr(1, "X"), Attr(1, "Y") };
|
|
|
|
var changed = AddressSpaceDiff.FindChangedGobjectIds(h, oldA, h, newA);
|
|
changed.ShouldContain(1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifies that removing a Galaxy attribute marks the owning object for OPC UA variable rebuild.
|
|
/// </summary>
|
|
[Fact]
|
|
public void AttributeRemoved_Detected()
|
|
{
|
|
var h = new List<GalaxyObjectInfo> { Obj(1, "A") };
|
|
var oldA = new List<GalaxyAttributeInfo> { Attr(1, "X"), Attr(1, "Y") };
|
|
var newA = new List<GalaxyAttributeInfo> { Attr(1, "X") };
|
|
|
|
var changed = AddressSpaceDiff.FindChangedGobjectIds(h, oldA, h, newA);
|
|
changed.ShouldContain(1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifies that changes to attribute field metadata such as MX data type trigger rebuild of the owning object.
|
|
/// </summary>
|
|
[Fact]
|
|
public void AttributeFieldChange_Detected()
|
|
{
|
|
var h = new List<GalaxyObjectInfo> { Obj(1, "A") };
|
|
var oldA = new List<GalaxyAttributeInfo> { Attr(1, "X", mxDataType: 5) };
|
|
var newA = new List<GalaxyAttributeInfo> { Attr(1, "X", mxDataType: 2) };
|
|
|
|
var changed = AddressSpaceDiff.FindChangedGobjectIds(h, oldA, h, newA);
|
|
changed.ShouldContain(1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifies that security-classification changes are treated as address-space changes for the owning attribute.
|
|
/// </summary>
|
|
[Fact]
|
|
public void AttributeSecurityChange_Detected()
|
|
{
|
|
var h = new List<GalaxyObjectInfo> { Obj(1, "A") };
|
|
var oldA = new List<GalaxyAttributeInfo>
|
|
{ new() { GobjectId = 1, AttributeName = "X", FullTagReference = "A.X", SecurityClassification = 1 } };
|
|
var newA = new List<GalaxyAttributeInfo>
|
|
{ new() { GobjectId = 1, AttributeName = "X", FullTagReference = "A.X", SecurityClassification = 2 } };
|
|
|
|
var changed = AddressSpaceDiff.FindChangedGobjectIds(h, oldA, h, newA);
|
|
changed.ShouldContain(1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifies that subtree expansion includes all descendants of a changed Galaxy object.
|
|
/// </summary>
|
|
[Fact]
|
|
public void ExpandToSubtrees_IncludesChildren()
|
|
{
|
|
var h = new List<GalaxyObjectInfo>
|
|
{
|
|
Obj(1, "Root"),
|
|
Obj(2, "Child", 1),
|
|
Obj(3, "Grandchild", 2),
|
|
Obj(4, "Sibling", 1),
|
|
Obj(5, "Unrelated")
|
|
};
|
|
|
|
var changed = new HashSet<int> { 1 };
|
|
var expanded = AddressSpaceDiff.ExpandToSubtrees(changed, h);
|
|
|
|
expanded.ShouldContain(1);
|
|
expanded.ShouldContain(2);
|
|
expanded.ShouldContain(3);
|
|
expanded.ShouldContain(4);
|
|
expanded.ShouldNotContain(5);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifies that subtree expansion does not introduce unrelated nodes when the changed object is already a leaf.
|
|
/// </summary>
|
|
[Fact]
|
|
public void ExpandToSubtrees_LeafNode_NoExpansion()
|
|
{
|
|
var h = new List<GalaxyObjectInfo>
|
|
{
|
|
Obj(1, "Root"),
|
|
Obj(2, "Child", 1),
|
|
Obj(3, "Sibling", 1)
|
|
};
|
|
|
|
var changed = new HashSet<int> { 2 };
|
|
var expanded = AddressSpaceDiff.ExpandToSubtrees(changed, h);
|
|
|
|
expanded.ShouldContain(2);
|
|
expanded.ShouldNotContain(1);
|
|
expanded.ShouldNotContain(3);
|
|
}
|
|
}
|
|
} |