feat(deploy): #971 follow-up deploy-time script compile gate
The deploy gate never compiled scripts, so a stored script the #971 allow-list now refuses only failed after the deploy (VirtualTag/Calculation Bad "sandbox violation", scripted-alarm load failing for every alarm on the node). - Core.Scripting.Abstractions: IDeployScriptChecker (Roslyn-free) + request/result records; ScriptContextKind moved here (same namespace). - Core.Scripting: ScriptEvaluator.Verify shares a private BuildCheckedCompilation factory with CompileToImage (wrap, injection guard, sandbox compile, ForbiddenTypeAnalyzer; no stack-guard rewrite, no emit). RoslynDeployScriptChecker checks per seam (VT/Calc as VirtualTagContext->object?, passthrough/blank skipped; predicates DependencyExtractor first then AlarmPredicateContext->bool), caches by (compile identity, SHA-256), parallel, bounded. - ControlPlane: DeployScriptGate collects enabled VTs / enabled alarm predicates / Calculation tags, resolves {{equip}} through EquipmentReferenceMap exactly as the compose seams do (template compiled once when SubstitutionPreservesCompilation, else the resolved source), groups findings per script naming its users. AdminOperationsActor warms the cache before the snapshot transaction and runs the authoritative pass on the same snapshot; Deployment:ScriptCompileGateMode = Error (default) | Warn | Off; an absent checker or an internal failure never blocks. - Host binds RoslynDeployScriptChecker on admin nodes. - Docs: VirtualTags.md (gate + upgrade note), ScriptEditor.md, security.md, CLAUDE.md. Found while testing: {{equip}} substitution pastes RawPaths into C# literals unescaped, so a segment containing \ or " breaks (or silently alters) the script; the gate now reports it at deploy.
This commit is contained in:
@@ -178,6 +178,22 @@ editor ⇔ publish parity (`Editor_and_publish_gate_agree`). Each violation is
|
||||
mapped via `tree.GetMappedLineSpan(span)` to user-source coordinates and emitted
|
||||
as an error marker with code `OTSCRIPT_FORBIDDEN`.
|
||||
|
||||
### The deploy gate compiles too (lmxopcua#971 follow-up)
|
||||
|
||||
Saving a script is not compile-gated — the editor's diagnostics are advisory while
|
||||
you type. The **deploy** is: before a deployment is sealed, every script it will
|
||||
run (enabled VirtualTags, enabled scripted-alarm predicates, Calculation tags) is
|
||||
compiled through the same `ScriptEvaluator` pipeline the runtime uses, with
|
||||
`{{equip}}/<RefName>` already resolved per equipment exactly as the compose seams
|
||||
resolve it. Under the default `Deployment:ScriptCompileGateMode=Error`, a script
|
||||
the runtime would refuse rejects the deploy with `ScriptCompileFailed`, naming the
|
||||
script, the seam it was compiled for and the entities using it — so an error the
|
||||
editor showed can no longer be deployed silently. Two differences from the editor
|
||||
to know: the gate compiles each script **as the seam that uses it** (a predicate
|
||||
must return `bool`; the editor analyses every script as a VirtualTag body), and it
|
||||
only checks scripts something enabled uses. See `docs/VirtualTags.md`
|
||||
§"Deploy-time script compile gate" for modes, caching and the upgrade note.
|
||||
|
||||
### Runtime safety (what happens after publish)
|
||||
|
||||
The editor cannot catch a script that compiles cleanly but never returns or
|
||||
|
||||
Reference in New Issue
Block a user