test: migrate SDK 2.0 wire contracts and pin baseline aggregate vectors

This commit is contained in:
Joseph Doherty
2026-11-10 10:44:23 -05:00
parent 6aaccb332f
commit aac7c88417
29 changed files with 4695 additions and 362 deletions
@@ -53,21 +53,21 @@ public sealed class HistoryUpdateOverTheWireTests
var node = RawNode(session, id);
var insert = await UpdateAsync(session, node, PerformUpdateType.Insert, ct, (T1, 1.5), (T2, 2.5));
insert.StatusCode.Code.ShouldBe(StatusCodes.Good);
insert.OperationResults.Select(c => c.Code).ShouldBe([StatusCodes.GoodEntryInserted, StatusCodes.GoodEntryInserted]);
insert.StatusCode.Code.ShouldBe(StatusCodes.Good.Code);
insert.OperationResults.ToList().Select(c => c.Code).ShouldBe([StatusCodes.GoodEntryInserted.Code, StatusCodes.GoodEntryInserted.Code]);
var read = await ReadRawAsync(session, node, ct);
read.Select(v => (v.SourceTimestamp, (double)v.Value)).ShouldBe([(T1, 1.5), (T2, 2.5)]);
read.Select(v => (v.SourceTimestamp, (double)v.ClrValue()!)).ShouldBe([(T1, 1.5), (T2, 2.5)]);
var dup = await UpdateAsync(session, node, PerformUpdateType.Insert, ct, (T1, 9.9));
dup.OperationResults.Select(c => c.Code).ShouldBe([StatusCodes.BadEntryExists]);
dup.OperationResults.ToList().Select(c => c.Code).ShouldBe([StatusCodes.BadEntryExists.Code]);
(await ReadRawAsync(session, node, ct)).Count.ShouldBe(2, "the refused insert changed nothing");
var del = await DeleteAtTimeAsync(session, node, ct, T1);
del.OperationResults.Select(c => c.Code).ShouldBe([StatusCodes.Good]);
del.OperationResults.ToList().Select(c => c.Code).ShouldBe([StatusCodes.Good.Code]);
var after = await ReadRawAsync(session, node, ct);
after.Select(v => (v.SourceTimestamp, (double)v.Value)).ShouldBe([(T2, 2.5)]);
after.Select(v => (v.SourceTimestamp, (double)v.ClrValue()!)).ShouldBe([(T2, 2.5)]);
}
finally { await rig.DisposeAsync(); }
}
@@ -102,17 +102,17 @@ public sealed class HistoryUpdateOverTheWireTests
};
var response = await session.HistoryReadAsync(
null, new ExtensionObject(details), TimestampsToReturn.Both, false,
new HistoryReadValueIdCollection { new HistoryReadValueId { NodeId = node } }, ct);
var result = response.Results.ShouldHaveSingleItem();
result.StatusCode.Code.ShouldBe(StatusCodes.Good);
new HistoryReadValueId[] { new HistoryReadValueId { NodeId = node } }, ct);
var result = response.Results.ToList().ShouldHaveSingleItem();
result.StatusCode.Code.ShouldBe(StatusCodes.Good.Code);
var data = ExtensionObject.ToEncodeable(result.HistoryData).ShouldBeOfType<HistoryModifiedData>();
data.DataValues.Select(v => v.SourceTimestamp).ShouldBe([T1, T1, T2]);
data.ModificationInfos.Select(m => m.UpdateType)
data.DataValues.ToList().Select(v => v.SourceTimestamp).ShouldBe([T1, T1, T2]);
data.ModificationInfos.ToList().Select(m => m.UpdateType)
.ShouldBe([HistoryUpdateType.Insert, HistoryUpdateType.Delete, HistoryUpdateType.Insert]);
data.ModificationInfos.ShouldAllBe(m => m.UserName == KeyPrincipal);
data.DataValues[0].StatusCode.Code.ShouldBe(StatusCodes.BadNoData); // an insert had no prior value
((double)data.DataValues[1].Value).ShouldBe(1.5); // the deleted sample's prior value
data.ModificationInfos.ToList().ShouldAllBe(m => m.UserName == KeyPrincipal);
data.DataValues[0].StatusCode.Code.ShouldBe(StatusCodes.BadNoData.Code); // an insert had no prior value
((double)data.DataValues[1].ClrValue()!).ShouldBe(1.5); // the deleted sample's prior value
}
finally { await rig.DisposeAsync(); }
}
@@ -139,13 +139,13 @@ public sealed class HistoryUpdateOverTheWireTests
using var denied = await rig.ConnectAsync(anonymous: true, ct);
var denial = await UpdateAsync(denied, RawNode(denied, id), PerformUpdateType.Insert, ct, (T1, 1.0));
denial.StatusCode.Code.ShouldBe(StatusCodes.BadUserAccessDenied);
denial.StatusCode.Code.ShouldBe(StatusCodes.BadUserAccessDenied.Code);
store.UpdateCalls.ShouldBe(0, "a denied session never reaches the updater");
store.Count.ShouldBe(0);
using var allowed = await rig.ConnectAsync(anonymous: false, ct);
var ok = await UpdateAsync(allowed, RawNode(allowed, id), PerformUpdateType.Insert, ct, (T1, 1.0));
ok.OperationResults.Select(c => c.Code).ShouldBe([StatusCodes.GoodEntryInserted]);
ok.OperationResults.ToList().Select(c => c.Code).ShouldBe([StatusCodes.GoodEntryInserted.Code]);
store.UpdateCalls.ShouldBe(1);
}
finally { await rig.DisposeAsync(); }
@@ -177,7 +177,7 @@ public sealed class HistoryUpdateOverTheWireTests
using (var writer = await rig.ConnectAsync(anonymous: false, ct))
{
var denial = await UpdateAsync(writer, RawNode(writer, id), PerformUpdateType.Insert, ct, (T1, 1.0));
denial.StatusCode.Code.ShouldBe(StatusCodes.BadUserAccessDenied);
denial.StatusCode.Code.ShouldBe(StatusCodes.BadUserAccessDenied.Code);
}
store.UpdateCalls.ShouldBe(0, "a denied session never reaches the updater");
@@ -186,7 +186,7 @@ public sealed class HistoryUpdateOverTheWireTests
rig.KeyRoles = ApiKeyInterimRoleMapper.Map([editor], KeyPrincipal);
using var allowed = await rig.ConnectAsync(anonymous: false, ct);
var ok = await UpdateAsync(allowed, RawNode(allowed, id), PerformUpdateType.Insert, ct, (T1, 1.0));
ok.OperationResults.Select(c => c.Code).ShouldBe([StatusCodes.GoodEntryInserted]);
ok.OperationResults.ToList().Select(c => c.Code).ShouldBe([StatusCodes.GoodEntryInserted.Code]);
store.UpdateCalls.ShouldBe(1);
}
finally { await rig.DisposeAsync(); }
@@ -241,7 +241,7 @@ public sealed class HistoryUpdateOverTheWireTests
(await ReadByteAsync(session, node, Attributes.AccessLevel, ct) & AccessLevels.HistoryWrite)
.ShouldBe(AccessLevels.HistoryWrite, "a late updater lights the bit on the existing node");
var ok = await UpdateAsync(session, node, PerformUpdateType.Insert, ct, (T1, 1.0));
ok.OperationResults.Select(c => c.Code).ShouldBe([StatusCodes.GoodEntryInserted]);
ok.OperationResults.ToList().Select(c => c.Code).ShouldBe([StatusCodes.GoodEntryInserted.Code]);
store.UpdateCalls.ShouldBe(1);
rig.Nm.HistorianDataUpdater = null;
@@ -249,7 +249,7 @@ public sealed class HistoryUpdateOverTheWireTests
(await ReadByteAsync(session, node, Attributes.AccessLevel, ct) & AccessLevels.HistoryWrite)
.ShouldBe(0, "a reset updater takes the bit back");
var refused = await UpdateAsync(session, node, PerformUpdateType.Insert, ct, (T2, 2.0));
refused.StatusCode.Code.ShouldBe(StatusCodes.BadHistoryOperationUnsupported);
refused.StatusCode.Code.ShouldBe(StatusCodes.BadHistoryOperationUnsupported.Code);
store.UpdateCalls.ShouldBe(1, "the reset updater is never reached");
}
finally { await rig.DisposeAsync(); }
@@ -262,11 +262,11 @@ public sealed class HistoryUpdateOverTheWireTests
private static async Task<byte> ReadByteAsync(ISession session, NodeId node, uint attribute, CancellationToken ct)
{
var response = await session.ReadAsync(null, 0, TimestampsToReturn.Neither, new ReadValueIdCollection
var response = await session.ReadAsync(null, 0, TimestampsToReturn.Neither, new ReadValueId[]
{
new ReadValueId { NodeId = node, AttributeId = attribute },
}, ct);
return (byte)response.Results.ShouldHaveSingleItem().Value;
return (byte)response.Results.ToList().ShouldHaveSingleItem().ClrValue()!;
}
private static async Task<HistoryUpdateResult> UpdateAsync(
@@ -275,7 +275,7 @@ public sealed class HistoryUpdateOverTheWireTests
{
var details = new UpdateDataDetails { NodeId = node, PerformInsertReplace = mode };
foreach (var (time, value) in items)
details.UpdateValues.Add(new DataValue(new Variant(value), StatusCodes.Good, time, time));
details.UpdateValues += new DataValue(Variant.From(value), StatusCodes.Good, time, time);
return await SendAsync(session, details, ct);
}
@@ -283,15 +283,15 @@ public sealed class HistoryUpdateOverTheWireTests
ISession session, NodeId node, CancellationToken ct, params DateTime[] times)
{
var details = new DeleteAtTimeDetails { NodeId = node };
foreach (var t in times) details.ReqTimes.Add(t);
foreach (var t in times) details.ReqTimes += (DateTimeUtc)t;
return SendAsync(session, details, ct);
}
private static async Task<HistoryUpdateResult> SendAsync(ISession session, object details, CancellationToken ct)
private static async Task<HistoryUpdateResult> SendAsync(ISession session, IEncodeable details, CancellationToken ct)
{
var response = await session.HistoryUpdateAsync(
null, new ExtensionObjectCollection { new ExtensionObject(details) }, ct);
return response.Results.ShouldHaveSingleItem();
null, new ExtensionObject[] { new ExtensionObject(details) }, ct);
return response.Results.ToList().ShouldHaveSingleItem();
}
private static async Task<List<DataValue>> ReadRawAsync(ISession session, NodeId node, CancellationToken ct)
@@ -306,10 +306,10 @@ public sealed class HistoryUpdateOverTheWireTests
};
var response = await session.HistoryReadAsync(
null, new ExtensionObject(details), TimestampsToReturn.Source, false,
new HistoryReadValueIdCollection { new HistoryReadValueId { NodeId = node } }, ct);
var result = response.Results.ShouldHaveSingleItem();
new HistoryReadValueId[] { new HistoryReadValueId { NodeId = node } }, ct);
var result = response.Results.ToList().ShouldHaveSingleItem();
StatusCode.IsBad(result.StatusCode).ShouldBeFalse($"HistoryRead failed: {result.StatusCode}");
var data = (HistoryData)ExtensionObject.ToEncodeable(result.HistoryData);
var data = ExtensionObject.ToEncodeable(result.HistoryData).ShouldBeOfType<HistoryData>();
return data.DataValues.ToList();
}
@@ -326,7 +326,7 @@ public sealed class HistoryUpdateOverTheWireTests
private void Record(DateTime t, double? prior, HistoryModificationType type, HistoryUpdateContext who) =>
_trail.Add(new HistoryModifiedValue(
new DataValueSnapshot(prior, prior is null ? StatusCodes.BadNoData : StatusCodes.Good, t, t),
new DataValueSnapshot(prior, prior is null ? StatusCodes.BadNoData.Code : StatusCodes.Good.Code, t, t),
DateTime.UtcNow, type, who.Principal, _trail.Count + 1, t));
public int UpdateCalls => Volatile.Read(ref _updateCalls);
@@ -347,11 +347,11 @@ public sealed class HistoryUpdateOverTheWireTests
foreach (var v in values)
{
var t = v.TimestampUtc!.Value;
if (_samples.ContainsKey(t)) { codes.Add(StatusCodes.BadEntryExists); continue; }
if (_samples.ContainsKey(t)) { codes.Add(StatusCodes.BadEntryExists.Code); continue; }
v.Value.TryGetDouble(out var d).ShouldBeTrue();
_samples[t] = d;
Record(t, null, HistoryModificationType.Insert, context);
codes.Add(StatusCodes.GoodEntryInserted);
codes.Add(StatusCodes.GoodEntryInserted.Code);
}
}
return codes;
@@ -368,9 +368,9 @@ public sealed class HistoryUpdateOverTheWireTests
lock (_gate)
return timesUtc.Select(t =>
{
if (!_samples.Remove(t, out var prior)) return StatusCodes.BadNoEntryExists;
if (!_samples.Remove(t, out var prior)) return StatusCodes.BadNoEntryExists.Code;
Record(t, prior, HistoryModificationType.Delete, context);
return StatusCodes.Good;
return StatusCodes.Good.Code;
}).ToList();
}
@@ -397,7 +397,7 @@ public sealed class HistoryUpdateOverTheWireTests
lock (_gate)
{
var rows = _samples.Where(kv => kv.Key >= startUtc && kv.Key <= endUtc)
.Select(kv => new DataValueSnapshot(kv.Value, StatusCodes.Good, kv.Key, kv.Key)).ToList();
.Select(kv => new DataValueSnapshot(kv.Value, StatusCodes.Good.Code, kv.Key, kv.Key)).ToList();
return new CoreHistoryReadResult(rows, null);
}
}