Phase 2 Stream D Option B — archive v1 surface + new Driver.Galaxy.E2E parity suite. Non-destructive intermediate state: the v1 OtOpcUa.Host + Historian.Aveva + Tests + IntegrationTests projects all still build (494 v1 unit + 6 v1 integration tests still pass when run explicitly), but solution-level dotnet test ZB.MOM.WW.OtOpcUa.slnx now skips them via IsTestProject=false on the test projects + archive-status PropertyGroup comments on the src projects. The destructive deletion is reserved for Phase 2 PR 3 with explicit operator review per CLAUDE.md "only use destructive operations when truly the best approach". tests/ZB.MOM.WW.OtOpcUa.Tests/ renamed via git mv to tests/ZB.MOM.WW.OtOpcUa.Tests.v1Archive/; csproj <AssemblyName> kept as the original ZB.MOM.WW.OtOpcUa.Tests so v1 OtOpcUa.Host's [InternalsVisibleTo("ZB.MOM.WW.OtOpcUa.Tests")] still matches and the project rebuilds clean. tests/ZB.MOM.WW.OtOpcUa.IntegrationTests gets <IsTestProject>false</IsTestProject>. src/ZB.MOM.WW.OtOpcUa.Host + src/ZB.MOM.WW.OtOpcUa.Historian.Aveva get PropertyGroup archive-status comments documenting they're functionally superseded but kept in-build because cascading dependencies (Historian.Aveva → Host; IntegrationTests → Host) make a single-PR deletion high blast-radius. New tests/ZB.MOM.WW.OtOpcUa.Driver.Galaxy.E2E/ project (.NET 10) with ParityFixture that spawns OtOpcUa.Driver.Galaxy.Host.exe (net48 x86) as a Process.Start subprocess with OTOPCUA_GALAXY_BACKEND=db env vars, awaits 2s for the PipeServer to bind, then exposes a connected GalaxyProxyDriver; skips on non-Windows / Administrator shells (PipeAcl denies admins per decision #76) / ZB unreachable / Host EXE not built — each skip carries a SkipReason string the test method reads via Assert.Skip(SkipReason). RecordingAddressSpaceBuilder captures every Folder/Variable/AddProperty registration so parity tests can assert on the same shape v1 LmxNodeManager produced. HierarchyParityTests (3) — Discover returns gobjects with attributes; attribute full references match the tag.attribute Galaxy reference grammar; HistoryExtension flag flows through correctly. StabilityFindingsRegressionTests (4) — one test per 2026-04-13 stability finding from commits c76ab8f and 7310925: phantom probe subscription doesn't corrupt unrelated host status; HostStatusChangedEventArgs structurally carries a specific HostName + OldState + NewState (event signature mathematically prevents the v1 cross-host quality-clear bug); all GalaxyProxyDriver capability methods return Task or Task<T> (sync-over-async would deadlock OPC UA stack thread); AcknowledgeAsync completes before returning (no fire-and-forget background work that could race shutdown). Solution test count: 470 pass / 7 skip (E2E on admin shell) / 1 pre-existing Phase 0 baseline. Run archived suites explicitly: dotnet test tests/ZB.MOM.WW.OtOpcUa.Tests.v1Archive (494 pass) + dotnet test tests/ZB.MOM.WW.OtOpcUa.IntegrationTests (6 pass). docs/v2/V1_ARCHIVE_STATUS.md inventories every archived surface with run-it-explicitly instructions + a 10-step deletion plan for PR 3 + rollback procedure (git revert restores all four projects). docs/v2/implementation/exit-gate-phase-2-final.md supersedes the two partial-exit docs with the per-stream status table (A/B/C/D/E all addressed, D split across PR 2/3 per safety protocol), the test count breakdown, fresh adversarial review of PR 2 deltas (4 new findings: medium IsTestProject=false safety net loss, medium structural-vs-behavioral stability tests, low backend=db default, low Process.Start env inheritance), the 8 carried-forward findings from exit-gate-phase-2.md, the recommended PR order (1 → 2 → 3 → 4). docs/v2/implementation/pr-2-body.md is the Gitea web-UI paste-in for opening PR 2 once pushed.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user