test(live): capture OperationComplete trigger, subtag Clear and status rows on windev (#210, #211)
ci / nightly-windev (push) Has been skipped
ci / windows-x86 (push) Successful in 2m23s
ci / java (push) Failing after 7m49s
ci / portable (push) Failing after 16m36s

Live MXAccess captures against the windev DEV Galaxy, recorded in
docs/LiveCaptures-2026-11-13.md:

- OperationComplete follows a Suspend/Activate whose synchronous MxStatus is
  Pending (advised, resolved item); one Ok row from RespondingLmx. Pinned by
  the new OperationCompleteLiveProbeTests live fact, with an
  unresolved-reference negative control. (#211 §3.1)
- No public COM event carries completion-only status bytes. All 71
  completions were typed MXSTATUS_PROXY[], so they stay raw permanently.
  (#211 §3.3)
- Subtag-mode Clear is drivable: the TestAlarm UDAs are MxSecurityOperate,
  so AuthenticateUser + WriteSecured toggles them. The new self-driven
  LiveSubtag_SelfDrivenRaiseThenClear_SynthesizesClear fact asserts the
  UnackAlm -> UnackRtn Clear (mutation-checked). (#210 §3.7)
- The B8 buffered "NoData bootstrap" is a ConfigurationError resolution
  failure (detail 6 / 1002). The DEV Galaxy has no buffered attribute, so a
  multi-sample capture needs IDE work. provider_switches was not driven. (#210)
- Status-row catalogue for lmxopcua#872: no Warning row seen, and Pending
  only on the synchronous Suspend/Activate return.

Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
This commit is contained in:
Joseph Doherty
2026-11-12 23:34:46 -05:00
parent 4890a3d16e
commit 9e4be25807
7 changed files with 584 additions and 24 deletions
@@ -1040,15 +1040,16 @@ public sealed class WorkerLiveMxAccessSmokeTests(ITestOutputHelper output)
// Best-effort capture of a SAMPLE-BEARING buffered batch.
//
// Live observation (B8): immediately after Advise the provider delivers an
// initial OnBufferedDataChange with data_type=NoData / raw_data_type=0 and zero
// quality+timestamp samples — the buffered analogue of the bad-quality/
// registration-state bootstrap event the OnDataChange tests skip with their
// family-match predicate. That empty bootstrap is parity, NOT a dropped payload:
// the converter ran without crashing and there were simply no samples to carry.
// We therefore match only a batch that actually carries samples, so a real
// multi-sample conversion can be validated and the empty bootstrap is skipped
// rather than mistaken for a defect.
// Live observation (B8, re-read 2026-11-13): immediately after Advise the provider
// delivers one OnBufferedDataChange with data_type=NoData and zero quality and
// timestamp samples. Its status row is ConfigurationError: detail 6
// (InvalidReference) for the (item, context) form used here, and detail 1002
// (InvalidPropertyId) for a full reference to an attribute without a buffer. It is
// a resolution failure, not a bootstrap. The DEV Galaxy has no buffered attribute,
// so no sample-bearing batch can arrive (docs/LiveCaptures-2026-11-13.md §5). The
// converter handling it without crashing is still worth keeping. We match only a
// batch that carries samples, so the test validates a multi-sample conversion if
// the item is pointed at a buffered attribute.
MxEvent? bufferedBatch = null;
try
{
@@ -1082,9 +1083,9 @@ public sealed class WorkerLiveMxAccessSmokeTests(ITestOutputHelper output)
{
// RESIDUAL (documented): the command path (AddBufferedItem +
// SetBufferedUpdateInterval + Advise) is proven and the buffered EVENT plumbing
// is live (the empty NoData bootstrap arrives and converts without crashing),
// but the rig did not drive a sample-bearing buffered batch within the timeout
// — the same environmental limitation as the externally-undrivable alarm rig.
// is live (the NoData resolution-failure event arrives and converts without
// crashing), but the rig has no buffered attribute to deliver a sample-bearing
// batch (docs/LiveCaptures-2026-11-13.md §5).
// The §3.2 OnBufferedDataChange MULTI-SAMPLE conversion therefore remains
// unverified live. This is environmental, not a defect — let the test pass.
output.WriteLine(
@@ -18,10 +18,12 @@
// 2. Remove (or set to null) the Skip parameter on the [Fact] below.
// 3. Drive a TestMachine alarm so its Active/Acked subtags toggle — either an
// alarm flip script (same one used by AlarmsLiveSmokeTests, ~10 s cadence)
// or a manual operator/IDE toggle of the alarm attribute. The rig's
// TestAlarm attributes are object-driven, so an external MXAccess Write
// cannot toggle them (confirmed live 2026-06-14 by toggling TestAlarm002
// from the IDE).
// or a manual operator/IDE toggle of the alarm attribute. The 2026-06-14
// conclusion that the rig's TestAlarm attributes are object-driven was
// wrong: they are MxSecurityOperate, so a plain Write is refused with 1008,
// and AuthenticateUser + WriteSecured toggles them.
// LiveSubtag_SelfDrivenRaiseThenClear_SynthesizesClear drives its own alarm
// that way and needs no flip script (docs/LiveCaptures-2026-11-13.md §4).
//
// net48/x86 constraints:
// - No init-only properties, records, index/range operators, C# 8+ pattern
@@ -205,6 +207,153 @@ public sealed class AlarmSubtagLiveSmokeTests
}
}
/// <summary>
/// Self-driven subtag lifecycle (mxaccessgw#210, stillpending §3.7): raises the
/// alarm with a secured write of its condition attribute, waits for the
/// subtag state machine's Raise, clears it with a second secured write and
/// asserts the synthesized Clear (UnackAlm -> UnackRtn, Degraded, same
/// synthetic GUID). The rig's TestAlarm UDAs are <c>MxSecurityOperate</c>:
/// a plain <c>Write</c> is refused with SecurityError 1008, which is why the
/// 2026-06 runs found them "object-driven". <c>WriteSecured</c> after
/// <c>AuthenticateUser</c> drives them (docs/AlarmProbeFindings.md). Runs only
/// when <c>MXGATEWAY_RUN_LIVE_MXACCESS_TESTS=1</c>. Object defaults to
/// <c>TestMachine_001</c>; override with <c>MXGATEWAY_LIVE_SUBTAG_ALARM_OBJECT</c>.
/// The write identity is <c>MXGATEWAY_PROBE_ACK_USER</c>/<c>_PASSWORD</c>
/// (default: the rig's <c>Administrator</c> with an empty password).
/// The alarm is left cleared (UNACK_RTN).
/// </summary>
[LiveMxAccessFact]
public void LiveSubtag_SelfDrivenRaiseThenClear_SynthesizesClear()
{
Exception? threadException = null;
ManualResetEventSlim done = new ManualResetEventSlim(false);
Thread thread = new Thread(() =>
{
try { RunSelfDrivenClear(); }
catch (Exception ex) { threadException = ex; }
finally { done.Set(); }
});
thread.IsBackground = true;
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
Assert.True(done.Wait(LiveProbeTimeout), "Live probe thread did not finish within " + LiveProbeTimeout + ".");
thread.Join();
List<string> lines = new List<string>();
string? line;
while (log.TryDequeue(out line))
{
output.WriteLine(line);
lines.Add(line);
}
string logPath = Environment.GetEnvironmentVariable("PROBE_LOG")
?? System.IO.Path.Combine(System.IO.Path.GetTempPath(), "alarm-subtag-clear-probe.log");
try { System.IO.File.WriteAllLines(logPath, lines); }
catch (Exception writeEx) { output.WriteLine("probe-log write failed: " + writeEx.Message); }
if (threadException != null)
{
throw threadException;
}
}
private void RunSelfDrivenClear()
{
string? objectName = Environment.GetEnvironmentVariable("MXGATEWAY_LIVE_SUBTAG_ALARM_OBJECT");
if (string.IsNullOrWhiteSpace(objectName))
{
objectName = "TestMachine_001";
}
string alarmTag = objectName + ".TestAlarm001";
string fullReference = AlarmRecordTransitionMapper.ComposeFullReference(Provider, Group, alarmTag);
Log("=== Self-driven subtag Raise -> Clear ===");
Log("AlarmFullReference: " + fullReference);
AlarmSubtagTarget target = new AlarmSubtagTarget
{
AlarmFullReference = fullReference,
SourceObjectReference = alarmTag,
ActiveSubtag = alarmTag + ".InAlarm",
AckedSubtag = alarmTag + ".Acked",
AckCommentSubtag = alarmTag + ".AckMsg",
PrioritySubtag = alarmTag + ".Priority",
};
MxAccessComObjectFactory factory = new MxAccessComObjectFactory();
LmxSubtagAlarmSource source = new LmxSubtagAlarmSource(factory, clientName: null);
using SubtagAlarmConsumer consumer = new SubtagAlarmConsumer(source, new List<AlarmSubtagTarget> { target });
ConcurrentQueue<MxAlarmTransitionEvent> transitions = new ConcurrentQueue<MxAlarmTransitionEvent>();
consumer.AlarmTransitionEmitted += (_, e) =>
{
Log("Transition emitted: " + DescribeTransition(e));
transitions.Enqueue(e);
};
source.ValueChanged += (_, c) => Log(string.Format("raw ValueChanged: {0} = {1}", c.ItemAddress, c.Value));
// A separate registration drives the condition attribute, as an operator client would.
IMxAccessServer writer = new MxAccessComServer(factory.Create());
int writerHandle = writer.Register("mxgw-subtag-clear-probe");
int conditionItem = writer.AddItem(writerHandle, alarmTag);
writer.Advise(writerHandle, conditionItem); // MXAccess refuses writes to unadvised items
string user = Environment.GetEnvironmentVariable("MXGATEWAY_PROBE_ACK_USER") ?? "Administrator";
string password = Environment.GetEnvironmentVariable("MXGATEWAY_PROBE_ACK_PASSWORD") ?? string.Empty;
int userId = writer.AuthenticateUser(writerHandle, user, password);
Log(string.Format("AuthenticateUser({0}) -> userId={1}", user, userId));
Assert.NotEqual(0, userId);
try
{
consumer.Subscribe(string.Format(@"\\{0}\Galaxy!{1}", Environment.MachineName, Group));
PumpFor(TimeSpan.FromSeconds(4));
Log("Driving condition = false (baseline) ...");
writer.WriteSecured(writerHandle, conditionItem, userId, 0, false);
PumpFor(TimeSpan.FromSeconds(4));
MxAlarmTransitionEvent? drained;
while (transitions.TryDequeue(out drained))
{
Log("Drained baseline transition: " + DescribeTransition(drained!));
}
Log("Driving condition = true (RAISE) ...");
writer.WriteSecured(writerHandle, conditionItem, userId, 0, true);
MxAlarmTransitionEvent? raise = WaitForTransitionKind(transitions, AlarmTransitionKind.Raise, RaiseWaitTimeout, "Raise");
Assert.NotNull(raise);
Assert.True(raise!.Record.Degraded);
Assert.Equal(MxAlarmStateKind.UnackAlm, raise.Record.State);
Log("Driving condition = false (CLEAR) ...");
writer.WriteSecured(writerHandle, conditionItem, userId, 0, false);
MxAlarmTransitionEvent? clear = WaitForTransitionKind(transitions, AlarmTransitionKind.Clear, ClearWaitTimeout, "Clear");
Assert.NotNull(clear);
Assert.True(clear!.Record.Degraded, "Subtag-synthesized Clear must be Degraded.");
Assert.Equal(MxAlarmStateKind.UnackAlm, clear.PreviousState);
Assert.Equal(MxAlarmStateKind.UnackRtn, clear.Record.State);
Assert.Equal(raise.Record.AlarmGuid, clear.Record.AlarmGuid);
Log(string.Format("CONFIRMED: subtag Clear synthesized ({0} -> {1}, Guid={2}).",
clear.PreviousState, clear.Record.State, clear.Record.AlarmGuid));
}
finally
{
try { writer.WriteSecured(writerHandle, conditionItem, userId, 0, false); PumpFor(TimeSpan.FromSeconds(1)); }
catch (Exception ex) { Log("restore write failed: " + ex.Message); }
try { writer.Unregister(writerHandle); }
catch (Exception ex) { Log("writer unregister failed: " + ex.Message); }
}
}
private static void PumpFor(TimeSpan duration)
{
DateTime deadline = DateTime.UtcNow + duration;
while (DateTime.UtcNow < deadline)
{
PumpMessages();
Thread.Sleep(100);
}
}
private void RunProbe()
{
Log("=== Subtag runtime-path resolution probe ===");
@@ -0,0 +1,230 @@
// OperationCompleteLiveProbeTests.cs
//
// Live fact for mxaccessgw#211 (stillpending §3.1): what makes native MXAccess raise
// the public OperationComplete COM event.
//
// RESULT (windev, DEV Galaxy, 2026-11-13): Suspend and Activate on an ADVISED item
// whose reference RESOLVED return a synchronous MxStatus of category Pending
// (raw category 1, success -1, detail 0, detected by RequestingLmx). About 110-220 ms
// later MXAccess raises OperationComplete for the same (server, item) handle pair
// with one MXSTATUS_PROXY row: category Ok, detected by RespondingLmx (raw 1),
// detail 0. Every call that does not return Pending raises no OperationComplete:
// Suspend/Activate on an advised but unresolved reference (synchronous Ok), Activate
// on an already-active item and a second Suspend on a suspended item (both
// synchronous Ok), and an added-but-unadvised item (E_INVALIDARG). Plain and
// supervisory advises behave the same. Writes never raise it: their outcome is
// OnWriteComplete only. Recorded in docs/LiveCaptures-2026-11-13.md.
//
// The probe suspends and re-activates one item on its own registration. It never
// writes. Runs only when MXGATEWAY_RUN_LIVE_MXACCESS_TESTS=1. The item defaults to
// TestMachine_001.TestChangingInt; override with MXGATEWAY_LIVE_OPERATION_COMPLETE_ITEM.
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Threading;
using ArchestrA.MxAccess;
using MxStatusCategory = ZB.MOM.WW.MxGateway.Contracts.Proto.MxStatusCategory;
using MxStatusProxy = ZB.MOM.WW.MxGateway.Contracts.Proto.MxStatusProxy;
using MxStatusSource = ZB.MOM.WW.MxGateway.Contracts.Proto.MxStatusSource;
using ZB.MOM.WW.MxGateway.Worker.Conversion;
using ZB.MOM.WW.MxGateway.Worker.Tests.TestSupport;
using Xunit.Abstractions;
namespace ZB.MOM.WW.MxGateway.Worker.Tests.Probes;
/// <summary>
/// Live probe that pins the native trigger of the MXAccess <c>OperationComplete</c>
/// event: a Suspend or Activate whose synchronous status is Pending.
/// </summary>
public sealed class OperationCompleteLiveProbeTests
{
private static readonly TimeSpan LiveProbeTimeout = TimeSpan.FromMinutes(3);
private static readonly TimeSpan EventWait = TimeSpan.FromSeconds(5);
private readonly ITestOutputHelper output;
private readonly ConcurrentQueue<string> log = new ConcurrentQueue<string>();
/// <summary>Initializes a new instance of the OperationCompleteLiveProbeTests class.</summary>
/// <param name="output">Test output helper for logging.</param>
public OperationCompleteLiveProbeTests(ITestOutputHelper output)
{
this.output = output;
}
/// <summary>
/// Suspend then Activate an advised, resolved item: each returns Pending and is
/// followed by one OperationComplete (Ok, RespondingLmx) for that item. Suspend on
/// an unresolved reference returns Ok and raises nothing (negative control).
/// </summary>
[LiveMxAccessFact]
public void LiveSuspendActivate_PendingStatus_IsFollowedByOperationComplete()
{
Exception? threadException = null;
ManualResetEventSlim done = new ManualResetEventSlim(false);
Thread thread = new Thread(() =>
{
try { Run(); }
catch (Exception ex) { threadException = ex; }
finally { done.Set(); }
});
thread.IsBackground = true;
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
Assert.True(done.Wait(LiveProbeTimeout), "Live probe thread did not finish within " + LiveProbeTimeout + ".");
thread.Join();
string? line;
while (log.TryDequeue(out line))
{
output.WriteLine(line);
}
if (threadException != null)
{
throw threadException;
}
}
private void Run()
{
string? item = Environment.GetEnvironmentVariable("MXGATEWAY_LIVE_OPERATION_COMPLETE_ITEM");
if (string.IsNullOrWhiteSpace(item))
{
item = "TestMachine_001.TestChangingInt";
}
MxStatusProxyConverter converter = new MxStatusProxyConverter();
List<Tuple<int, int, IReadOnlyList<MxStatusProxy>>> completions = new List<Tuple<int, int, IReadOnlyList<MxStatusProxy>>>();
LMXProxyServerClass com = new LMXProxyServerClass();
com.OperationComplete += (int hServer, int hItem, ref MXSTATUS_PROXY[] statuses) =>
{
IReadOnlyList<MxStatusProxy> rows = converter.ConvertMany(statuses);
completions.Add(Tuple.Create(hServer, hItem, rows));
Log(string.Format("OperationComplete hServer={0} hItem={1} rows=[{2}]", hServer, hItem, Describe(rows)));
};
int serverHandle = com.Register("mxgw-operation-complete-probe");
try
{
int resolved = com.AddItem(serverHandle, item);
com.Advise(serverHandle, resolved);
int unresolved = com.AddItem(serverHandle, "TestMachine_001.NoSuchAttribute_OperationCompleteProbe");
com.Advise(serverHandle, unresolved);
PumpFor(TimeSpan.FromSeconds(3));
ExpectPendingThenCompletion("Suspend", serverHandle, resolved, completions, converter,
() => { ((ILMXProxyServer4)com).Suspend(serverHandle, resolved, out MxStatus s); return s; });
ExpectPendingThenCompletion("Activate", serverHandle, resolved, completions, converter,
() => { ((ILMXProxyServer4)com).Activate(serverHandle, resolved, out MxStatus s); return s; });
// Negative control: an unresolved reference completes synchronously and raises nothing.
completions.Clear();
((ILMXProxyServer4)com).Suspend(serverHandle, unresolved, out MxStatus unresolvedStatus);
MxStatusProxy unresolvedRow = converter.Convert(unresolvedStatus);
Log("Suspend(unresolved) -> " + Describe(new[] { unresolvedRow }));
Assert.Equal(MxStatusCategory.Ok, unresolvedRow.Category);
PumpFor(EventWait);
Assert.Empty(completions);
((ILMXProxyServer4)com).Activate(serverHandle, unresolved, out MxStatus _);
}
finally
{
try { com.Unregister(serverHandle); }
catch (COMException ex) { Log("Unregister failed: 0x" + ex.HResult.ToString("X8")); }
}
}
private void ExpectPendingThenCompletion(
string verb,
int serverHandle,
int itemHandle,
List<Tuple<int, int, IReadOnlyList<MxStatusProxy>>> completions,
MxStatusProxyConverter converter,
Func<MxStatus> call)
{
completions.Clear();
MxStatusProxy sync = converter.Convert(call());
Log(string.Format("{0} -> {1}", verb, Describe(new[] { sync })));
Assert.Equal(MxStatusCategory.Pending, sync.Category);
Assert.Equal(1, sync.RawCategory);
Assert.Equal(0, sync.Detail);
DateTime deadline = DateTime.UtcNow + EventWait;
while (completions.Count == 0 && DateTime.UtcNow < deadline)
{
PumpFor(TimeSpan.FromMilliseconds(100));
}
Assert.True(completions.Count == 1, verb + " must be followed by exactly one OperationComplete, saw " + completions.Count + ".");
Tuple<int, int, IReadOnlyList<MxStatusProxy>> completion = completions[0];
Assert.Equal(serverHandle, completion.Item1);
Assert.Equal(itemHandle, completion.Item2);
Assert.Single(completion.Item3);
Assert.Equal(MxStatusCategory.Ok, completion.Item3[0].Category);
Assert.Equal(MxStatusSource.RespondingLmx, completion.Item3[0].DetectedBy);
}
private static string Describe(IEnumerable<MxStatusProxy> rows)
{
List<string> parts = new List<string>();
foreach (MxStatusProxy r in rows)
{
parts.Add(string.Format(
"success={0} category={1} rawCategory={2} detectedBy={3} rawDetectedBy={4} detail={5}",
r.Success, r.Category, r.RawCategory, r.DetectedBy, r.RawDetectedBy, r.Detail));
}
return string.Join("; ", parts);
}
private void Log(string line)
{
log.Enqueue(string.Format("{0:HH:mm:ss.fff} {1}", DateTime.UtcNow, line));
}
private static void PumpFor(TimeSpan duration)
{
DateTime deadline = DateTime.UtcNow + duration;
while (DateTime.UtcNow < deadline)
{
NativeMethods.MSG msg;
while (NativeMethods.PeekMessage(out msg, IntPtr.Zero, 0, 0, NativeMethods.PM_REMOVE))
{
NativeMethods.TranslateMessage(ref msg);
NativeMethods.DispatchMessage(ref msg);
}
Thread.Sleep(20);
}
}
private static class NativeMethods
{
internal const uint PM_REMOVE = 0x0001;
[StructLayout(LayoutKind.Sequential)]
internal struct MSG
{
internal IntPtr hwnd;
internal uint message;
internal IntPtr wParam;
internal IntPtr lParam;
internal uint time;
internal int ptX;
internal int ptY;
}
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool PeekMessage(out MSG lpMsg, IntPtr hWnd, uint wMsgFilterMin, uint wMsgFilterMax, uint wRemoveMsg);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool TranslateMessage(ref MSG lpMsg);
[DllImport("user32.dll")]
internal static extern IntPtr DispatchMessage(ref MSG lpmsg);
}
}