fix(scripts): memoize missing-assembly resolution on the site compile path

This commit is contained in:
Joseph Doherty
2026-08-12 16:38:04 -04:00
parent 089b16980f
commit 71284adcc4
2 changed files with 27 additions and 0 deletions
@@ -251,4 +251,19 @@ public class ScriptCompilationServiceTests
// The options object itself is cached, so it must not be rebuilt either.
Assert.Same(first.CompiledScript.Options, second.CompiledScript.Options);
}
[Fact]
public void Compile_UsesProcessWideCachingMetadataResolver()
{
SiteScriptCompileCache.Clear();
var result = _service.Compile("resolver-pin", "return 41 + 1;");
Assert.True(result.IsSuccess);
// Without the shared caching resolver, EVERY compile re-resolves the
// transitive assembly closure via MetadataReference.CreateFromFile —
// ~74+ fresh native metadata copies per compiled script (2026-08-12 dump).
Assert.Same(
ZB.MOM.WW.ScadaBridge.ScriptAnalysis.CachingScriptMetadataResolver.Instance,
result.CompiledScript!.Options.MetadataResolver);
}
}