fix(s7): refuse unservable tag shapes per tag at every gate (R07:H3, R07:U4)

The init-time tag guards THREW: one mis-authored tag (DB1.DBZ0, DB1.DBW0 typed
Float64, T5 typed Int32, a writable Bool array) faulted the whole driver and the
actor retried the same init every 10 s forever, darkening every tag on the PLC.
Neither the editor nor the deploy gate checked any of it.

- S7AddressParser moves to S7.Contracts (same namespace) and a new
  S7TagShapeRules there is the single authority on servable shapes.
- S7TagDefinitionFactory.FromTagConfig applies it, so the AdminUI editor, the
  deploy gate (Inspect, with the specific reason) and the driver init refuse
  the same tags. Init now skips a refused tag (ISkippedTagReporter) instead of
  throwing; the throwing RejectUnsupportedTagConfigs is gone.
- New rules on top of the old guards: a narrow type at the wrong access width
  (every read failed) and a Bool array not starting at bit 0 (U4: DB1.DBX0.3
  silently read bit 0 of bytes 0..n).
- AdminUI test fixtures that used addresses the driver could never serve
  (DB1.DBS0, a browse "SomeAddress", Int32/Float32 on DBW) now use real ones.

Refs #742
Claude-Session: https://claude.ai/code/session_01Ub9hGmYLQvn9XETzw7CMsT
This commit is contained in:
Joseph Doherty
2026-10-22 15:04:19 -04:00
parent 7bcb6331ed
commit 87a7414df7
19 changed files with 598 additions and 368 deletions
@@ -0,0 +1,57 @@
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
namespace ZB.MOM.WW.OtOpcUa.Driver.S7.IntegrationTests.S7_1500;
/// <summary>
/// Live gate for R07:H3 — one mis-authored tag must not darken the PLC. Before the fix each of
/// these shapes threw at init, so the driver Faulted and served nothing (and the actor retried the
/// same init every 10 s forever). Now each is skipped on its own and the good tags keep reading
/// their seeded values over real S7comm.
/// </summary>
[Collection(Snap7ServerCollection.Name)]
[Trait("Category", "Integration")]
[Trait("Device", "S7_1500")]
public sealed class S7_1500TagShapeSkipTests(Snap7ServerFixture sim)
{
/// <summary>Unservable tags are skipped per tag; the seeded neighbours still read Good.</summary>
[Fact]
public async Task Mis_authored_tags_are_skipped_and_the_rest_of_the_PLC_still_reads()
{
if (sim.SkipReason is not null) Assert.Skip(sim.SkipReason);
var ct = TestContext.Current.CancellationToken;
var good = S7_1500Profile.BuildOptions(sim.Host, sim.Port);
var bad = new[]
{
new S7TagDefinition("Bad/Typo", "DB1.DBZ0", S7DataType.Int16),
new S7TagDefinition("Bad/WideOnWord", "DB1.DBW0", S7DataType.Float64),
new S7TagDefinition("Bad/TimerAsInt", "T5", S7DataType.Int32, Writable: false),
new S7TagDefinition("Bad/OffsetBoolArray", "DB1.DBX50.3", S7DataType.Bool, Writable: false, ArrayCount: 8),
};
var options = new S7DriverOptions
{
Host = good.Host, Port = good.Port, CpuType = good.CpuType, Rack = good.Rack, Slot = good.Slot,
Timeout = good.Timeout, Probe = good.Probe,
RawTags = [.. good.RawTags, .. S7RawTags.Entries(bad)],
};
await using var drv = new S7Driver(options, driverInstanceId: "s7-shape-skip-live");
await drv.InitializeAsync("{}", ct);
drv.GetHealth().State.ShouldBe(DriverState.Healthy);
drv.GetSkippedTags().ShouldNotBeNull().Sample.Select(s => s.RawPath)
.ShouldBe(bad.Select(b => b.Name), ignoreOrder: true);
var r = await drv.ReadAsync(
[S7_1500Profile.ProbeTag, S7_1500Profile.SmokeI16Tag, S7_1500Profile.SmokeBoolTag, bad[0].Name], ct);
r[0].StatusCode.ShouldBe(0u);
Convert.ToInt32(r[0].Value).ShouldBe(S7_1500Profile.ProbeSeedValue);
r[1].StatusCode.ShouldBe(0u);
Convert.ToInt32(r[1].Value).ShouldBe((int)S7_1500Profile.SmokeI16SeedValue);
r[2].StatusCode.ShouldBe(0u);
Convert.ToBoolean(r[2].Value).ShouldBeTrue();
r[3].StatusCode.ShouldBe(0x80340000u, "a skipped tag reads BadNodeIdUnknown");
}
}