Files
lmxopcua/tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.FOCAS.Tests/FocasInspectAcceptGateTests.cs
T
Joseph Doherty 05b424788f fix(tagconfig): close the four #551 residuals — accept-gate-first Inspect, three authoring rules, CSV/service gate, doc sweep
Gitea #551.

1. CSV import ran no driver-typed config gate. Its typed columns were always
   strictly parsed, but the free-form TagConfigJson column reached the database
   unread, so a CSV could author a tag the driver rejects — one that deploys
   green and reads BadNodeIdUnknown forever. RawTagCsvMapper.Parse now names the
   offending row in the staged review grid, and RawTreeService enforces the same
   gate on CreateTag/UpdateTag/ImportTags: a form cannot be the guarantee (the
   API and any future caller reach none of them, and this repo has no bUnit).
   A rejected import row is an ERROR — the batch inserts nothing and the row is
   named — never a skip.

   Note the brief's premise that manual entry rides ImportTagsAsync is wrong:
   RawManualTagEntryModal commits row-by-row via CreateTagAsync, which is why
   the gate had to land on all three write paths.

2/3. The seven pre-#549 Inspect methods ran a hand-list of DescribeInvalidEnum
   checks, so every rejection cause not on the list was invisible. They are now
   ACCEPT-GATE-FIRST (the MTConnect/Sql/OpcUaClient/Calculation shape): ask the
   driver's own reader for the verdict, then explain the refusal, with a
   catch-all so "the parse rejects but Inspect said nothing" is unreachable.
   That closes S7's absent dataType, AbCip members[], Modbus stringByteOrder and
   the type-dependent guards, plus causes the issue did not name (absent
   region/address/tagPath/symbolPath/topic, TwinCAT Structure, MQTT's Sparkplug
   tuple). FOCAS and MQTT keep advisories about ACCEPTED blobs, so they
   diagnose rather than return empty.

   Authoring half: ModbusTagConfigModel gains stringByteOrder;
   AbCipTagConfigModel asks the new AbCipTagDefinitionFactory.DescribeInvalidMember;
   S7TagConfigModel captures whether the SOURCE blob declared dataType and asks
   S7TagDefinitionFactory.DataTypeKey/DeclaresDataType. One authority per rule.

4. Doc sweep: the six factory Inspect summaries, EquipmentTagConfigInspector's
   class remarks and AdminOperationsActor's comment all claimed invalid enums are
   "silently defaulted by the lenient runtime" — false since R2-11 Phase C made
   the runtime reads strict. They describe rejections now.
2026-08-10 00:08:06 -04:00

99 lines
4.4 KiB
C#

using Shouldly;
using Xunit;
namespace ZB.MOM.WW.OtOpcUa.Driver.FOCAS.Tests;
/// <summary>
/// Gitea #551: <see cref="FocasTagDefinitionFactory.Inspect"/> gained an accept gate for its
/// <b>rejection</b> diagnosis — see <c>ModbusInspectAcceptGateTests</c>'s remarks for why both
/// directions are pinned.
/// <para>
/// FOCAS is the one factory that deliberately does NOT return empty on accept: two of its warnings
/// are <b>advisories</b> about blobs the mapper ACCEPTS but the driver still cannot serve as
/// authored — an unparseable FOCAS address (#540, dropped at the driver's own init) and an authored
/// <c>writable:true</c> (the wire is read-only). Folding FOCAS into the plain "accept ⇒ empty"
/// shape would have silently deleted both, so they are pinned here alongside the new rejections.
/// </para>
/// </summary>
public sealed class FocasInspectAcceptGateTests
{
private const string RawPath = "cell/focas/dev1/T1";
/// <summary>Blobs the mapper ACCEPTS <b>and</b> that carry no advisory — the gate must be silent.</summary>
public static TheoryData<string> CleanAndAccepted() =>
[
"""{"address":"R100","dataType":"Int32"}""",
"""{"address":"X0.0","dataType":"Bit"}""",
"""{"address":"PARAM:1020"}""",
"""{"address":"FIXED:Identity/SeriesNumber","dataType":"String"}""",
];
/// <summary>Blobs the mapper REJECTS — the gate must produce at least one warning for each.</summary>
public static TheoryData<string> Rejected() =>
[
"""{"dataType":"Int32"}""", // no address
"""{"address":"","dataType":"Int32"}""", // blank address
"""{"address":100}""", // address not a string
"""{"address":"R100","dataType":"Intt32"}""", // typo'd dataType
];
[Theory]
[MemberData(nameof(CleanAndAccepted))]
public void A_clean_config_the_mapper_accepts_draws_no_warning(string tagConfig)
{
FocasTagDefinitionFactory.FromTagConfig(tagConfig, RawPath, out _).ShouldBeTrue("fixture must be accepted");
FocasTagDefinitionFactory.Inspect(tagConfig).ShouldBeEmpty();
}
[Theory]
[MemberData(nameof(Rejected))]
public void A_config_the_mapper_rejects_is_never_passed_over_in_silence(string tagConfig)
{
FocasTagDefinitionFactory.FromTagConfig(tagConfig, RawPath, out _).ShouldBeFalse("fixture must be rejected");
FocasTagDefinitionFactory.Inspect(tagConfig).ShouldNotBeEmpty();
}
[Fact]
public void An_absent_address_is_named()
=> FocasTagDefinitionFactory.Inspect("""{"dataType":"Int32"}""")
.ShouldContain(w => w.Contains("'address'"));
// ---- The two advisories the accept gate must NOT swallow ----
[Fact]
public void An_unparseable_address_still_warns_even_though_the_mapper_accepts_it()
{
const string Blob = """{"address":"not-an-address","dataType":"Int32"}""";
FocasTagDefinitionFactory.FromTagConfig(Blob, RawPath, out _).ShouldBeTrue("the mapper accepts any non-blank address");
FocasTagDefinitionFactory.Inspect(Blob).ShouldContain(w => w.Contains("not parseable"));
}
[Fact]
public void An_authored_writable_still_warns_even_though_the_mapper_accepts_it()
{
const string Blob = """{"address":"R100","dataType":"Int32","writable":true}""";
FocasTagDefinitionFactory.FromTagConfig(Blob, RawPath, out _).ShouldBeTrue("the mapper accepts writable:true");
FocasTagDefinitionFactory.Inspect(Blob).ShouldContain(w => w.Contains("read-only"));
}
/// <summary>A rejected blob still gets its advisories — the two diagnoses are independent.</summary>
[Fact]
public void A_rejected_config_reports_the_rejection_and_the_advisory_together()
{
var warnings = FocasTagDefinitionFactory.Inspect(
"""{"address":"not-an-address","dataType":"Intt32","writable":true}""");
warnings.ShouldContain(w => w.Contains("dataType"));
warnings.ShouldContain(w => w.Contains("not parseable"));
warnings.ShouldContain(w => w.Contains("read-only"));
}
[Fact]
public void A_blank_reference_draws_nothing()
=> FocasTagDefinitionFactory.Inspect(" ").ShouldBeEmpty();
[Fact]
public void Unparseable_json_names_the_json()
=> FocasTagDefinitionFactory.Inspect("{oops").ShouldContain(w => w.Contains("not valid JSON"));
}