feat(alarms): carry AlarmTypeName + operator Comment on AlarmTransitionEvent (historian feed prep)

This commit is contained in:
Joseph Doherty
2026-06-11 11:03:00 -04:00
parent cd72f79ef4
commit 8ac3ac5be9
5 changed files with 61 additions and 4 deletions
@@ -448,6 +448,37 @@ public sealed class ScriptedAlarmEngineTests
persisted!.Confirmed.ShouldBe(AlarmConfirmedState.Confirmed);
}
/// <summary>Verifies the emitted <see cref="ScriptedAlarmEvent.Comment"/> carries the operator's
/// ack comment on the Acknowledged emission while the earlier Activated emission has no comment,
/// and that an explicit AddComment emission carries the comment text. (historian feed prep)</summary>
[Fact]
public async Task Emission_carries_operator_Comment_on_ack_and_add_comment()
{
var up = new FakeUpstream();
up.Set("Temp", 50);
using var eng = Build(up, out _);
await eng.LoadAsync([Alarm("HighTemp", """return (int)ctx.GetTag("Temp").Value > 100;""")],
TestContext.Current.CancellationToken);
var events = new List<ScriptedAlarmEvent>();
eng.OnEvent += (_, e) => events.Add(e);
// Activate → Acknowledge(comment) → AddComment(text).
up.Push("Temp", 150);
await WaitForAsync(() => events.Any(e => e.Emission == EmissionKind.Activated));
await eng.AcknowledgeAsync("HighTemp", "op1", "looking into it", TestContext.Current.CancellationToken);
await WaitForAsync(() => events.Any(e => e.Emission == EmissionKind.Acknowledged));
await eng.AddCommentAsync("HighTemp", "op2", "second look", TestContext.Current.CancellationToken);
await WaitForAsync(() => events.Any(e => e.Emission == EmissionKind.CommentAdded));
// Engine-driven Activated emission carries no operator comment.
events.First(e => e.Emission == EmissionKind.Activated).Comment.ShouldBeNull();
// Acknowledged emission carries the ack comment.
events.First(e => e.Emission == EmissionKind.Acknowledged).Comment.ShouldBe("looking into it");
// CommentAdded emission carries the latest appended comment text.
events.First(e => e.Emission == EmissionKind.CommentAdded).Comment.ShouldBe("second look");
}
// (2b) TimedShelveAsync / UnshelveAsync end-to-end through the engine.
/// <summary>Verifies that TimedShelveAsync shelves with a deadline and UnshelveAsync removes the shelve before the timer expires.</summary>
[Fact]