fix(commons): flow fold ranks lifecycle before time, schema required/legacy-type checks, CSV trailing comma, case-insensitive audit enum parse (CMN-6,7,8,9,12, WP7 task 7.5)
This commit is contained in:
@@ -655,6 +655,27 @@ public class FlowGraphBuilderTests
|
||||
Assert.Equal(sa.Lifecycle!.Select(r => r.Kind), sb.Lifecycle!.Select(r => r.Kind));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// CMN-6: the resolve row is written centrally and the submit row at the site; with the site clock
|
||||
/// ahead, the submit row's timestamp is LATER than the delivery's. The fold must still treat the
|
||||
/// resolve as terminal, not render the completed operation as Pending.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Fold_WithCrossNodeClockSkew_StillTreatsResolveAsTerminal()
|
||||
{
|
||||
var corr = Guid.NewGuid();
|
||||
var submit = Outbound(AuditChannel.ApiOutbound, AuditKind.CachedSubmit, AuditStatus.Submitted, 2000, corr, "Delmia.Ack", node: "node-a", request: "req");
|
||||
var resolve = Outbound(AuditChannel.ApiOutbound, AuditKind.CachedResolve, AuditStatus.Delivered, 1000, corr, "Delmia.Ack", node: "central-a", response: "res");
|
||||
|
||||
var graph = FlowGraphBuilder.Build([SiteRunRow(20), submit, resolve]);
|
||||
|
||||
var step = Assert.Single(graph.Steps, s => s.Kind == FlowStepKind.ApiCall);
|
||||
Assert.Equal(FlowStepOutcome.Ok, step.Outcome);
|
||||
Assert.Equal("res", step.OutputJson);
|
||||
Assert.Equal(["CachedSubmit", "CachedResolve"], step.Lifecycle!.Select(r => r.Kind));
|
||||
Assert.True(step.DurationMs >= 0);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that a cached step whose submit row is missing is still treated as asynchronous.</summary>
|
||||
[Fact]
|
||||
public void CachedStep_WhoseSubmitRowIsMissing_IsStillAsync()
|
||||
|
||||
@@ -197,4 +197,16 @@ public class NativeAlarmSourceOverrideCsvParserTests
|
||||
Assert.Empty(result.Rows);
|
||||
Assert.Contains(result.Errors, e => e.Contains("Line 2") && e.Contains("MesReportable"));
|
||||
}
|
||||
|
||||
/// <summary>Verifies that one trailing delimiter on every row (a spreadsheet export) is tolerated, header included.</summary>
|
||||
[Fact]
|
||||
public void Parse_TrailingCommaOnEveryRow_IsTolerated()
|
||||
{
|
||||
const string csv = "SourceName,Connection,SourceReference,Filter,\nPressure,OPC,ns=2;s=P,Active,\n";
|
||||
|
||||
var result = NativeAlarmSourceOverrideCsvParser.Parse(csv);
|
||||
|
||||
Assert.Empty(result.Errors);
|
||||
Assert.Equal("Pressure", Assert.Single(result.Rows).SourceName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,4 +262,39 @@ public class OverrideCsvParserTests
|
||||
Assert.Equal("a,b", row.Value);
|
||||
Assert.Equal("Type", row.ElementType);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that one trailing delimiter on every row (a spreadsheet export) is tolerated, header included.</summary>
|
||||
[Fact]
|
||||
public void Parse_TrailingCommaOnEveryRow_IsTolerated()
|
||||
{
|
||||
const string csv = "AttributeName,Value,ElementType,\nSetpoint,42,Int32,\nName,Pump A,,\n";
|
||||
|
||||
var result = OverrideCsvParser.Parse(csv);
|
||||
|
||||
Assert.Empty(result.Errors);
|
||||
Assert.Equal(2, result.Rows.Count);
|
||||
Assert.Equal("Int32", result.Rows[0].ElementType);
|
||||
Assert.Null(result.Rows[1].ElementType);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that a two-column file with a trailing comma is tolerated.</summary>
|
||||
[Fact]
|
||||
public void Parse_TwoColumnWithTrailingComma_IsTolerated()
|
||||
{
|
||||
var result = OverrideCsvParser.Parse("AttributeName,Value,\nSetpoint,42,\n");
|
||||
|
||||
Assert.Empty(result.Errors);
|
||||
Assert.Equal("42", Assert.Single(result.Rows).Value);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that a genuinely wrong column count, or a NON-empty extra column, stays an error.</summary>
|
||||
[Fact]
|
||||
public void Parse_ExtraNonEmptyColumn_StillAnError()
|
||||
{
|
||||
var result = OverrideCsvParser.Parse("AttributeName,Value\nSetpoint,42,extra\nA,1,,\n");
|
||||
|
||||
Assert.Empty(result.Rows);
|
||||
Assert.Equal(2, result.Errors.Count);
|
||||
Assert.All(result.Errors, e => Assert.Contains("expected 2 columns", e));
|
||||
}
|
||||
}
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Audit;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.Commons.Tests.Types.Audit;
|
||||
|
||||
/// <summary>Review CMN-12: stored enum tokens parse case-insensitively, like the query parsers.</summary>
|
||||
public class AuditRowProjectionParseEnumTests
|
||||
{
|
||||
/// <summary>A mis-cased stored token resolves to its member rather than the fallback.</summary>
|
||||
/// <param name="stored">The stored token.</param>
|
||||
[Theory]
|
||||
[InlineData("DbOutbound")]
|
||||
[InlineData("dboutbound")]
|
||||
[InlineData("DBOUTBOUND")]
|
||||
public void ParseEnum_IsCaseInsensitive(string stored)
|
||||
=> Assert.Equal(AuditChannel.DbOutbound, AuditRowProjection.ParseEnum(stored, AuditChannel.ApiInbound));
|
||||
|
||||
/// <summary>Unknown or empty tokens still fall back.</summary>
|
||||
/// <param name="stored">The stored token.</param>
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
[InlineData("NoSuchChannel")]
|
||||
public void ParseEnum_UnknownFallsBack(string? stored)
|
||||
=> Assert.Equal(AuditChannel.ApiInbound, AuditRowProjection.ParseEnum(stored, AuditChannel.ApiInbound));
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
using System.Text.Json;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.InboundApi;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.Commons.Tests.Types.InboundApi;
|
||||
|
||||
/// <summary>Review CMN-7 (required matching) and CMN-8 (unknown legacy types).</summary>
|
||||
public class InboundApiSchemaWp7Tests
|
||||
{
|
||||
/// <summary>A "required" entry spelled with different casing than the property still makes it required.</summary>
|
||||
[Fact]
|
||||
public void Required_MatchesPropertyNamesCaseInsensitively()
|
||||
{
|
||||
const string json = """{"type":"object","properties":{"WorkOrders":{"type":"string"},"Other":{"type":"string"}},"required":["workorders"]}""";
|
||||
|
||||
var schema = InboundApiSchema.Parse(json)!;
|
||||
|
||||
Assert.True(schema.Fields.Single(f => f.Name == "WorkOrders").Required);
|
||||
Assert.False(schema.Fields.Single(f => f.Name == "Other").Required);
|
||||
}
|
||||
|
||||
/// <summary>A typo'd legacy type is a parse error naming the field and the valid vocabulary.</summary>
|
||||
/// <param name="legacy">The legacy parameter array.</param>
|
||||
[Theory]
|
||||
[InlineData("""[{"name":"Qty","type":"strign"}]""")]
|
||||
[InlineData("""[{"name":"Items","type":"List","itemType":"intger"}]""")]
|
||||
public void LegacyArray_UnknownType_ThrowsClearError(string legacy)
|
||||
{
|
||||
var ex = Assert.Throws<JsonException>(() => InboundApiSchema.Parse(legacy));
|
||||
|
||||
Assert.Contains("unknown", ex.Message);
|
||||
Assert.Contains("Valid types", ex.Message);
|
||||
}
|
||||
|
||||
/// <summary>Every legacy alias still parses.</summary>
|
||||
[Fact]
|
||||
public void LegacyArray_KnownAliases_StillParse()
|
||||
{
|
||||
const string legacy = """[{"name":"a","type":"Integer"},{"name":"b","type":"Float"},{"name":"c","type":"DateTime"},{"name":"d","type":"List","itemType":"String"},{"name":"e","type":"Object"},{"name":"f","type":"Boolean"},{"name":"g"}]""";
|
||||
|
||||
var schema = InboundApiSchema.Parse(legacy)!;
|
||||
|
||||
Assert.Equal(7, schema.Fields.Count);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user