feat(core): T0-3 DriverTypeNames constants + reflection guard

Add DriverTypeNames as the single source of truth for driver-type
dispatch strings, one const per currently-registered driver factory
(value = the exact factory DriverTypeName). Fixes the latent drift
between hand-authored dispatch-map literals and the real factory names
(e.g. TwinCAT/FOCAS/GalaxyMxGateway) at the source.

A reflection guard test in Core.Abstractions.Tests builds the real
registered-factory set by driving each *DriverFactoryExtensions.Register
into a live DriverFactoryRegistry (mirroring the Host's
DriverFactoryBootstrap) and asserts bidirectional parity with the
constants, so any future rename on either side breaks the test gate.

Consumers are rewired in Batch 2 WP8; Calculation's const lands with its
factory in WP7.

Claude-Session: https://claude.ai/code/session_01LVneM3eh1UtJxEisFXgmox
This commit is contained in:
Joseph Doherty
2026-07-16 02:05:09 -04:00
parent f121f8ca16
commit 12b9978974
3 changed files with 177 additions and 0 deletions
@@ -0,0 +1,68 @@
namespace ZB.MOM.WW.OtOpcUa.Core.Abstractions;
/// <summary>
/// Single source of truth for the driver-type identifier strings the runtime
/// dispatches on. Each constant's <b>value</b> is the exact <c>DriverTypeName</c>
/// that the corresponding driver factory registers under in the process
/// <c>DriverFactoryRegistry</c> — the string the deploy pipeline stores in
/// <c>DriverInstance.DriverType</c> and every dispatch map keys by.
/// </summary>
/// <remarks>
/// <para>
/// Historically several dispatch maps hand-authored these strings and drifted from
/// the authoritative factory names (e.g. <c>"TwinCat"</c> vs the real
/// <c>"TwinCAT"</c>, <c>"Focas"</c> vs <c>"FOCAS"</c>). Consumers should reference
/// these constants instead of literals so the drift can never recur.
/// </para>
/// <para>
/// The reflection guard test
/// (<c>DriverTypeNamesGuardTests</c>) asserts bidirectional parity between these
/// constants and the set the driver factories actually register, so a rename on
/// either side breaks the build's test gate. Only constants for
/// <b>currently-registered</b> factories belong here — a not-yet-registered driver
/// (e.g. the Calculation driver landing in a later Batch 2 package) adds its own
/// constant when its factory is wired in.
/// </para>
/// </remarks>
public static class DriverTypeNames
{
/// <summary>Modbus TCP / RTU-over-TCP driver.</summary>
public const string Modbus = "Modbus";
/// <summary>Siemens S7 driver.</summary>
public const string S7 = "S7";
/// <summary>Allen-Bradley CIP (ControlLogix / CompactLogix) driver.</summary>
public const string AbCip = "AbCip";
/// <summary>Allen-Bradley legacy (PCCC / DF1-over-TCP) driver.</summary>
public const string AbLegacy = "AbLegacy";
/// <summary>Beckhoff TwinCAT ADS driver.</summary>
public const string TwinCAT = "TwinCAT";
/// <summary>FANUC FOCAS CNC driver.</summary>
public const string FOCAS = "FOCAS";
/// <summary>OPC UA client (upstream-server) driver.</summary>
public const string OpcUaClient = "OpcUaClient";
/// <summary>AVEVA System Platform (Wonderware) Galaxy driver, via the mxaccessgw gateway.</summary>
public const string Galaxy = "GalaxyMxGateway";
/// <summary>
/// Every driver-type string declared above, for callers that need to enumerate
/// the full set (e.g. validation of an authored <c>DriverType</c>).
/// </summary>
public static IReadOnlyCollection<string> All { get; } =
[
Modbus,
S7,
AbCip,
AbLegacy,
TwinCAT,
FOCAS,
OpcUaClient,
Galaxy,
];
}