fix(scripting): #1063 one compile-refusal authority for editor and deploy gate (ScriptCompileRules + the runtime's own wrapper text) — CS0161 and wrapper injection are now flagged in the editor; #1065 {{equip}} in a Calculation script is refused by the gate and by a new Calculation editor mode

#1063: the Monaco diagnostics dropped every Roslyn error located in the synthesized
wrapper as 'phantom', so CS0161 (not all code paths return a value, pinned on Run)
passed the editor and failed the deploy gate. ScriptCompileRules (Core.Scripting) now
states which diagnostics refuse (every Error, wherever located; LMX001/002 injection)
and which sources skip the compile (blank/passthrough value scripts); ScriptEvaluator
and the editor both use it, and the editor wraps with ScriptEvaluator.WrapperPreamble/
WrapperSuffix instead of its own copy. Wrapper-located refusals are drawn on the
script's last line. EditorGateParityTests runs one corpus through editor and gate in
all three modes.

#1065: a Calculation tag is raw/device-level with no equipment and its seam never
substitutes {{equip}}, so such a script deployed clean and read Bad forever. Refused
rather than substituted: EquipTokenLiteralScanner.FindInCalculation is run by
RoslynDeployScriptChecker for every Calculation use (before the passthrough shortcut,
outside the shared VT/Calc cache) and by the editor in the new 'calculation' mode
(Calculation tag editor; ScriptEdit defaults to it when a Calculation tag uses the
script).
This commit is contained in:
Joseph Doherty
2026-12-03 16:47:14 -05:00
parent a06dc8dd9f
commit 73f49eaf32
18 changed files with 644 additions and 186 deletions
@@ -1,24 +1,49 @@
using ZB.MOM.WW.OtOpcUa.Core.Scripting;
namespace ZB.MOM.WW.OtOpcUa.AdminUI.ScriptAnalysis;
/// <summary>
/// Which seam the editor analyses a script as (lmxopcua#1025). The deploy gate compiles each script as the seam that
/// uses it, so the editor has to wrap the source the same way: a value script is
/// <c>object Run(ScriptGlobals&lt;VirtualTagContext&gt;)</c> (VirtualTag and Calculation share it); a scripted-alarm
/// predicate is <c>bool Run(ScriptGlobals&lt;AlarmPredicateContext&gt;)</c>. Carried as a string on the wire; null,
/// blank or anything unrecognised means <see cref="Value"/>.
/// predicate is <c>bool Run(ScriptGlobals&lt;AlarmPredicateContext&gt;)</c>. A Calculation script compiles as a value
/// script but is held to one more gate rule — no <c>{{equip}}</c> token (lmxopcua#1065) — so it has its own mode.
/// Carried as a string on the wire; null, blank or anything unrecognised means <see cref="Value"/>.
/// </summary>
public static class ScriptAnalysisModes
{
/// <summary>A VirtualTag / Calculation value script (the default).</summary>
/// <summary>A VirtualTag value script (the default).</summary>
public const string Value = "value";
/// <summary>A scripted-alarm predicate: must return <c>bool</c>.</summary>
public const string AlarmPredicate = "alarmPredicate";
/// <summary>A Calculation-tag script: the value shape, plus the Calculation-only refusal of <c>{{equip}}</c>.</summary>
public const string Calculation = "calculation";
/// <summary>True when <paramref name="mode"/> selects the predicate shape.</summary>
/// <param name="mode">The wire value.</param>
/// <returns>Whether it names <see cref="AlarmPredicate"/>.</returns>
public static bool IsPredicate(string? mode) => string.Equals(mode, AlarmPredicate, StringComparison.OrdinalIgnoreCase);
/// <summary>True when <paramref name="mode"/> selects the Calculation rules.</summary>
/// <param name="mode">The wire value.</param>
/// <returns>Whether it names <see cref="Calculation"/>.</returns>
public static bool IsCalculation(string? mode) => string.Equals(mode, Calculation, StringComparison.OrdinalIgnoreCase);
/// <summary>The deploy-gate seam a mode analyses as — what the gate's checker is asked for the same script.</summary>
/// <param name="mode">The wire value.</param>
/// <returns>The seam.</returns>
public static ScriptContextKind KindOf(string? mode) =>
IsPredicate(mode) ? ScriptContextKind.AlarmPredicate
: IsCalculation(mode) ? ScriptContextKind.Calculation
: ScriptContextKind.VirtualTag;
/// <summary>The canonical wire value for <paramref name="mode"/> (unrecognised means <see cref="Value"/>).</summary>
/// <param name="mode">The wire value.</param>
/// <returns>One of the three constants.</returns>
public static string Normalize(string? mode) =>
IsPredicate(mode) ? AlarmPredicate : IsCalculation(mode) ? Calculation : Value;
}
// EquipmentId (optional) carries the owning-equipment context the {{equip}}/<RefName> completion +