05b424788f
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.
99 lines
4.7 KiB
C#
99 lines
4.7 KiB
C#
using Shouldly;
|
|
using Xunit;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Driver.S7.Tests;
|
|
|
|
/// <summary>
|
|
/// Gitea #551 item 2: <see cref="S7TagDefinitionFactory.Inspect"/> is <b>accept-gate-first</b> — it asks
|
|
/// <see cref="S7TagDefinitionFactory.FromTagConfig"/> for the verdict and only explains a refusal. See
|
|
/// <c>ModbusInspectAcceptGateTests</c>'s remarks for why both directions (never stricter, never silent)
|
|
/// are pinned.
|
|
/// <para>
|
|
/// S7 carries the fleet's one unique rule: the reader REQUIRES the <c>dataType</c> key to be
|
|
/// present. A blob with only an <c>address</c> therefore deploys green and reads
|
|
/// <c>BadNodeIdUnknown</c> forever — and neither this gate nor the AdminUI model said a word about
|
|
/// it until #551.
|
|
/// </para>
|
|
/// </summary>
|
|
public sealed class S7InspectAcceptGateTests
|
|
{
|
|
private const string RawPath = "cell/s7/dev1/T1";
|
|
|
|
/// <summary>Blobs the mapper ACCEPTS — the gate must say nothing about any of them.</summary>
|
|
public static TheoryData<string> Accepted() =>
|
|
[
|
|
"""{"address":"DB1.DBW0","dataType":"Int16"}""",
|
|
"""{"address":"M0.0","dataType":"Bool"}""",
|
|
"""{"address":"DB1.DBB0","dataType":"String","stringLength":254}""",
|
|
// stringLength is irrelevant to a non-String tag, so an out-of-range remnant is ACCEPTED.
|
|
"""{"address":"DB1.DBW0","dataType":"Int16","stringLength":9999}""",
|
|
// A non-string dataType token satisfies the PRESENCE rule and then reads as absent ⇒ Int16.
|
|
"""{"address":"DB1.DBW0","dataType":7}""",
|
|
];
|
|
|
|
/// <summary>Blobs the mapper REJECTS — the gate must produce at least one warning for each.</summary>
|
|
public static TheoryData<string> Rejected() =>
|
|
[
|
|
"""{"dataType":"Int16"}""", // no address
|
|
"""{"address":"","dataType":"Int16"}""", // blank address
|
|
"""{"address":123,"dataType":"Int16"}""", // address not a string
|
|
"""{"address":"DB1.DBW0"}""", // no dataType key at all (#551)
|
|
"""{"address":"DB1.DBW0","dataType":"Intt16"}""", // typo'd dataType
|
|
"""{"address":"DB1.DBB0","dataType":"String","stringLength":255}""", // over the 254 S7 limit
|
|
"""{"address":"DB1.DBB0","dataType":"String","stringLength":-1}""", // negative length
|
|
];
|
|
|
|
[Theory]
|
|
[MemberData(nameof(Accepted))]
|
|
public void A_config_the_mapper_accepts_draws_no_warning(string tagConfig)
|
|
{
|
|
S7TagDefinitionFactory.FromTagConfig(tagConfig, RawPath, out _).ShouldBeTrue("fixture must be accepted");
|
|
S7TagDefinitionFactory.Inspect(tagConfig).ShouldBeEmpty();
|
|
}
|
|
|
|
[Theory]
|
|
[MemberData(nameof(Rejected))]
|
|
public void A_config_the_mapper_rejects_is_never_passed_over_in_silence(string tagConfig)
|
|
{
|
|
S7TagDefinitionFactory.FromTagConfig(tagConfig, RawPath, out _).ShouldBeFalse("fixture must be rejected");
|
|
S7TagDefinitionFactory.Inspect(tagConfig).ShouldNotBeEmpty();
|
|
}
|
|
|
|
/// <summary>The headline case: present-and-typo'd was reported; ABSENT was not (Gitea #551 item 2).</summary>
|
|
[Fact]
|
|
public void An_absent_dataType_is_named()
|
|
=> S7TagDefinitionFactory.Inspect("""{"address":"DB1.DBW0"}""")
|
|
.ShouldContain(w => w.Contains("no 'dataType'"));
|
|
|
|
[Fact]
|
|
public void An_absent_address_is_named()
|
|
=> S7TagDefinitionFactory.Inspect("""{"dataType":"Int16"}""")
|
|
.ShouldContain(w => w.Contains("'address'"));
|
|
|
|
[Fact]
|
|
public void An_out_of_range_string_length_is_named()
|
|
=> S7TagDefinitionFactory.Inspect("""{"address":"DB1.DBB0","dataType":"String","stringLength":255}""")
|
|
.ShouldContain(w => w.Contains("stringLength"));
|
|
|
|
// ---- DeclaresDataType is the shared authority the AdminUI model asks (one rule, two doors) ----
|
|
|
|
[Theory]
|
|
[InlineData("""{"dataType":"Int16"}""", true)]
|
|
[InlineData("""{"dataType":7}""", true)] // presence is judged on the KEY, not the value
|
|
[InlineData("""{"dataType":null}""", true)]
|
|
[InlineData("""{"address":"DB1.DBW0"}""", false)]
|
|
public void DeclaresDataType_judges_the_key_not_the_value(string tagConfig, bool expected)
|
|
{
|
|
using var doc = System.Text.Json.JsonDocument.Parse(tagConfig);
|
|
S7TagDefinitionFactory.DeclaresDataType(doc.RootElement).ShouldBe(expected);
|
|
}
|
|
|
|
[Fact]
|
|
public void A_blank_reference_draws_nothing()
|
|
=> S7TagDefinitionFactory.Inspect(" ").ShouldBeEmpty();
|
|
|
|
[Fact]
|
|
public void Unparseable_json_names_the_json()
|
|
=> S7TagDefinitionFactory.Inspect("{oops").ShouldContain(w => w.Contains("not valid JSON"));
|
|
}
|