fix(mqtt): runtime mappers no longer refuse leading-whitespace TagConfig — JsonDocument.Parse + ValueKind is the single framing authority (#559)

FromTagConfig and FromSparkplugTagConfig each carried a framing pre-check
(`tagConfig[0] != '{'`) evaluated on the UNTRIMMED string, so a TagConfig blob
with leading whitespace was refused by MQTT alone and the tag read
BadNodeIdUnknown forever — while the other six structural-parse drivers
(Modbus, S7, AbCip, AbLegacy, TwinCAT, FOCAS) hand the identical blob to
JsonDocument.Parse, which skips leading whitespace per the JSON spec.

The clause is dropped (the blank guard stays). JsonDocument.Parse plus the
root-ValueKind check now decide framing, exactly as for the six siblings: an
array/number/string root fails ValueKind, non-JSON is a JsonException. The gate
was a validator, not a discriminator — no caller (MqttSubscriptionManager,
SparkplugIngestor, MqttTagConfigModel, Inspect) used the first byte to pick a
format — so verdicts are identical for every input except whitespace-padded
JSON objects, which now get their content's verdict.

Inspect needs no logic change (it has trimmed since #556 and hands the RAW
reference to the mappers), but its comments claimed the padded-blob refusal was
production-reachable; rewritten. That shape was also MQTT's only vehicle for the
catch-all backstop, which is now unreachable-today like FOCAS's — so its test is
replaced by the same count-relation pin, and the backstop code stays as
defence-in-depth.

Tests: both mappers pinned by padded-vs-unpadded DEFINITION equality (a record,
so field-wise), padded non-object/malformed negative controls, an Inspect
verdict+inspection parity theory over the accepted AND rejected corpus with an
anti-vacuity control, and a padded MQTT corpus entry in the AdminUI
authoring/runtime parity suite.
This commit is contained in:
Joseph Doherty
2026-08-10 03:36:46 -04:00
parent 15e65c86d0
commit 621a9e5dc2
5 changed files with 227 additions and 51 deletions
@@ -111,10 +111,12 @@ public sealed class FocasInspectAcceptGateTests
/// <see cref="FocasTagDefinitionFactory.FromTagConfig"/> — absent / non-string / blank
/// <c>address</c>, invalid <c>dataType</c> — has a matching describe branch, and
/// <c>TryReadEnumStrict</c> and <c>DescribeInvalidEnum</c> share one classifier so they cannot
/// disagree. So the guard is protective here rather than a live fix; MQTT's is live (a padded
/// blob its own mappers refuse and every branch finds well-formed — see
/// <c>MqttInspectAcceptGateTests</c>). What this pins is the property that must survive the
/// next rejection cause someone adds without a describe branch.
/// disagree. So the guard is protective here rather than a live fix. It is now protective
/// fleet-wide: MQTT's used to be live — a padded blob its own mappers refused and every branch
/// found well-formed — until Gitea #559 removed those mappers' framing gates, since the refusal
/// was itself the defect. <c>MqttInspectAcceptGateTests</c> pins the same count relation.
/// What this pins is the property that must survive the next rejection cause someone adds
/// without a describe branch.
/// </para>
/// </summary>
[Fact]