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
@@ -102,15 +102,21 @@ public static class ScriptResultMaterializer
/// <summary>
/// Whether a returned value of <paramref name="type"/> can reach an OPC UA client (lmxopcua#1100): a
/// <see cref="PublishableScalarTypes"/> scalar, or a one-dimensional array whose element type is publishable
/// (a jagged array of them included — the publish path carries it as an array of Variants).
/// <see cref="PublishableScalarTypes"/> scalar, or a one-dimensional array whose element type is one.
/// </summary>
/// <remarks>
/// A jagged array (<c>int[][]</c>, <c>byte[][]</c>) is refused (lmxopcua#1104), although
/// <c>SdkValueBoundary.FromClr</c> would take it as an array of Variants: a script-fed node has a scalar DataType
/// (Int32 with ValueRank one dimension, say), so a Variant-of-arrays value is not what its DataType declares, and
/// the out-of-process wire has no nested-array tag — the in-process runner published it while the worker answered
/// "unsupported type". Refused here, inside the run, both runners fail it with the same reason.
/// </remarks>
/// <param name="type">The runtime type of the returned value.</param>
/// <returns><c>true</c> when the publish path can represent the value.</returns>
public static bool IsPublishable(Type type)
{
if (type.IsArray)
return type.GetArrayRank() == 1 && !type.IsVariableBoundArray && IsPublishable(type.GetElementType()!);
return type.GetArrayRank() == 1 && !type.IsVariableBoundArray && PublishableScalarTypes.Contains(type.GetElementType()!);
return PublishableScalarTypes.Contains(type);
}
@@ -122,6 +128,11 @@ public static class ScriptResultMaterializer
private static void EnsurePublishable(Type type)
{
if (IsPublishable(type)) return;
if (type.IsArray && type.GetElementType()!.IsArray)
throw new ScriptResultException(
$"The script returned a value of type '{Describe(type)}', which an OPC UA node cannot carry: an array of " +
"arrays has no representation on a node whose DataType is a scalar type; return one flat one-dimensional " +
"array (e.g. a.SelectMany(x => x).ToArray()) or publish each inner array from its own tag.");
throw new ScriptResultException(
$"The script returned a value of type '{Describe(type)}', which an OPC UA node cannot carry; return null, " +
"a bool, an integer type, float, double, string, DateTime or Guid, or a one-dimensional array of one of them " +