Template validation rejects CallShared/CallScript with a parameters object (blocks deploy) #150

Closed
opened 2026-11-28 06:41:08 -05:00 by dohertj2 · 1 comment
Owner

Summary

Template validation (the pre-deploy gate) rejects every Scripts.CallShared("name", new { ... }) call that passes arguments, so a template that calls a shared script with parameters cannot be deployed. CallScript uses the same check and is affected the same way.

Cause

SemanticValidator.ExtractCallsOfType (src/ZB.MOM.WW.ScadaBridge.TemplateEngine/Validation/SemanticValidator.cs) treats each comma-separated argument after the script name as one positional argument. ValidateCallParameters (line ~361, called at lines 104 and 134) then requires that count to equal the number of declared ParameterDefinitions.

The runtime has no positional form. ScriptCallHelper.CallShared(string scriptName, object? parameters = null, CancellationToken ct = default) and ScriptRuntimeContext.CallScript(string scriptName, object? parameters = null) take ONE parameters object, which ScriptArgs.Normalize turns into a name→value dictionary. A correct call always counts as 1 argument:

  • shared script declares N≠1 parameters → calls 'X' with 1 arguments but N are expected
  • shared script declares no parameters → ... with 1 arguments but 0 are expected

It passes only when exactly one parameter is declared, and then the positional type check compares the whole object expression against that one declared type.

Repro (DEV vd03, 2026-11-28)

  • Shared script SendNotificationExample (id 3) declares NotificationList, Subject, Body.
  • Template NotifyExample (id 49), Call script SendTestNotification:
    await Scripts.CallShared("SendNotificationExample", new { NotificationList = ..., Subject = ..., Body = ... })
  • template validate --id 49 → isValid:false, category 7 (ParameterMismatch): calls 'SendNotificationExample' with 1 arguments but 3 are expected.
  • With the parameter definitions cleared: ... with 1 arguments but 0 are expected.

The same code runs correctly in Test Run and on the site once deployed.

Workaround in use

Put the script name in a variable (var name = "SendNotificationExample"; Scripts.CallShared(name, new { ... })). ExtractStringArgument only recognises a string literal, so the call is no longer validated at all. That is how NotifyExample was deployed on vd03.

Fix direction

  • When the single argument is an anonymous-object creation (new { A = ..., B = ... }), validate by name: required declared parameters must be present, unknown names flagged (or warned), and types checked per member where they can be inferred.
  • For any other single expression (a variable, a dictionary, a method call), skip the count/type check, or at most warn.
  • Zero arguments against declared required parameters stays an error.
  • Add SemanticValidatorTests for CallShared and CallScript with an anonymous object, a dictionary variable, and no arguments. Today no test calls either one with arguments.
## Summary Template validation (the pre-deploy gate) rejects every `Scripts.CallShared("name", new { ... })` call that passes arguments, so a template that calls a shared script with parameters cannot be deployed. `CallScript` uses the same check and is affected the same way. ## Cause `SemanticValidator.ExtractCallsOfType` (`src/ZB.MOM.WW.ScadaBridge.TemplateEngine/Validation/SemanticValidator.cs`) treats each comma-separated argument after the script name as one **positional** argument. `ValidateCallParameters` (line ~361, called at lines 104 and 134) then requires that count to equal the number of declared `ParameterDefinitions`. The runtime has no positional form. `ScriptCallHelper.CallShared(string scriptName, object? parameters = null, CancellationToken ct = default)` and `ScriptRuntimeContext.CallScript(string scriptName, object? parameters = null)` take ONE parameters object, which `ScriptArgs.Normalize` turns into a name→value dictionary. A correct call always counts as 1 argument: - shared script declares N≠1 parameters → `calls 'X' with 1 arguments but N are expected` - shared script declares no parameters → `... with 1 arguments but 0 are expected` It passes only when exactly one parameter is declared, and then the positional type check compares the whole object expression against that one declared type. ## Repro (DEV vd03, 2026-11-28) - Shared script `SendNotificationExample` (id 3) declares `NotificationList`, `Subject`, `Body`. - Template `NotifyExample` (id 49), Call script `SendTestNotification`: `await Scripts.CallShared("SendNotificationExample", new { NotificationList = ..., Subject = ..., Body = ... })` - `template validate --id 49` → `isValid:false`, category 7 (ParameterMismatch): `calls 'SendNotificationExample' with 1 arguments but 3 are expected.` - With the parameter definitions cleared: `... with 1 arguments but 0 are expected.` The same code runs correctly in Test Run and on the site once deployed. ## Workaround in use Put the script name in a variable (`var name = "SendNotificationExample"; Scripts.CallShared(name, new { ... })`). `ExtractStringArgument` only recognises a string literal, so the call is no longer validated at all. That is how `NotifyExample` was deployed on vd03. ## Fix direction - When the single argument is an anonymous-object creation (`new { A = ..., B = ... }`), validate by **name**: required declared parameters must be present, unknown names flagged (or warned), and types checked per member where they can be inferred. - For any other single expression (a variable, a dictionary, a method call), skip the count/type check, or at most warn. - Zero arguments against declared required parameters stays an error. - Add `SemanticValidatorTests` for CallShared and CallScript with an anonymous object, a dictionary variable, and no arguments. Today no test calls either one with arguments.
dohertj2 added the type:bugpriority:p2 labels 2026-11-28 06:41:08 -05:00
Author
Owner

Fixed in 607ffc2e (main). CallShared/CallScript calls are now parsed with Roslyn and the single parameters object is validated by name: an anonymous object must supply every required declared parameter (error otherwise), undeclared names are warnings, literal member types are checked; any other expression (variable, dictionary, method call, null) is not checked; no parameters argument is an error only when required parameters are declared. The literal-name form Scripts.CallShared("SendNotificationExample", new { ... }) now passes validation, so the variable-name workaround is no longer needed once this build is deployed.

Fixed in 607ffc2e (main). CallShared/CallScript calls are now parsed with Roslyn and the single parameters object is validated by name: an anonymous object must supply every required declared parameter (error otherwise), undeclared names are warnings, literal member types are checked; any other expression (variable, dictionary, method call, null) is not checked; no parameters argument is an error only when required parameters are declared. The literal-name form `Scripts.CallShared("SendNotificationExample", new { ... })` now passes validation, so the variable-name workaround is no longer needed once this build is deployed.
Sign in to join this conversation.