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,295 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using ZB.MOM.WW.OtOpcUa.Host.Configuration;
using ZB.MOM.WW.OtOpcUa.Host.Domain;
namespace ZB.MOM.WW.OtOpcUa.Host
{
/// <summary>
/// Fluent builder for constructing OpcUaService with dependency overrides.
/// Used by integration tests to substitute fakes for COM/DB components.
/// </summary>
internal class OpcUaServiceBuilder
{
private IUserAuthenticationProvider? _authProvider;
private bool _authProviderSet;
private AppConfiguration _config = new();
private IGalaxyRepository? _galaxyRepository;
private bool _galaxyRepositorySet;
private IMxAccessClient? _mxAccessClient;
private bool _mxAccessClientSet;
private IMxProxy? _mxProxy;
private bool _mxProxySet;
/// <summary>
/// Replaces the default service configuration used by the test host.
/// </summary>
/// <param name="config">The full configuration snapshot to inject into the service under test.</param>
/// <returns>The current builder so additional overrides can be chained.</returns>
public OpcUaServiceBuilder WithConfig(AppConfiguration config)
{
_config = config;
return this;
}
/// <summary>
/// Sets the OPC UA port used by the test host so multiple integration runs can coexist.
/// </summary>
/// <param name="port">The TCP port to expose for the test server.</param>
/// <returns>The current builder so additional overrides can be chained.</returns>
public OpcUaServiceBuilder WithOpcUaPort(int port)
{
_config.OpcUa.Port = port;
return this;
}
/// <summary>
/// Sets the Galaxy name represented by the test address space.
/// </summary>
/// <param name="name">The Galaxy name to expose through OPC UA and diagnostics.</param>
/// <returns>The current builder so additional overrides can be chained.</returns>
public OpcUaServiceBuilder WithGalaxyName(string name)
{
_config.OpcUa.GalaxyName = name;
return this;
}
/// <summary>
/// Injects an MXAccess proxy substitute for tests that exercise the proxy-driven runtime path.
/// </summary>
/// <param name="proxy">The proxy fake or stub to supply to the service.</param>
/// <returns>The current builder so additional overrides can be chained.</returns>
public OpcUaServiceBuilder WithMxProxy(IMxProxy? proxy)
{
_mxProxy = proxy;
_mxProxySet = true;
return this;
}
/// <summary>
/// Injects a repository substitute for tests that control Galaxy hierarchy and deploy metadata.
/// </summary>
/// <param name="repository">The repository fake or stub to supply to the service.</param>
/// <returns>The current builder so additional overrides can be chained.</returns>
public OpcUaServiceBuilder WithGalaxyRepository(IGalaxyRepository? repository)
{
_galaxyRepository = repository;
_galaxyRepositorySet = true;
return this;
}
/// <summary>
/// Override the MxAccessClient directly, skipping STA thread and COM interop entirely.
/// When set, the service will use this client instead of creating one from IMxProxy.
/// </summary>
/// <param name="client">The direct MXAccess client substitute to inject into the service.</param>
/// <returns>The current builder so additional overrides can be chained.</returns>
public OpcUaServiceBuilder WithMxAccessClient(IMxAccessClient? client)
{
_mxAccessClient = client;
_mxAccessClientSet = true;
return this;
}
/// <summary>
/// Seeds a convenience fake repository with Galaxy hierarchy and attribute rows for address-space tests.
/// </summary>
/// <param name="hierarchy">The object hierarchy to expose through the test OPC UA namespace.</param>
/// <param name="attributes">The attribute rows to attach to the hierarchy.</param>
/// <returns>The current builder so additional overrides can be chained.</returns>
public OpcUaServiceBuilder WithHierarchy(List<GalaxyObjectInfo> hierarchy, List<GalaxyAttributeInfo> attributes)
{
if (!_galaxyRepositorySet)
{
var fake = new FakeBuilderGalaxyRepository();
_galaxyRepository = fake;
_galaxyRepositorySet = true;
}
if (_galaxyRepository is FakeBuilderGalaxyRepository fakeRepo)
{
fakeRepo.Hierarchy = hierarchy;
fakeRepo.Attributes = attributes;
}
return this;
}
/// <summary>
/// Disables the embedded dashboard so tests can focus on the runtime bridge without binding the HTTP listener.
/// </summary>
/// <returns>The current builder so additional overrides can be chained.</returns>
/// <summary>
/// Injects a custom authentication provider for tests that need deterministic role resolution.
/// </summary>
public OpcUaServiceBuilder WithAuthProvider(IUserAuthenticationProvider? provider)
{
_authProvider = provider;
_authProviderSet = true;
return this;
}
/// <summary>
/// Sets the authentication configuration for the test host.
/// </summary>
public OpcUaServiceBuilder WithAuthentication(AuthenticationConfiguration authConfig)
{
_config.Authentication = authConfig;
return this;
}
public OpcUaServiceBuilder DisableDashboard()
{
_config.Dashboard.Enabled = false;
return this;
}
/// <summary>
/// Sets the redundancy configuration for the test host.
/// </summary>
/// <param name="redundancy">The redundancy configuration to inject.</param>
/// <returns>The current builder so additional overrides can be chained.</returns>
public OpcUaServiceBuilder WithRedundancy(RedundancyConfiguration redundancy)
{
_config.Redundancy = redundancy;
return this;
}
/// <summary>
/// Sets the application URI for the test host, distinct from the namespace URI.
/// </summary>
/// <param name="applicationUri">The unique application URI for this server instance.</param>
/// <returns>The current builder so additional overrides can be chained.</returns>
public OpcUaServiceBuilder WithApplicationUri(string applicationUri)
{
_config.OpcUa.ApplicationUri = applicationUri;
return this;
}
/// <summary>
/// Sets the security profile configuration for the test host.
/// </summary>
/// <param name="security">The security profile configuration to inject.</param>
/// <returns>The current builder so additional overrides can be chained.</returns>
/// <summary>
/// Enables alarm condition tracking on the test host so integration tests can exercise the alarm-creation path.
/// </summary>
/// <param name="enabled">Whether alarm tracking should be enabled.</param>
/// <returns>The current builder so additional overrides can be chained.</returns>
public OpcUaServiceBuilder WithAlarmTracking(bool enabled)
{
_config.OpcUa.AlarmTrackingEnabled = enabled;
return this;
}
/// <summary>
/// Configures the template-based alarm object filter for integration tests.
/// </summary>
/// <param name="filters">Zero or more wildcard patterns. Empty → filter disabled.</param>
/// <returns>The current builder so additional overrides can be chained.</returns>
public OpcUaServiceBuilder WithAlarmFilter(params string[] filters)
{
_config.OpcUa.AlarmFilter = new AlarmFilterConfiguration
{
ObjectFilters = filters.ToList()
};
return this;
}
public OpcUaServiceBuilder WithSecurity(SecurityProfileConfiguration security)
{
_config.Security = security;
return this;
}
/// <summary>
/// Effectively disables Galaxy change detection by pushing the polling interval beyond realistic test durations.
/// </summary>
/// <returns>The current builder so additional overrides can be chained.</returns>
public OpcUaServiceBuilder DisableChangeDetection()
{
_config.GalaxyRepository.ChangeDetectionIntervalSeconds = int.MaxValue;
return this;
}
/// <summary>
/// Creates an <see cref="OpcUaService" /> using the accumulated test doubles and configuration overrides.
/// </summary>
/// <returns>A service instance ready for integration-style testing.</returns>
public OpcUaService Build()
{
return new OpcUaService(
_config,
_mxProxySet ? _mxProxy : null,
_galaxyRepositorySet ? _galaxyRepository : null,
_mxAccessClientSet ? _mxAccessClient : null,
_mxAccessClientSet,
_authProviderSet ? _authProvider : null,
_authProviderSet);
}
/// <summary>
/// Internal fake repository used by WithHierarchy for convenience.
/// </summary>
private class FakeBuilderGalaxyRepository : IGalaxyRepository
{
/// <summary>
/// Gets or sets the hierarchy rows that the fake repository returns to the service.
/// </summary>
public List<GalaxyObjectInfo> Hierarchy { get; set; } = new();
/// <summary>
/// Gets or sets the attribute rows that the fake repository returns to the service.
/// </summary>
public List<GalaxyAttributeInfo> Attributes { get; set; } = new();
/// <summary>
/// Occurs when the fake repository wants to simulate a Galaxy deploy change.
/// </summary>
public event Action? OnGalaxyChanged;
/// <summary>
/// Returns the seeded hierarchy rows for address-space construction.
/// </summary>
/// <param name="ct">A cancellation token that is ignored by the in-memory fake.</param>
/// <returns>The configured hierarchy rows.</returns>
public Task<List<GalaxyObjectInfo>> GetHierarchyAsync(CancellationToken ct = default)
{
return Task.FromResult(Hierarchy);
}
/// <summary>
/// Returns the seeded attribute rows for address-space construction.
/// </summary>
/// <param name="ct">A cancellation token that is ignored by the in-memory fake.</param>
/// <returns>The configured attribute rows.</returns>
public Task<List<GalaxyAttributeInfo>> GetAttributesAsync(CancellationToken ct = default)
{
return Task.FromResult(Attributes);
}
/// <summary>
/// Returns the current UTC time so change-detection tests have a deploy timestamp to compare against.
/// </summary>
/// <param name="ct">A cancellation token that is ignored by the in-memory fake.</param>
/// <returns>The current UTC time.</returns>
public Task<DateTime?> GetLastDeployTimeAsync(CancellationToken ct = default)
{
return Task.FromResult<DateTime?>(DateTime.UtcNow);
}
/// <summary>
/// Reports a healthy repository connection for builder-based test setups.
/// </summary>
/// <param name="ct">A cancellation token that is ignored by the in-memory fake.</param>
/// <returns>A completed task returning <see langword="true" />.</returns>
public Task<bool> TestConnectionAsync(CancellationToken ct = default)
{
return Task.FromResult(true);
}
}
}
}