feat(runtime): F7 spawn lifecycle + F20 ShouldStub gate

DriverHostActor.ApplyAndAck now reads the deployment artifact and
reconciles its set of DriverInstanceActor children — spawn the missing,
ApplyDelta to those with changed config, stop the removed/disabled.
The diff lives in pure DriverSpawnPlanner so it can be unit-tested
without an ActorSystem.

Adds IDriverFactory in Core.Abstractions (consumed by Runtime) +
DriverFactoryRegistryAdapter in Core.Hosting that wraps the existing
v1 DriverFactoryRegistry — Runtime stays decoupled from Polly/Serilog,
the Host wires the adapter once driver assemblies have registered.

ShouldStub(type, roles) is now actually called on every spawn — Galaxy
+ Wonderware-Historian boot stubbed on macOS/Linux or whenever the host
carries the dev role. Missing factory ⇒ stub fallback, never a crash.

Tests: 24 → 34 in Runtime (+10):
- DriverSpawnPlannerTests x7 (diff cases, type change ⇒ stop+respawn)
- DeploymentArtifactTests  x5 (empty/malformed/missing fields tolerant)
- DriverHostActorReconcileTests x4 (spawn count, stub fallback,
  ShouldStub gate, second-apply stops the removed)
All 6 v2 test suites green: 120 tests passing.

Closes F20 (ShouldStub wired). F7 marked partial — subscription
publishing + write path still stubbed in DriverInstanceActor itself.
This commit is contained in:
Joseph Doherty
2026-05-26 08:57:16 -04:00
parent 9892ceae9a
commit da141497f8
10 changed files with 768 additions and 12 deletions
@@ -0,0 +1,28 @@
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
namespace ZB.MOM.WW.OtOpcUa.Core.Hosting;
/// <summary>
/// Adapts the existing <see cref="DriverFactoryRegistry"/> (v1 surface, still the
/// concrete singleton every driver assembly registers itself against) to the v2
/// <see cref="IDriverFactory"/> abstraction consumed by Runtime. The fused Host binds
/// this in DI once each <c>Driver.*.Register(registry)</c> call has completed.
/// </summary>
public sealed class DriverFactoryRegistryAdapter : IDriverFactory
{
private readonly DriverFactoryRegistry _registry;
public DriverFactoryRegistryAdapter(DriverFactoryRegistry registry)
{
ArgumentNullException.ThrowIfNull(registry);
_registry = registry;
}
public IDriver? TryCreate(string driverType, string driverInstanceId, string driverConfigJson)
{
var factory = _registry.TryGet(driverType);
return factory?.Invoke(driverInstanceId, driverConfigJson);
}
public IReadOnlyCollection<string> SupportedTypes => _registry.RegisteredTypes;
}