test(overrides): case-variant override names verified end to end through the flattener; UI single path gets the hint (ScadaBridge#105)
Re-verified #105 item 2 on the real write paths: ManagementActor bulk attribute overrides (CLI set-overrides / management API) and InstanceService.SetAttributeOverrideAsync (Central UI single editor) both match the template member ordinally and refuse a case-variant name, so nothing is stored for the flattener to drop. Native-source overrides already validate against the flattener's own output. - New theory tests drive each path, feed whatever it stored into the real FlatteningService, and assert every stored override is applied (exact-case row is the positive control). Mutation: accepting case variants (OrdinalIgnoreCase) fails them with "stored ... but the flattener dropped it as unresolved". - The did-you-mean hint moves to TemplateEngine.OverrideNameMatching and is now also on the UI single-attribute path; ambiguous matches get no hint. Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
This commit is contained in:
@@ -2831,6 +2831,66 @@ public class ManagementActorTests : TestKit, IDisposable
|
||||
_templateRepo.DidNotReceiveWithAnyArgs().AddInstanceAttributeOverrideAsync(default!, default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ScadaBridge#105, end to end: drive the real ManagementActor bulk attribute override
|
||||
/// path (the CLI <c>instance set-overrides</c> / management API path), capture whatever it
|
||||
/// stores, and run the stored overrides through the real <see cref="ZB.MOM.WW.ScadaBridge.TemplateEngine.Flattening.FlatteningService"/>.
|
||||
/// Invariant: every override the management path accepts is applied by the flattener —
|
||||
/// none is stored and then silently dropped as unresolved. The exact-case row is the
|
||||
/// positive control (stored AND applied); the case-variant rows must be refused.
|
||||
/// </summary>
|
||||
[Theory]
|
||||
[InlineData("Setpoint", true)]
|
||||
[InlineData("setpoint", false)]
|
||||
[InlineData("SETPOINT", false)]
|
||||
public void SetInstanceOverrides_EveryStoredOverride_IsAppliedByTheFlattener(string requestedName, bool accepted)
|
||||
{
|
||||
var template = new Template("PumpTemplate") { Id = 1 };
|
||||
template.Attributes.Add(new TemplateAttribute("Setpoint") { Id = 1, TemplateId = 1, DataType = DataType.Double, Value = "0" });
|
||||
var instance = new Instance("Pump6") { Id = 6, SiteId = 1, TemplateId = 1 };
|
||||
_templateRepo.GetInstanceByIdAsync(6, Arg.Any<CancellationToken>()).Returns(instance);
|
||||
_templateRepo.GetAttributesByTemplateIdAsync(1, Arg.Any<CancellationToken>())
|
||||
.Returns(template.Attributes.ToList());
|
||||
_templateRepo.GetOverridesByInstanceIdAsync(6, Arg.Any<CancellationToken>())
|
||||
.Returns(new List<Commons.Entities.Instances.InstanceAttributeOverride>());
|
||||
var stored = new List<Commons.Entities.Instances.InstanceAttributeOverride>();
|
||||
_templateRepo
|
||||
.When(r => r.AddInstanceAttributeOverrideAsync(Arg.Any<Commons.Entities.Instances.InstanceAttributeOverride>(), Arg.Any<CancellationToken>()))
|
||||
.Do(ci => stored.Add(ci.Arg<Commons.Entities.Instances.InstanceAttributeOverride>()));
|
||||
|
||||
var actor = CreateActor();
|
||||
actor.Tell(Envelope(new SetInstanceOverridesCommand(6, new Dictionary<string, string?> { [requestedName] = "42" }), "Deployer"));
|
||||
var response = ExpectMsg<object>(TimeSpan.FromSeconds(5));
|
||||
|
||||
// Feed what the management path persisted into the real flattener.
|
||||
foreach (var o in stored) instance.AttributeOverrides.Add(o);
|
||||
var flattened = new ZB.MOM.WW.ScadaBridge.TemplateEngine.Flattening.FlatteningService().Flatten(
|
||||
instance, [template],
|
||||
new Dictionary<int, IReadOnlyList<TemplateComposition>>(),
|
||||
new Dictionary<int, IReadOnlyList<Template>>(),
|
||||
new Dictionary<int, DataConnection>());
|
||||
Assert.True(flattened.IsSuccess, flattened.IsFailure ? flattened.Error : null);
|
||||
foreach (var o in stored)
|
||||
Assert.True(
|
||||
flattened.Value.Attributes.Any(a => a.CanonicalName == o.AttributeName && a.Source == "Override"),
|
||||
$"Override '{o.AttributeName}' was stored by the management path but the flattener dropped it as unresolved.");
|
||||
|
||||
var setpoint = Assert.Single(flattened.Value.Attributes, a => a.CanonicalName == "Setpoint");
|
||||
if (accepted)
|
||||
{
|
||||
Assert.IsType<ManagementSuccess>(response);
|
||||
Assert.Equal("42", setpoint.Value);
|
||||
Assert.Equal("Override", setpoint.Source);
|
||||
}
|
||||
else
|
||||
{
|
||||
var error = Assert.IsType<ManagementError>(response);
|
||||
Assert.Contains("did you mean 'Setpoint'", error.Error);
|
||||
Assert.Empty(stored);
|
||||
Assert.Equal("0", setpoint.Value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>ScadaBridge#105: a bulk native-source override differing only by case is rejected, nothing stored.</summary>
|
||||
[Fact]
|
||||
public void SetInstanceNativeAlarmSourceOverrides_CaseVariantName_IsRejectedWithHint()
|
||||
|
||||
Reference in New Issue
Block a user