Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Implement M6a contract-level validation execution

Yuechen Lib55a27e5c8a2
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs
index b86c6b10..fe92f74d 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs
@@ -118,7 +118,7 @@ public sealed class FirmamentPrimitiveExecutionTests
Assert.True(result.Compilation.IsSuccess);
var artifact = result.Compilation.Value;
- Assert.Equal("firmament-m5b-selector-contract-metadata-validated-primitives-and-booleans-executed", artifact.ArtifactKind);
+ Assert.Equal("firmament-contract-validations-executed", artifact.ArtifactKind);
Assert.Equal(2, artifact.PrimitiveLoweringPlan!.Primitives.Count);
Assert.Equal(2, artifact.PrimitiveLoweringPlan.Booleans.Count);
Assert.Single(artifact.PrimitiveLoweringPlan.SkippedOps);
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentScaffoldTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentScaffoldTests.cs
index 59692767..485347de 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentScaffoldTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentScaffoldTests.cs
@@ -37,7 +37,7 @@ public sealed class FirmamentScaffoldTests
Assert.True(result.Compilation.IsSuccess);
var artifact = result.Compilation.Value;
- Assert.Equal("firmament-m5b-selector-contract-metadata-validated-primitives-and-booleans-executed", artifact.ArtifactKind);
+ Assert.Equal("firmament-contract-validations-executed", artifact.ArtifactKind);
Assert.NotNull(artifact.ParsedDocument);
Assert.Equal("1", artifact.ParsedDocument!.Firmament.Version);
Assert.Equal("demo", artifact.ParsedDocument.Model.Name);
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentValidationExecutionTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentValidationExecutionTests.cs
new file mode 100644
index 00000000..5c8dd357
--- /dev/null
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentValidationExecutionTests.cs
@@ -0,0 +1,163 @@
+using Aetheris.Kernel.Firmament.ParsedModel;
+
+namespace Aetheris.Kernel.Firmament.Tests;
+
+public sealed class FirmamentValidationExecutionTests
+{
+ [Fact]
+ public void Compile_Executes_ExpectExists_For_BareFeatureId_Target()
+ {
+ var result = CompileFixture("testdata/firmament/fixtures/m2c-valid-expect-exists-bare-target-earlier.firmament");
+
+ Assert.True(result.Compilation.IsSuccess);
+ var validation = Assert.Single(result.Compilation.Value.ValidationExecutionResult!.Validations);
+ Assert.Equal(1, validation.OpIndex);
+ Assert.Equal(FirmamentKnownOpKind.ExpectExists, validation.Kind);
+ Assert.Equal("base", validation.Target);
+ Assert.True(validation.IsExecuted);
+ Assert.True(validation.IsSuccess);
+ Assert.Null(validation.Reason);
+ }
+
+ [Fact]
+ public void Compile_Executes_ExpectExists_For_ContractValid_SelectorTarget()
+ {
+ var result = CompileFixture("testdata/firmament/fixtures/m6a-valid-expect-exists-selector-contract-level.firmament");
+
+ Assert.True(result.Compilation.IsSuccess);
+ var validation = Assert.Single(result.Compilation.Value.ValidationExecutionResult!.Validations);
+ Assert.True(validation.IsExecuted);
+ Assert.True(validation.IsSuccess);
+ }
+
+ [Fact]
+ public void Compile_Executes_ExpectSelectable_One_With_Count_One()
+ {
+ var result = CompileFixture("testdata/firmament/fixtures/m6a-valid-expect-selectable-one-count1.firmament");
+
+ Assert.True(result.Compilation.IsSuccess);
+ var validation = Assert.Single(result.Compilation.Value.ValidationExecutionResult!.Validations);
+ Assert.True(validation.IsExecuted);
+ Assert.True(validation.IsSuccess);
+ }
+
+ [Fact]
+ public void Compile_Executes_ExpectSelectable_One_With_Count_Greater_Than_One_As_Failure()
+ {
+ var result = CompileFixture("testdata/firmament/fixtures/m6a-invalid-expect-selectable-one-count2.firmament");
+
+ Assert.True(result.Compilation.IsSuccess);
+ var validation = Assert.Single(result.Compilation.Value.ValidationExecutionResult!.Validations);
+ Assert.True(validation.IsExecuted);
+ Assert.False(validation.IsSuccess);
+ Assert.Contains("incompatible", validation.Reason, StringComparison.Ordinal);
+ }
+
+ [Fact]
+ public void Compile_Executes_ExpectSelectable_Many_With_Plural_Count()
+ {
+ var result = CompileFixture("testdata/firmament/fixtures/m6a-valid-expect-selectable-many-count2.firmament");
+
+ Assert.True(result.Compilation.IsSuccess);
+ var validation = Assert.Single(result.Compilation.Value.ValidationExecutionResult!.Validations);
+ Assert.True(validation.IsExecuted);
+ Assert.True(validation.IsSuccess);
+ }
+
+ [Fact]
+ public void Compile_Records_Unsupported_For_ExpectSelectable_On_BareFeatureId_Target()
+ {
+ var result = CompileFixture("testdata/firmament/fixtures/m6a-unsupported-expect-selectable-bare-target.firmament");
+
+ Assert.True(result.Compilation.IsSuccess);
+ var validation = Assert.Single(result.Compilation.Value.ValidationExecutionResult!.Validations);
+ Assert.False(validation.IsExecuted);
+ Assert.False(validation.IsSuccess);
+ Assert.Contains("does not support bare feature-id", validation.Reason, StringComparison.Ordinal);
+ }
+
+ [Fact]
+ public void Compile_Records_Unsupported_For_ExpectManifold_At_M6a()
+ {
+ var result = CompileFixture("testdata/firmament/fixtures/m6a-unsupported-expect-manifold.firmament");
+
+ Assert.True(result.Compilation.IsSuccess);
+ var validation = Assert.Single(result.Compilation.Value.ValidationExecutionResult!.Validations);
+ Assert.Equal(FirmamentKnownOpKind.ExpectManifold, validation.Kind);
+ Assert.False(validation.IsExecuted);
+ Assert.False(validation.IsSuccess);
+ Assert.Contains("unsupported", validation.Reason, StringComparison.Ordinal);
+ }
+
+ [Fact]
+ public void Compile_Preserves_ValidationExecution_Source_Order_And_OpIndices()
+ {
+ const string source = """
+firmament:
+ version: 1
+
+model:
+ name: demo
+ units: mm
+
+ops[4]:
+ -
+ op: box
+ id: base
+ size[3]:
+ 1
+ 2
+ 3
+ -
+ op: expect_exists
+ target: base
+ -
+ op: expect_selectable
+ target: base.top_face
+ count: 1
+ -
+ op: expect_manifold
+""";
+
+ var result = Compile(source);
+
+ Assert.True(result.Compilation.IsSuccess);
+ var validations = result.Compilation.Value.ValidationExecutionResult!.Validations;
+ Assert.Collection(
+ validations,
+ first =>
+ {
+ Assert.Equal(1, first.OpIndex);
+ Assert.Equal(FirmamentKnownOpKind.ExpectExists, first.Kind);
+ },
+ second =>
+ {
+ Assert.Equal(2, second.OpIndex);
+ Assert.Equal(FirmamentKnownOpKind.ExpectSelectable, second.Kind);
+ },
+ third =>
+ {
+ Assert.Equal(3, third.OpIndex);
+ Assert.Equal(FirmamentKnownOpKind.ExpectManifold, third.Kind);
+ });
+ }
+
+ [Fact]
+ public void Compile_Still_Executes_Primitives_And_Booleans_With_M6a_ValidationExecution_Output()
+ {
+ var result = CompileFixture("testdata/firmament/fixtures/m3d-mixed-primitive-boolean-validation.firmament");
+
+ Assert.True(result.Compilation.IsSuccess);
+ Assert.NotEmpty(result.Compilation.Value.PrimitiveExecutionResult!.ExecutedPrimitives);
+ Assert.NotEmpty(result.Compilation.Value.ValidationExecutionResult!.Validations);
+ }
+
+ private static FirmamentCompileResult CompileFixture(string fixturePath) =>
+ Compile(FirmamentCorpusHarness.ReadFixtureText(fixturePath));
+
+ private static FirmamentCompileResult Compile(string source)
+ {
+ var compiler = new FirmamentCompiler();
+ return compiler.Compile(new FirmamentCompileRequest(new FirmamentSourceDocument(source)));
+ }
+}
diff --git a/Aetheris.Kernel.Firmament/Execution/FirmamentValidationExecutionResult.cs b/Aetheris.Kernel.Firmament/Execution/FirmamentValidationExecutionResult.cs
new file mode 100644
index 00000000..65117d49
--- /dev/null
+++ b/Aetheris.Kernel.Firmament/Execution/FirmamentValidationExecutionResult.cs
@@ -0,0 +1,14 @@
+using Aetheris.Kernel.Firmament.ParsedModel;
+
+namespace Aetheris.Kernel.Firmament.Execution;
+
+public sealed record FirmamentValidationExecutionResult(
+ IReadOnlyList<FirmamentExecutedValidation> Validations);
+
+public sealed record FirmamentExecutedValidation(
+ int OpIndex,
+ FirmamentKnownOpKind Kind,
+ string? Target,
+ bool IsExecuted,
+ bool IsSuccess,
+ string? Reason);
diff --git a/Aetheris.Kernel.Firmament/Execution/FirmamentValidationExecutor.cs b/Aetheris.Kernel.Firmament/Execution/FirmamentValidationExecutor.cs
new file mode 100644
index 00000000..2a48e092
--- /dev/null
+++ b/Aetheris.Kernel.Firmament/Execution/FirmamentValidationExecutor.cs
@@ -0,0 +1,117 @@
+using System.Globalization;
+using Aetheris.Kernel.Core.Results;
+using Aetheris.Kernel.Firmament.ParsedModel;
+using Aetheris.Kernel.Firmament.Validation;
+
+namespace Aetheris.Kernel.Firmament.Execution;
+
+internal static class FirmamentValidationExecutor
+{
+ public static KernelResult<FirmamentValidationExecutionResult> Execute(FirmamentParsedDocument parsedDocument)
+ {
+ ArgumentNullException.ThrowIfNull(parsedDocument);
+
+ var validations = new List<FirmamentExecutedValidation>();
+
+ for (var index = 0; index < parsedDocument.Ops.Entries.Count; index++)
+ {
+ var entry = parsedDocument.Ops.Entries[index];
+ if (entry.Family != FirmamentOpFamily.Validation)
+ {
+ continue;
+ }
+
+ var target = entry.RawFields.TryGetValue("target", out var targetRaw) ? targetRaw : null;
+ var result = entry.KnownKind switch
+ {
+ FirmamentKnownOpKind.ExpectExists => ExecuteExpectExists(index, entry, target),
+ FirmamentKnownOpKind.ExpectSelectable => ExecuteExpectSelectable(index, entry, target),
+ FirmamentKnownOpKind.ExpectManifold => new FirmamentExecutedValidation(
+ OpIndex: index,
+ Kind: entry.KnownKind,
+ Target: target,
+ IsExecuted: false,
+ IsSuccess: false,
+ Reason: "expect_manifold is unsupported at M6a contract-level validation execution."),
+ _ => new FirmamentExecutedValidation(
+ OpIndex: index,
+ Kind: entry.KnownKind,
+ Target: target,
+ IsExecuted: false,
+ IsSuccess: false,
+ Reason: $"Validation op '{entry.OpName}' is not executable.")
+ };
+
+ validations.Add(result);
+ }
+
+ return KernelResult<FirmamentValidationExecutionResult>.Success(
+ new FirmamentValidationExecutionResult(validations));
+ }
+
+ private static FirmamentExecutedValidation ExecuteExpectExists(int opIndex, FirmamentParsedOpEntry entry, string? target)
+ {
+ var isSelectorShaped = entry.ClassifiedFields is not null
+ && entry.ClassifiedFields.TryGetValue("targetShape", out var targetShape)
+ && string.Equals(targetShape, FirmamentValidationTargetShape.SelectorShaped.ToString(), StringComparison.Ordinal);
+
+ var isSuccess = !string.IsNullOrWhiteSpace(target)
+ && (isSelectorShaped || IsFeatureIdTarget(entry));
+
+ return new FirmamentExecutedValidation(
+ OpIndex: opIndex,
+ Kind: entry.KnownKind,
+ Target: target,
+ IsExecuted: true,
+ IsSuccess: isSuccess,
+ Reason: isSuccess ? null : "expect_exists target is not executable at M6a.");
+ }
+
+ private static FirmamentExecutedValidation ExecuteExpectSelectable(int opIndex, FirmamentParsedOpEntry entry, string? target)
+ {
+ if (IsFeatureIdTarget(entry))
+ {
+ return new FirmamentExecutedValidation(
+ OpIndex: opIndex,
+ Kind: entry.KnownKind,
+ Target: target,
+ IsExecuted: false,
+ IsSuccess: false,
+ Reason: "expect_selectable does not support bare feature-id targets at M6a.");
+ }
+
+ if (entry.ClassifiedFields is null
+ || !entry.ClassifiedFields.TryGetValue("selectorCardinality", out var selectorCardinality)
+ || !entry.RawFields.TryGetValue("count", out var countRaw)
+ || !int.TryParse(countRaw, NumberStyles.Integer, CultureInfo.InvariantCulture, out var requestedCount))
+ {
+ return new FirmamentExecutedValidation(
+ OpIndex: opIndex,
+ Kind: entry.KnownKind,
+ Target: target,
+ IsExecuted: true,
+ IsSuccess: false,
+ Reason: "expect_selectable missing executable contract-cardinality inputs.");
+ }
+
+ var isSuccess = string.Equals(selectorCardinality, FirmamentSelectorCardinality.One.ToString(), StringComparison.Ordinal)
+ ? requestedCount == 1
+ : string.Equals(selectorCardinality, FirmamentSelectorCardinality.Many.ToString(), StringComparison.Ordinal)
+ && requestedCount > 1;
+
+ return new FirmamentExecutedValidation(
+ OpIndex: opIndex,
+ Kind: entry.KnownKind,
+ Target: target,
+ IsExecuted: true,
+ IsSuccess: isSuccess,
+ Reason: isSuccess
+ ? null
+ : $"expect_selectable count '{requestedCount}' is incompatible with selector cardinality '{selectorCardinality}' at M6a contract level.");
+ }
+
+ private static bool IsFeatureIdTarget(FirmamentParsedOpEntry entry) =>
+ entry.ClassifiedFields is not null
+ && entry.ClassifiedFields.TryGetValue("targetShape", out var targetShape)
+ && string.Equals(targetShape, FirmamentValidationTargetShape.FeatureId.ToString(), StringComparison.Ordinal);
+}
diff --git a/Aetheris.Kernel.Firmament/FirmamentCompilationArtifact.cs b/Aetheris.Kernel.Firmament/FirmamentCompilationArtifact.cs
index 80d8d3f1..a38914e2 100644
--- a/Aetheris.Kernel.Firmament/FirmamentCompilationArtifact.cs
+++ b/Aetheris.Kernel.Firmament/FirmamentCompilationArtifact.cs
@@ -8,4 +8,5 @@ public sealed record FirmamentCompilationArtifact(
string ArtifactKind = "firmament-m5b-selector-contract-metadata-validated-primitives-and-booleans-executed",
FirmamentParsedDocument? ParsedDocument = null,
FirmamentPrimitiveLoweringPlan? PrimitiveLoweringPlan = null,
- FirmamentPrimitiveExecutionResult? PrimitiveExecutionResult = null);
+ FirmamentPrimitiveExecutionResult? PrimitiveExecutionResult = null,
+ FirmamentValidationExecutionResult? ValidationExecutionResult = null);
diff --git a/Aetheris.Kernel.Firmament/FirmamentCompiler.cs b/Aetheris.Kernel.Firmament/FirmamentCompiler.cs
index b47f5099..35de24d7 100644
--- a/Aetheris.Kernel.Firmament/FirmamentCompiler.cs
+++ b/Aetheris.Kernel.Firmament/FirmamentCompiler.cs
@@ -70,12 +70,20 @@ public sealed class FirmamentCompiler
KernelResult<FirmamentCompilationArtifact>.Failure(primitiveExecutionResult.Diagnostics));
}
+ var validationExecutionResult = FirmamentValidationExecutor.Execute(validatedDocument);
+ if (!validationExecutionResult.IsSuccess)
+ {
+ return new FirmamentCompileResult(
+ KernelResult<FirmamentCompilationArtifact>.Failure(validationExecutionResult.Diagnostics));
+ }
+
return new FirmamentCompileResult(
KernelResult<FirmamentCompilationArtifact>.Success(
new FirmamentCompilationArtifact(
- ArtifactKind: "firmament-m5b-selector-contract-metadata-validated-primitives-and-booleans-executed",
+ ArtifactKind: "firmament-contract-validations-executed",
ParsedDocument: validatedDocument,
PrimitiveLoweringPlan: primitiveLoweringResult.Value,
- PrimitiveExecutionResult: primitiveExecutionResult.Value)));
+ PrimitiveExecutionResult: primitiveExecutionResult.Value,
+ ValidationExecutionResult: validationExecutionResult.Value)));
}
}
diff --git a/testdata/firmament/fixtures/m6a-invalid-expect-selectable-one-count2.firmament b/testdata/firmament/fixtures/m6a-invalid-expect-selectable-one-count2.firmament
new file mode 100644
index 00000000..aa228886
--- /dev/null
+++ b/testdata/firmament/fixtures/m6a-invalid-expect-selectable-one-count2.firmament
@@ -0,0 +1,19 @@
+firmament:
+ version: 1
+
+model:
+ name: demo
+ units: mm
+
+ops[2]:
+ -
+ op: box
+ id: base
+ size[3]:
+ 10
+ 20
+ 30
+ -
+ op: expect_selectable
+ target: base.top_face
+ count: 2
diff --git a/testdata/firmament/fixtures/m6a-unsupported-expect-manifold.firmament b/testdata/firmament/fixtures/m6a-unsupported-expect-manifold.firmament
new file mode 100644
index 00000000..acf55abf
--- /dev/null
+++ b/testdata/firmament/fixtures/m6a-unsupported-expect-manifold.firmament
@@ -0,0 +1,10 @@
+firmament:
+ version: 1
+
+model:
+ name: demo
+ units: mm
+
+ops[1]:
+ -
+ op: expect_manifold
diff --git a/testdata/firmament/fixtures/m6a-unsupported-expect-selectable-bare-target.firmament b/testdata/firmament/fixtures/m6a-unsupported-expect-selectable-bare-target.firmament
new file mode 100644
index 00000000..a14781c4
--- /dev/null
+++ b/testdata/firmament/fixtures/m6a-unsupported-expect-selectable-bare-target.firmament
@@ -0,0 +1,19 @@
+firmament:
+ version: 1
+
+model:
+ name: demo
+ units: mm
+
+ops[2]:
+ -
+ op: box
+ id: base
+ size[3]:
+ 10
+ 20
+ 30
+ -
+ op: expect_selectable
+ target: base
+ count: 1
diff --git a/testdata/firmament/fixtures/m6a-valid-expect-exists-selector-contract-level.firmament b/testdata/firmament/fixtures/m6a-valid-expect-exists-selector-contract-level.firmament
new file mode 100644
index 00000000..89626861
--- /dev/null
+++ b/testdata/firmament/fixtures/m6a-valid-expect-exists-selector-contract-level.firmament
@@ -0,0 +1,18 @@
+firmament:
+ version: 1
+
+model:
+ name: demo
+ units: mm
+
+ops[2]:
+ -
+ op: box
+ id: base
+ size[3]:
+ 10
+ 20
+ 30
+ -
+ op: expect_exists
+ target: base.top_face
diff --git a/testdata/firmament/fixtures/m6a-valid-expect-selectable-many-count2.firmament b/testdata/firmament/fixtures/m6a-valid-expect-selectable-many-count2.firmament
new file mode 100644
index 00000000..e736e60c
--- /dev/null
+++ b/testdata/firmament/fixtures/m6a-valid-expect-selectable-many-count2.firmament
@@ -0,0 +1,19 @@
+firmament:
+ version: 1
+
+model:
+ name: demo
+ units: mm
+
+ops[2]:
+ -
+ op: box
+ id: base
+ size[3]:
+ 10
+ 20
+ 30
+ -
+ op: expect_selectable
+ target: base.side_faces
+ count: 2
diff --git a/testdata/firmament/fixtures/m6a-valid-expect-selectable-one-count1.firmament b/testdata/firmament/fixtures/m6a-valid-expect-selectable-one-count1.firmament
new file mode 100644
index 00000000..378ce917
--- /dev/null
+++ b/testdata/firmament/fixtures/m6a-valid-expect-selectable-one-count1.firmament
@@ -0,0 +1,19 @@
+firmament:
+ version: 1
+
+model:
+ name: demo
+ units: mm
+
+ops[2]:
+ -
+ op: box
+ id: base
+ size[3]:
+ 10
+ 20
+ 30
+ -
+ op: expect_selectable
+ target: base.top_face
+ count: 1