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:
@@ -18,7 +18,12 @@ namespace ZB.MOM.WW.OtOpcUa.Core.Scripting;
|
||||
/// <c>AlarmPredicateContext → bool</c>. No passthrough shortcut: the alarm engine always compiles.</item>
|
||||
/// </list>
|
||||
/// <see cref="ScriptEvaluator{TContext, TResult}.Verify"/> builds its compilation through the same private factory
|
||||
/// <see cref="ScriptEvaluator{TContext, TResult}.CompileToImage"/> uses, so the gate and the runtime cannot drift.
|
||||
/// <see cref="ScriptEvaluator{TContext, TResult}.CompileToImage"/> uses, so the gate and the runtime cannot drift;
|
||||
/// which diagnostics refuse and which sources skip the compile are <see cref="ScriptCompileRules"/>, which the Monaco
|
||||
/// editor reads too (lmxopcua#1063). One rule is kind-specific and runs before everything else: a
|
||||
/// <b>Calculation</b> script may not carry <c>{{equip}}</c> in a path literal
|
||||
/// (<see cref="EquipTokenLiteralScanner.FindInCalculation"/>, lmxopcua#1065) — the passthrough shortcut included, and
|
||||
/// outside the cache, because VirtualTag and Calculation otherwise share one cached verdict.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
@@ -55,11 +60,21 @@ public sealed class RoslynDeployScriptChecker : IDeployScriptChecker
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(requests);
|
||||
var keys = new string?[requests.Count];
|
||||
var direct = new IReadOnlyList<string>?[requests.Count];
|
||||
var pending = new Dictionary<string, DeployScriptCheckRequest>(StringComparer.Ordinal);
|
||||
for (var i = 0; i < requests.Count; i++)
|
||||
{
|
||||
var request = requests[i] ?? throw new ArgumentException("A request is null.", nameof(requests));
|
||||
if (SkipsCompile(request)) continue;
|
||||
// lmxopcua#1065: a Calculation script may not carry {{equip}} at all. A source scan, kind-specific, so it runs
|
||||
// before the passthrough shortcut (`return ctx.GetTag("{{equip}}/X").Value;` never reaches Roslyn) and outside
|
||||
// the compile cache (VirtualTag and Calculation share one cached compile verdict; this rule is not shared).
|
||||
if (request.Kind == ScriptContextKind.Calculation
|
||||
&& EquipTokenLiteralScanner.FindInCalculation(request.Source) is { Count: > 0 } calcFindings)
|
||||
{
|
||||
direct[i] = ["equip token in a Calculation script — " + string.Join("; ", calcFindings.Select(f => f.Message))];
|
||||
continue;
|
||||
}
|
||||
if (ScriptCompileRules.SkipsCompile(request.Kind, request.Source)) continue;
|
||||
var key = CacheKey(request);
|
||||
keys[i] = key;
|
||||
if (!_cache.ContainsKey(key)) pending.TryAdd(key, request);
|
||||
@@ -79,7 +94,7 @@ public sealed class RoslynDeployScriptChecker : IDeployScriptChecker
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
results[i] = new DeployScriptCheckResult(
|
||||
requests[i], keys[i] is { } key ? Resolve(key, requests[i]).Problems : []);
|
||||
requests[i], direct[i] ?? (keys[i] is { } key ? Resolve(key, requests[i]).Problems : []));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
@@ -94,11 +109,6 @@ public sealed class RoslynDeployScriptChecker : IDeployScriptChecker
|
||||
return verdict;
|
||||
}
|
||||
|
||||
/// <summary>True when the runtime seam answers the source without compiling it.</summary>
|
||||
private static bool SkipsCompile(DeployScriptCheckRequest request) =>
|
||||
request.Kind is ScriptContextKind.VirtualTag or ScriptContextKind.Calculation
|
||||
&& (string.IsNullOrWhiteSpace(request.Source) || PassthroughScript.TryMatch(request.Source, out _));
|
||||
|
||||
private static string CacheKey(DeployScriptCheckRequest request)
|
||||
{
|
||||
var identity = request.Kind == ScriptContextKind.AlarmPredicate ? "alarm" : "value";
|
||||
|
||||
Reference in New Issue
Block a user