fix(ui): disposal guard on Alarm Summary live callback, matching the DebugView pattern (plan R2-07 T9)

This commit is contained in:
Joseph Doherty
2026-07-13 10:58:50 -04:00
parent 925c869826
commit 76ef97f729
2 changed files with 32 additions and 1 deletions
@@ -278,6 +278,30 @@ public class AlarmSummaryRenderTests : BunitContext
});
}
// ── arch-review R2 N7: disposal guard on the live callback ─────────────────
[Fact]
public void LiveCallbackRacingDispose_IsDropped_NoRebuildNoThrow()
{
var cut = RenderWithSiteSelected();
_liveCache.PushAlarms(new List<AlarmStateChanged>
{
new("Gamma", "G-alarm", AlarmState.Active, 300, DateTimeOffset.UtcNow),
});
cut.WaitForAssertion(() => Assert.Equal("Gamma", FirstRowInstance(cut)));
// Snapshot the callback BEFORE disposal — this models a delta thread that
// already read the delegate when Dispose ran (arch-review R2 N7).
var inFlight = _liveCache.CapturedCallback!;
cut.Instance.Dispose();
_liveCache.PushAlarms(new List<AlarmStateChanged>()); // mutate the fake's snapshot
var ex = Record.Exception(inFlight);
Assert.Null(ex);
// The disposed page must not have re-applied the (now empty) live snapshot.
Assert.Equal("Gamma", FirstRowInstance(cut));
}
/// <summary>
/// Controllable in-memory fake of <see cref="ISiteAlarmLiveCache"/>: records
/// subscribe/dispose counts and lets a test push a live snapshot (which flips
@@ -293,6 +317,7 @@ public class AlarmSummaryRenderTests : BunitContext
public int SubscribeCount { get; private set; }
public int DisposeCount { get; private set; }
public int? LastSubscribedSite { get; private set; }
public Action? CapturedCallback => _onChanged;
public IDisposable Subscribe(int siteId, Action onChanged)
{