Phase 0 — mechanical rename ZB.MOM.WW.LmxOpcUa.* → ZB.MOM.WW.OtOpcUa.*

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>
This commit is contained in:
Joseph Doherty
2026-04-17 13:57:47 -04:00
parent 5b8d708c58
commit 3b2defd94f
293 changed files with 841 additions and 722 deletions

View File

@@ -0,0 +1,118 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Host.GalaxyRepository;
using ZB.MOM.WW.OtOpcUa.Tests.Helpers;
namespace ZB.MOM.WW.OtOpcUa.Tests.GalaxyRepository
{
/// <summary>
/// Verifies the polling service that detects Galaxy deploy changes and triggers address-space rebuilds.
/// </summary>
public class ChangeDetectionServiceTests
{
/// <summary>
/// Confirms that the first poll always triggers an initial rebuild notification.
/// </summary>
[Fact]
public async Task FirstPoll_AlwaysTriggers()
{
var repo = new FakeGalaxyRepository { LastDeployTime = new DateTime(2024, 1, 1) };
var service = new ChangeDetectionService(repo, 1);
var triggered = false;
service.OnGalaxyChanged += () => triggered = true;
service.Start();
await Task.Delay(500);
service.Stop();
triggered.ShouldBe(true);
service.Dispose();
}
/// <summary>
/// Confirms that repeated polls with the same deploy timestamp do not retrigger rebuilds.
/// </summary>
[Fact]
public async Task SameTimestamp_DoesNotTriggerAgain()
{
var repo = new FakeGalaxyRepository { LastDeployTime = new DateTime(2024, 1, 1) };
var service = new ChangeDetectionService(repo, 1);
var triggerCount = 0;
service.OnGalaxyChanged += () => Interlocked.Increment(ref triggerCount);
service.Start();
await Task.Delay(2500); // Should have polled at least twice
service.Stop();
triggerCount.ShouldBe(1); // Only the first poll
service.Dispose();
}
/// <summary>
/// Confirms that a changed deploy timestamp triggers another rebuild notification.
/// </summary>
[Fact]
public async Task ChangedTimestamp_TriggersAgain()
{
var repo = new FakeGalaxyRepository { LastDeployTime = new DateTime(2024, 1, 1) };
var service = new ChangeDetectionService(repo, 1);
var triggerCount = 0;
service.OnGalaxyChanged += () => Interlocked.Increment(ref triggerCount);
service.Start();
await Task.Delay(500);
// Change the deploy time
repo.LastDeployTime = new DateTime(2024, 2, 1);
await Task.Delay(1500);
service.Stop();
triggerCount.ShouldBeGreaterThanOrEqualTo(2);
service.Dispose();
}
/// <summary>
/// Confirms that transient polling failures do not crash the service and allow later recovery.
/// </summary>
[Fact]
public async Task FailedPoll_DoesNotCrash_RetriesNext()
{
var repo = new FakeGalaxyRepository { LastDeployTime = new DateTime(2024, 1, 1) };
var service = new ChangeDetectionService(repo, 1);
var triggerCount = 0;
service.OnGalaxyChanged += () => Interlocked.Increment(ref triggerCount);
service.Start();
await Task.Delay(500);
// Make it fail
repo.ShouldThrow = true;
await Task.Delay(1500);
// Restore and it should recover
repo.ShouldThrow = false;
repo.LastDeployTime = new DateTime(2024, 3, 1);
await Task.Delay(1500);
service.Stop();
// Should have triggered at least on first poll and on the changed timestamp
triggerCount.ShouldBeGreaterThanOrEqualTo(1);
service.Dispose();
}
/// <summary>
/// Confirms that stopping the service before it starts is a harmless no-op.
/// </summary>
[Fact]
public void Stop_BeforeStart_DoesNotThrow()
{
var repo = new FakeGalaxyRepository();
var service = new ChangeDetectionService(repo, 30);
service.Stop(); // Should not throw
service.Dispose();
}
}
}

View File

