fix(alarms): a native condition's AddComment is not subject to the scripted verdict (#937)

Native AddComment shares HandleAlarmCommand but is applied at the node only;
asking the scripted host made it BadInvalidState (live A02 on fu937-1).

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Joseph Doherty
2026-11-28 11:01:47 -05:00
parent 4d41e61858
commit e45012b69d
3 changed files with 48 additions and 5 deletions
@@ -189,6 +189,43 @@ public sealed class ScriptedCommandVerdictWireTests
finally { await rig.DisposeAsync(); }
}
/// <summary>
/// A NATIVE condition's AddComment is applied at the node (no scripted engine owns it): neither the scripted pre-check
/// nor the verdict ask applies, even while the scripted engine is blind (caught live by A02 on fu937-1).
/// </summary>
[Fact]
public async Task A_native_AddComment_is_not_subject_to_the_scripted_verdict()
{
var ct = TestContext.Current.CancellationToken;
var rig = await StartAsync("Verdict937NativeComment", encrypted: false, ct);
try
{
rig.Enforce(false, [Key()], ClusterGrant(KeyPrincipal, "acl-key", All));
rig.MaterialiseNative();
var asked = 0;
rig.Nm.AlarmCommandAsker = (cmd, _) =>
{
Interlocked.Increment(ref asked);
return Task.FromResult(new AlarmCommandOutcome(cmd.AlarmId, cmd.Operation, AlarmCommandVerdict.NotApplied, "not mine"));
};
rig.Nm.ScriptedAlarmCommandPreflight = () => "the scripted engine is blind";
using var session = await rig.ConnectAsync(anonymous: false, ct);
var events = new RecordedEvents();
var subscription = await RecordedEvents.SubscribeAsync(session, events, ct);
var item = RecordedEvents.AddEventItem(subscription, ObjectIds.Server);
await subscription.ApplyChangesAsync(ct);
rig.Project(true, ConditionMethodEventTests.PreState("AddComment", native: true) with { Message = "base" });
await RecordedEvents.WaitUntilAsync(() => events.Has(item, "base"));
await ConditionMethodEventTests.CallAsync(session, ConditionNodeId(session, true), "AddComment",
events.LatestEventId(item, "base"), ct);
Volatile.Read(ref asked).ShouldBe(0);
await subscription.DeleteAsync(true, ct);
}
finally { await rig.DisposeAsync(); }
}
/// <summary>A2b: a remote (gRPC data) condition method on a scripted condition carries the same verdict.</summary>
[Fact]
public async Task A_remote_condition_method_reports_the_engine_refusal_as_dispatched()