fix(galaxy): #895 review - re-areaed, subtag-provider and pre-subscription alarm references resolve
v2-ci / unit-tests (push) Has been cancelled

Review of e113faf5 found three gaps in the alarm-feed reverse map:

- A tag hand-authored as Galaxy!<Area>.tag.Attr stopped resolving once Galaxy moved the object to
  another area: the feed's full reference named the new area and none of the fallbacks looked at the
  authored provider form. Provider-form attributeRefs are now also indexed by their area-free
  tag.Attr, and the ack dials the reference the feed now uses.
- A reference composed with an empty area (Galaxy!tag.Attr, the gateway's ComposeFullReference when
  the area is blank) with the subtag provider's object-only source reference stripped "tag." and
  missed. The part after the '!' is now also tried.
- Resolution ran after the subscription gate, so a transition seen with no handle registered taught
  nothing for the ack. It now resolves first; fan-out is still gated.

A picker tag and a provider-form tag for the same alarm resolve deterministically and log a warning.
New tests cover re-area for both forms, subtag shapes, H6-style dotted refs, unmatched/malformed
refs, the collision, pre-subscription learning, and the #869 confirmation of a picker-form ack;
reverted-code runs fail them.

Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
This commit is contained in:
Joseph Doherty
2026-11-13 01:49:07 -05:00
parent 9375c9e287
commit d528838864
3 changed files with 227 additions and 21 deletions
@@ -206,6 +206,155 @@ public sealed class GalaxyDriverRawPathKeyingTests
driver.ToAlarmAckReference("Galaxy!Area1.Other.Attr").ShouldBe("Galaxy!Area1.Other.Attr");
}
// ===== lmxopcua#895 review: area changes, subtag-provider shape, collisions, ack confirmation =====
private const string OtherRawPath = "area/line/tank1/level-hand";
private static GalaxyDriverOptions Opts(params (string RawPath, string AttributeRef)[] tags) => OptsWithRawTags() with
{
RawTags = [.. tags.Select(t => new RawTagEntry(t.RawPath, $"{{\"attributeRef\":\"{t.AttributeRef}\"}}", false))],
};
/// <summary>Galaxy moves a picker-authored tag's object to another area: the transition still resolves (via the
/// unchanged source reference) and the ack follows the latest area the feed named.</summary>
[Fact]
public void PickerForm_AfterReArea_ResolvesAndAckFollowsTheNewArea()
{
using var driver = new GalaxyDriver("g", OptsWithRawTags(), hierarchySource: null);
driver.ResolveAlarmRawPath("Galaxy!Area1.Tank1.Level", AttributeRef).ShouldBe(RawPath);
driver.ResolveAlarmRawPath("Galaxy!Area2.Tank1.Level", AttributeRef).ShouldBe(RawPath);
driver.ToAlarmAckReference(RawPath).ShouldBe("Galaxy!Area2.Tank1.Level");
}
/// <summary>A tag hand-authored as <c>Galaxy!Area1.tag.Attr</c> keeps resolving after Galaxy re-areas the object
/// (before the review fix the feed's <c>Galaxy!Area2…</c> matched nothing and every transition was dropped), and
/// its ack dials the reference the feed now uses.</summary>
[Fact]
public void HandAuthoredProviderForm_AfterReArea_ResolvesAndAcksTheNewArea()
{
using var driver = new GalaxyDriver("g", Opts((RawPath, "Galaxy!Area1.Tank1.Level")), hierarchySource: null);
driver.ToAlarmAckReference(RawPath).ShouldBe("Galaxy!Area1.Tank1.Level");
driver.ResolveAlarmRawPath("Galaxy!Area2.Tank1.Level", "Tank1.Level").ShouldBe(RawPath);
driver.ToAlarmAckReference(RawPath).ShouldBe("Galaxy!Area2.Tank1.Level");
}
/// <summary>The gateway's subtag (degraded) provider sends only the object as the source reference. The
/// area-stripped full reference resolves it, and a reference composed with an empty area
/// (<c>Galaxy!tag.Attr</c>) resolves through what follows the <c>!</c>.</summary>
[Theory]
[InlineData("Galaxy!Area1.Tank1.Level", "Tank1")]
[InlineData("Galaxy!Tank1.Level", "Tank1")]
[InlineData("Galaxy!Tank1.Level", "")]
[InlineData("Galaxy!Area1.Tank1.Level", null)]
public void SubtagProviderShapes_Resolve(string fullRef, string? source)
{
using var driver = new GalaxyDriver("g", OptsWithRawTags(), hierarchySource: null);
driver.ResolveAlarmRawPath(fullRef, source).ShouldBe(RawPath);
driver.ToAlarmAckReference(RawPath).ShouldBe(fullRef);
}
/// <summary>H6-style contained/dotted references: the object's tag_name (not its contained hierarchy) is what
/// the feed and the picker share, and an alarm attribute nested under another attribute keeps its dots.</summary>
[Theory]
[InlineData("TableAlarms_008.RuntimeAlert", "Galaxy!CVDAisle_1.TableAlarms_008.RuntimeAlert", "TableAlarms_008.RuntimeAlert")]
[InlineData("TableAlarms_008.RuntimeAlert", "Galaxy!CVDAisle_1.TableAlarms_008.RuntimeAlert", "TableAlarms_008")]
[InlineData("Tank1.Level.HiHi", "Galaxy!Area1.Tank1.Level.HiHi", "Tank1")]
public void DottedAndContainedReferences_Resolve(string attributeRef, string fullRef, string source)
{
using var driver = new GalaxyDriver("g", Opts((RawPath, attributeRef)), hierarchySource: null);
driver.ResolveAlarmRawPath(fullRef, source).ShouldBe(RawPath);
driver.ToAlarmAckReference(RawPath).ShouldBe(fullRef);
}
/// <summary>Feed references that match nothing — or are malformed — keep the identity fallback, never throw, and
/// teach nothing (no authored RawPath's ack reference changes).</summary>
[Theory]
[InlineData("Galaxy!Area1.Other.Attr", "Other.Attr")]
[InlineData("Galaxy!Area1.Other.Attr", "Other")]
[InlineData("Galaxy!", "")]
[InlineData("Galaxy!Area1.", null)]
[InlineData("NoBang.Tank1", "")]
[InlineData("", "")]
public void UnmatchedOrMalformed_KeepsIdentity_AndLearnsNothing(string fullRef, string? source)
{
using var driver = new GalaxyDriver("g", OptsWithRawTags(), hierarchySource: null);
driver.ResolveAlarmRawPath(fullRef, source).ShouldBe(fullRef);
driver.ToAlarmAckReference(RawPath).ShouldBe(AttributeRef);
}
/// <summary>The same Galaxy alarm authored twice — picker form and hand-authored provider form. Deterministic: the
/// exact provider-form match wins while the area matches; any other area surfaces under the picker tag.</summary>
[Fact]
public void PickerAndHandAuthoredOfTheSameAlarm_ResolveDeterministically()
{
using var driver = new GalaxyDriver(
"g", Opts((RawPath, AttributeRef), (OtherRawPath, "Galaxy!Area1.Tank1.Level")), hierarchySource: null);
driver.ResolveAlarmRawPath("Galaxy!Area1.Tank1.Level", AttributeRef).ShouldBe(OtherRawPath);
driver.ResolveAlarmRawPath("Galaxy!Area2.Tank1.Level", AttributeRef).ShouldBe(RawPath);
driver.ToAlarmAckReference(RawPath).ShouldBe("Galaxy!Area2.Tank1.Level");
driver.ToAlarmAckReference(OtherRawPath).ShouldBe("Galaxy!Area1.Tank1.Level");
}
/// <summary>A transition that arrives while no alarm subscription is registered is not fanned out, but it still
/// teaches the ack reference (the feed starts before SubscribeAlarmsAsync registers its handle).</summary>
[Fact]
public async Task TransitionWithoutSubscription_StillTeachesTheAckReference()
{
var feed = new FakeAlarmFeed();
var ack = new RecordingAcknowledger();
using var driver = new GalaxyDriver(
"g", OptsWithRawTags(), hierarchySource: null, alarmAcknowledger: ack, alarmFeed: feed,
ackCredentialResolver: FixedAckCredentialResolver.Fallback());
var handle = await driver.SubscribeAlarmsAsync(["Tank1"], CancellationToken.None);
await driver.UnsubscribeAlarmsAsync(handle, CancellationToken.None);
var observed = new List<AlarmEventArgs>();
driver.OnAlarmEvent += (_, args) => observed.Add(args);
feed.Emit(NewTransition("Galaxy!Area1.Tank1.Level", AttributeRef));
await driver.AcknowledgeAsync(
[new AlarmAcknowledgeRequest("Tank1", RawPath, "ack it")], CancellationToken.None);
observed.ShouldBeEmpty();
ack.Calls.ShouldHaveSingleItem().AlarmRef.ShouldBe("Galaxy!Area1.Tank1.Level");
}
/// <summary>lmxopcua#869 with the picker form: an ack the gateway only SENT is confirmed by Galaxy's acknowledged
/// transition, which names the provider-qualified reference — the one the ack now dials.</summary>
[Fact]
public async Task PickerForm_UnconfirmedAck_IsConfirmedByTheFeedsAcknowledgedTransition()
{
const string fullRef = "Galaxy!Area1.Tank1.Level";
var feed = new FakeAlarmFeed();
var opts = OptsWithRawTags() with { AlarmAck = new GalaxyAlarmAckOptions { ConfirmTimeoutMs = 120_000 } };
using var driver = new GalaxyDriver(
"g", opts, hierarchySource: null, alarmAcknowledger: new UnconfirmedAcknowledger(), alarmFeed: feed,
ackCredentialResolver: FixedAckCredentialResolver.Fallback());
await driver.SubscribeAlarmsAsync(["Tank1"], CancellationToken.None);
feed.Emit(NewTransition(fullRef, AttributeRef));
AlarmAcknowledgeRequest[] request = [new AlarmAcknowledgeRequest("Tank1", RawPath, "ack it")];
await driver.AcknowledgeAsync(request, CancellationToken.None);
var confirm = driver.ConfirmAcknowledgedAsync(request, CancellationToken.None);
confirm.IsCompleted.ShouldBeFalse();
feed.Emit(NewTransition(fullRef, AttributeRef) with { TransitionKind = GalaxyAlarmTransitionKind.Acknowledge });
await TestWait.ForAsync(confirm, "the feed's acknowledged transition must confirm the picker-form ack");
}
private sealed class UnconfirmedAcknowledger : IGalaxyAlarmAcknowledger
{
public Task<GalaxyAckOutcome> AcknowledgeAsync(
string alarmFullReference, string comment, GalaxyAckCredential credential, CancellationToken cancellationToken)
=> Task.FromResult(GalaxyAckOutcome.Unconfirmed("sent; OnWriteComplete not observed"));
}
// ===== helpers / fakes =====
private static GalaxyAttribute Attr(string name, int sec)