fix(centralui): bound FlowDebugService script cache (review 2026-10-21 07/M-2)

This commit is contained in:
Joseph Doherty
2026-10-22 08:37:20 -04:00
parent bd0f87e523
commit b032d7fe48
2 changed files with 29 additions and 0 deletions
@@ -677,6 +677,24 @@ public sealed class FlowDebugServiceTests : IDisposable
Assert.False(options.Single(o => o.CanonicalName == "Mod.Tick").IsWriteKind);
}
/// <summary>Verifies the per-circuit script cache stays bounded however many instances are browsed (review 2026-10-21 07/M-2).</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task GetInstanceScripts_BrowsingManyInstances_KeepsCacheBounded()
{
var svc = CreateService(reply: null);
for (var id = 100; id < 100 + 3 * FlowDebugService.ScriptCacheCapacity; id++)
{
WireFlattened(id, "Sim" + id, new ResolvedScript { CanonicalName = "Manual", Code = "x", TriggerType = "Call" });
await svc.GetInstanceScriptsAsync(id);
}
var cache = (System.Collections.IDictionary)typeof(FlowDebugService)
.GetField("_scriptCache", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!
.GetValue(svc)!;
Assert.True(cache.Count <= FlowDebugService.ScriptCacheCapacity);
}
/// <summary>Verifies that requesting scripts for an unknown instance yields an empty result.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]