@@ -0,0 +1,196 @@
using System.Collections.Generic;
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Host.Domain;
using ZB.MOM.WW.OtOpcUa.Host.GalaxyRepository;
namespace ZB.MOM.WW.OtOpcUa.Tests.GalaxyRepository
{
public class PlatformScopeFilterTests
{
// Category constants matching the Galaxy schema.
private const int CatPlatform = 1;
private const int CatAppEngine = 3;
private const int CatUserDefined = 10;
private const int CatArea = 13;
/// <summary>
/// Builds a two-platform Galaxy hierarchy for filtering tests.
///
/// Structure:
/// Area1 (id=1, area, parent=0)
/// PlatformA (id=10, cat=1, hosted_by=0) ← node "NODEA"
/// EngineA (id=20, cat=3, hosted_by=10)
/// Obj1 (id=30, cat=10, hosted_by=20)
/// Obj2 (id=31, cat=10, hosted_by=20)
/// PlatformB (id=11, cat=1, hosted_by=0) ← node "NODEB"
/// EngineB (id=21, cat=3, hosted_by=11)
/// Obj3 (id=32, cat=10, hosted_by=21)
/// Area2 (id=2, area, parent=0)
/// Obj4 (id=33, cat=10, hosted_by=21) ← hosted by EngineB
/// </summary>
private static (List<GalaxyObjectInfo> hierarchy, List<PlatformInfo> platforms) CreateTwoPlatformGalaxy()
{
var hierarchy = new List<GalaxyObjectInfo>
{
new() { GobjectId = 1, TagName = "Area1", ContainedName = "Area1", BrowseName = "Area1", ParentGobjectId = 0, IsArea = true, CategoryId = CatArea, HostedByGobjectId = 0 },
new() { GobjectId = 10, TagName = "PlatformA", ContainedName = "PlatformA", BrowseName = "PlatformA", ParentGobjectId = 1, IsArea = false, CategoryId = CatPlatform, HostedByGobjectId = 0 },
new() { GobjectId = 20, TagName = "EngineA_001", ContainedName = "EngineA", BrowseName = "EngineA", ParentGobjectId = 10, IsArea = false, CategoryId = CatAppEngine, HostedByGobjectId = 10 },
new() { GobjectId = 30, TagName = "Obj1_001", ContainedName = "Obj1", BrowseName = "Obj1", ParentGobjectId = 20, IsArea = false, CategoryId = CatUserDefined, HostedByGobjectId = 20 },
new() { GobjectId = 31, TagName = "Obj2_001", ContainedName = "Obj2", BrowseName = "Obj2", ParentGobjectId = 20, IsArea = false, CategoryId = CatUserDefined, HostedByGobjectId = 20 },
new() { GobjectId = 11, TagName = "PlatformB", ContainedName = "PlatformB", BrowseName = "PlatformB", ParentGobjectId = 1, IsArea = false, CategoryId = CatPlatform, HostedByGobjectId = 0 },
new() { GobjectId = 21, TagName = "EngineB_001", ContainedName = "EngineB", BrowseName = "EngineB", ParentGobjectId = 11, IsArea = false, CategoryId = CatAppEngine, HostedByGobjectId = 11 },
new() { GobjectId = 32, TagName = "Obj3_001", ContainedName = "Obj3", BrowseName = "Obj3", ParentGobjectId = 21, IsArea = false, CategoryId = CatUserDefined, HostedByGobjectId = 21 },
new() { GobjectId = 2, TagName = "Area2", ContainedName = "Area2", BrowseName = "Area2", ParentGobjectId = 0, IsArea = true, CategoryId = CatArea, HostedByGobjectId = 0 },
new() { GobjectId = 33, TagName = "Obj4_001", ContainedName = "Obj4", BrowseName = "Obj4", ParentGobjectId = 2, IsArea = false, CategoryId = CatUserDefined, HostedByGobjectId = 21 },
};
var platforms = new List<PlatformInfo>
{
new() { GobjectId = 10, NodeName = "NODEA" },
new() { GobjectId = 11, NodeName = "NODEB" },
};
return (hierarchy, platforms);
}
[Fact]
public void Filter_ReturnsOnlyObjectsUnderMatchingPlatform()
{
var (hierarchy, platforms) = CreateTwoPlatformGalaxy();
var (filtered, ids) = PlatformScopeFilter.Filter(hierarchy, platforms, "NODEA");
// Should include: Area1, PlatformA, EngineA, Obj1, Obj2
// Should exclude: PlatformB, EngineB, Obj3, Area2, Obj4
ids.ShouldContain(1); // Area1 (ancestor of PlatformA)
ids.ShouldContain(10); // PlatformA
ids.ShouldContain(20); // EngineA
ids.ShouldContain(30); // Obj1
ids.ShouldContain(31); // Obj2
ids.ShouldNotContain(11); // PlatformB
ids.ShouldNotContain(21); // EngineB
ids.ShouldNotContain(32); // Obj3
ids.ShouldNotContain(33); // Obj4
ids.ShouldNotContain(2); // Area2 (no local children)
filtered.Count.ShouldBe(5);
}
[Fact]
public void Filter_ReturnsObjectsUnderPlatformB()
{
var (hierarchy, platforms) = CreateTwoPlatformGalaxy();
var (filtered, ids) = PlatformScopeFilter.Filter(hierarchy, platforms, "NODEB");
// Should include: Area1, PlatformB, EngineB, Obj3, Area2, Obj4
ids.ShouldContain(1); // Area1 (ancestor of PlatformB)
ids.ShouldContain(11); // PlatformB
ids.ShouldContain(21); // EngineB
ids.ShouldContain(32); // Obj3
ids.ShouldContain(2); // Area2 (has Obj4 hosted by EngineB)
ids.ShouldContain(33); // Obj4
// Should exclude PlatformA's subtree
ids.ShouldNotContain(10);
ids.ShouldNotContain(20);
ids.ShouldNotContain(30);
ids.ShouldNotContain(31);
filtered.Count.ShouldBe(6);
}
[Fact]
public void Filter_IsCaseInsensitiveOnNodeName()
{
var (hierarchy, platforms) = CreateTwoPlatformGalaxy();
var (filtered, _) = PlatformScopeFilter.Filter(hierarchy, platforms, "nodea");
filtered.Count.ShouldBe(5);
}
[Fact]
public void Filter_ReturnsEmptyWhenNoMatchingPlatform()
{
var (hierarchy, platforms) = CreateTwoPlatformGalaxy();
var (filtered, ids) = PlatformScopeFilter.Filter(hierarchy, platforms, "UNKNOWN");
filtered.ShouldBeEmpty();
ids.ShouldBeEmpty();
}
[Fact]
public void Filter_IncludesAncestorAreasForConnectedTree()
{
// An object nested several levels deep should pull in all ancestor areas.
var hierarchy = new List<GalaxyObjectInfo>
{
new() { GobjectId = 1, TagName = "TopArea", ContainedName = "TopArea", BrowseName = "TopArea", ParentGobjectId = 0, IsArea = true, CategoryId = CatArea, HostedByGobjectId = 0 },
new() { GobjectId = 2, TagName = "SubArea", ContainedName = "SubArea", BrowseName = "SubArea", ParentGobjectId = 1, IsArea = true, CategoryId = CatArea, HostedByGobjectId = 0 },
new() { GobjectId = 10, TagName = "Plat", ContainedName = "Plat", BrowseName = "Plat", ParentGobjectId = 2, IsArea = false, CategoryId = CatPlatform, HostedByGobjectId = 0 },
new() { GobjectId = 20, TagName = "Eng", ContainedName = "Eng", BrowseName = "Eng", ParentGobjectId = 10, IsArea = false, CategoryId = CatAppEngine, HostedByGobjectId = 10 },
new() { GobjectId = 30, TagName = "Obj", ContainedName = "Obj", BrowseName = "Obj", ParentGobjectId = 20, IsArea = false, CategoryId = CatUserDefined, HostedByGobjectId = 20 },
};
var platforms = new List<PlatformInfo> { new() { GobjectId = 10, NodeName = "LOCAL" } };
var (filtered, ids) = PlatformScopeFilter.Filter(hierarchy, platforms, "LOCAL");
ids.ShouldContain(1); // TopArea
ids.ShouldContain(2); // SubArea
ids.ShouldContain(10); // Platform
ids.ShouldContain(20); // Engine
ids.ShouldContain(30); // Object
filtered.Count.ShouldBe(5);
}
[Fact]
public void Filter_ExcludesAreaWithNoLocalDescendants()
{
var hierarchy = new List<GalaxyObjectInfo>
{
new() { GobjectId = 1, TagName = "UsedArea", ContainedName = "UsedArea", BrowseName = "UsedArea", ParentGobjectId = 0, IsArea = true, CategoryId = CatArea, HostedByGobjectId = 0 },
new() { GobjectId = 2, TagName = "EmptyArea", ContainedName = "EmptyArea", BrowseName = "EmptyArea", ParentGobjectId = 0, IsArea = true, CategoryId = CatArea, HostedByGobjectId = 0 },
new() { GobjectId = 10, TagName = "Plat", ContainedName = "Plat", BrowseName = "Plat", ParentGobjectId = 1, IsArea = false, CategoryId = CatPlatform, HostedByGobjectId = 0 },
};
var platforms = new List<PlatformInfo> { new() { GobjectId = 10, NodeName = "LOCAL" } };
var (_, ids) = PlatformScopeFilter.Filter(hierarchy, platforms, "LOCAL");
ids.ShouldContain(1); // UsedArea (ancestor of Plat)
ids.ShouldNotContain(2); // EmptyArea (no local descendants)
}
[Fact]
public void FilterAttributes_RetainsOnlyMatchingGobjectIds()
{
var gobjectIds = new HashSet<int> { 10, 30 };
var attributes = new List<GalaxyAttributeInfo>
{
new() { GobjectId = 10, TagName = "Plat", AttributeName = "Attr1", FullTagReference = "Plat.Attr1" },
new() { GobjectId = 20, TagName = "Other", AttributeName = "Attr2", FullTagReference = "Other.Attr2" },
new() { GobjectId = 30, TagName = "Obj", AttributeName = "Attr3", FullTagReference = "Obj.Attr3" },
};
var filtered = PlatformScopeFilter.FilterAttributes(attributes, gobjectIds);
filtered.Count.ShouldBe(2);
filtered.ShouldAllBe(a => gobjectIds.Contains(a.GobjectId));
}
[Fact]
public void Filter_PreservesOriginalOrder()
{
var (hierarchy, platforms) = CreateTwoPlatformGalaxy();
var (filtered, _) = PlatformScopeFilter.Filter(hierarchy, platforms, "NODEA");
// Verify the order matches the original hierarchy order for included items.
for (int i = 1; i < filtered.Count; i++)
{
var prevIndex = hierarchy.FindIndex(o => o.GobjectId == filtered[i - 1].GobjectId);
var currIndex = hierarchy.FindIndex(o => o.GobjectId == filtered[i].GobjectId);
prevIndex.ShouldBeLessThan(currIndex);
}
}
}
}