fix(scripting): #1104 a jagged-array script result is refused identically in both runners

int[][] / byte[][] used to be the one result divergence left after #1100: in process
ScriptResultMaterializer passed it (SdkValueBoundary.FromClr carries it as an array of Variants),
while the worker's wire has no nested-array tag and answered "unsupported type". A script-fed node
has a scalar DataType, so a Variant-of-arrays value is not what it declares either; not documented as
a feature anywhere (only noted as the known divergence). Decision: refuse, via the shared rule.

- IsPublishable: a 1-D array's element must be a PublishableScalarTypes scalar (no recursion).
- EnsurePublishable: a nested array gets its own reason, still "... which an OPC UA node cannot
  carry: an array of arrays ...", with a flatten hint (SelectMany). Same "script threw: ..." text in
  both runners.
- SdkValueBoundaryScriptResultTests: int[][] leaves the rule==FromClr theory; a separate fact pins
  the one deliberate difference (FromClr takes it, the rule refuses).
- ParityTests: "jagged array" + "jagged byte array" rows. ShadowModeTests census: the jagged script
  now MATCHES; the unsupported_type mismatch is exercised by a decimal INPUT (design §14 #11), the
  real remaining worker-only refusal.
- ContainmentTests.Unsupported_input_and_result_types: jagged now expects the materializer reason.

Mutation: restoring the recursive element check fails 4 tests (2 parity rows, shadow census,
containment unsupported-type).

Behaviour change: a value script returning a jagged array now fails (Bad + script log) in process
too, instead of publishing a Variant array onto a scalar-typed node.
This commit is contained in:
Joseph Doherty
2026-12-04 20:31:25 -05:00
parent ce0133b03c
commit d81990bcbf
7 changed files with 76 additions and 17 deletions
@@ -100,6 +100,26 @@ public sealed class ScriptResultMaterializerTests
.Message.ShouldStartWith("The script returned a value of type 'KeyValuePair<String, Int32>[]'");
}
/// <summary>
/// lmxopcua#1104: an array of arrays is refused in both runners (the in-process runner used to publish it as an
/// array of Variants, the worker answered "unsupported type"), with a reason that says to flatten it — a
/// <c>byte[][]</c> included. The scalar-array positive controls are in
/// <see cref="Every_publishable_type_passes_scalar_and_array_positive_controls"/>.
/// </summary>
[Fact]
public void A_jagged_array_is_refused_with_a_flatten_hint()
{
foreach (var value in new object[] { new[] { new[] { 1 } }, new[] { new byte[] { 1 } }, new[] { new[] { "a" } }, new[] { new[] { new[] { 1.0 } } } })
{
ScriptResultMaterializer.IsPublishable(value.GetType()).ShouldBeFalse(value.GetType().Name);
var message = Should.Throw<ScriptResultException>(() => ScriptResultMaterializer.Materialize(value, 100), value.GetType().Name).Message;
message.ShouldContain("which an OPC UA node cannot carry: an array of arrays");
message.ShouldContain("SelectMany");
}
Should.Throw<ScriptResultException>(() => ScriptResultMaterializer.Materialize(new[] { new[] { 1 } }, 100))
.Message.ShouldStartWith("The script returned a value of type 'Int32[][]'");
}
[Fact]
public void An_unpublishable_lazy_sequence_is_refused_before_it_runs()
{
@@ -116,8 +136,6 @@ public sealed class ScriptResultMaterializerTests
ScriptResultMaterializer.Materialize(guid, 100).ShouldBe(guid);
ScriptResultMaterializer.Materialize(new[] { guid }, 100).ShouldBeOfType<Guid[]>();
ScriptResultMaterializer.Materialize(new List<Guid> { guid }, 100).ShouldBeOfType<Guid[]>().ShouldBe([guid]);
// A jagged array is publishable too (the OPC UA boundary carries it as an array of Variants).
ScriptResultMaterializer.Materialize(new[] { new[] { 1 } }, 100).ShouldBeOfType<int[][]>();
foreach (var type in ScriptResultMaterializer.PublishableScalarTypes)
{
var scalar = type == typeof(string) ? "s" : Activator.CreateInstance(type)!;