fix(scripted-alarms): harden artifact boolean decode + direct helper tests (T6 review)

Default HistorizeToAveva/Retain/Enabled to the entity defaults (true) when a
field is absent/null/non-boolean so a partial blob decodes identically to the
composer's view of a default-constructed ScriptedAlarm (byte-parity), and only
call GetBoolean for a genuine true/false token. Add direct ExtractAlarmDependencyRefs
unit tests (overlap dedup + reserved {{equip}} exclusion).
This commit is contained in:
Joseph Doherty
2026-06-10 14:47:24 -04:00
parent 8e8ca9efe8
commit c9590c03d0
2 changed files with 37 additions and 6 deletions
@@ -653,12 +653,16 @@ public static class DeploymentArtifact
var severity = el.TryGetProperty("Severity", out var svEl) && svEl.TryGetInt32(out var sv) ? sv : 0;
var messageTemplate = el.TryGetProperty("MessageTemplate", out var mtEl) ? mtEl.GetString() : null;
var predicateScriptId = el.TryGetProperty("PredicateScriptId", out var psEl) ? psEl.GetString() : null;
var historize = el.TryGetProperty("HistorizeToAveva", out var hEl) && hEl.ValueKind != JsonValueKind.Null
? hEl.GetBoolean() : false;
var retain = el.TryGetProperty("Retain", out var rEl) && rEl.ValueKind != JsonValueKind.Null
? rEl.GetBoolean() : false;
var enabled = el.TryGetProperty("Enabled", out var enEl) && enEl.ValueKind != JsonValueKind.Null
? enEl.GetBoolean() : false;
// Booleans default to the entity defaults (true) when absent / null / non-boolean, so a
// partial blob decodes the same as the composer's view of a default-constructed
// ScriptedAlarm — preserving byte-parity. GetBoolean only runs for a genuine true/false
// token (a non-bool token would otherwise throw InvalidOperationException, uncaught here).
bool ReadBool(string prop, bool dflt) =>
el.TryGetProperty(prop, out var b) && b.ValueKind is JsonValueKind.True or JsonValueKind.False
? b.GetBoolean() : dflt;
var historize = ReadBool("HistorizeToAveva", true);
var retain = ReadBool("Retain", true);
var enabled = ReadBool("Enabled", true);
if (string.IsNullOrWhiteSpace(scriptedAlarmId)) continue;