Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Add M21 hardening regression corpus and failure-path guards
Yuechen Lifdb72c768294
diff --git a/Aetheris.Kernel.Core.Tests/Brep/HardeningRandomizedStressTests.cs b/Aetheris.Kernel.Core.Tests/Brep/HardeningRandomizedStressTests.csnew file mode 100644index 00000000..af2b4843--- /dev/null+++ b/Aetheris.Kernel.Core.Tests/Brep/HardeningRandomizedStressTests.cs@@ -0,0 +1,103 @@+using Aetheris.Kernel.Core.Brep;+using Aetheris.Kernel.Core.Brep.Boolean;+using Aetheris.Kernel.Core.Brep.Picking;+using Aetheris.Kernel.Core.Brep.Tessellation;+using Aetheris.Kernel.Core.Diagnostics;+using Aetheris.Kernel.Core.Math;++namespace Aetheris.Kernel.Core.Tests.Brep;++public sealed class HardeningRandomizedStressTests+{+ [Fact]+ public void Randomized_CreateBoxDimensions_WithFixedSeed_AreAlwaysValid()+ {+ var random = new Random(214748);++ for (var i = 0; i < 64; i++)+ {+ var width = 0.1d + (random.NextDouble() * 20d);+ var height = 0.1d + (random.NextDouble() * 20d);+ var depth = 0.1d + (random.NextDouble() * 20d);++ var result = BrepPrimitives.CreateBox(width, height, depth);+ Assert.True(result.IsSuccess);+ Assert.True(BrepDisplayTessellator.Tessellate(result.Value).IsSuccess);+ }+ }++ [Fact]+ public void Randomized_BoxBooleanClassification_WithFixedSeed_IsNoThrowAndDeterministicDiagnostics()+ {+ var random = new Random(19840615);++ for (var i = 0; i < 80; i++)+ {+ var left = CreateRandomAxisAlignedBox(random);+ var right = CreateRandomAxisAlignedBox(random);++ var exception = Record.Exception(() => BrepBoolean.Union(left, right));+ Assert.Null(exception);++ var result = BrepBoolean.Union(left, right);+ if (!result.IsSuccess)+ {+ var diagnostic = Assert.Single(result.Diagnostics);+ Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);+ Assert.False(string.IsNullOrWhiteSpace(diagnostic.Message));+ }+ }+ }++ [Fact]+ public void Randomized_PickRays_WithFixedSeed_DoNotThrow_AndReturnStableOrderingShape()+ {+ var random = new Random(90210);+ var body = BrepPrimitives.CreateBox(2d, 2d, 2d).Value;+ var tessellation = BrepDisplayTessellator.Tessellate(body).Value;+ var options = PickQueryOptions.Default with { IncludeBackfaces = true, EdgeTolerance = 1e-5d, SortTieTolerance = 1e-5d };++ for (var i = 0; i < 50; i++)+ {+ var origin = new Point3D(+ (random.NextDouble() * 8d) - 4d,+ (random.NextDouble() * 8d) - 4d,+ (random.NextDouble() * 8d) - 4d);+ var directionVector = new Vector3D(+ (random.NextDouble() * 2d) - 1d,+ (random.NextDouble() * 2d) - 1d,+ (random.NextDouble() * 2d) - 1d);++ if (!Direction3D.TryCreate(directionVector, out var direction))+ {+ direction = Direction3D.XAxis;+ }++ var ray = new Ray3D(origin, direction);+ var first = BrepPicker.Pick(body, tessellation, ray, options);+ var second = BrepPicker.Pick(body, tessellation, ray, options);++ Assert.True(first.IsSuccess);+ Assert.True(second.IsSuccess);+ Assert.Equal(first.Value.Count, second.Value.Count);++ for (var h = 1; h < first.Value.Count; h++)+ {+ Assert.True(first.Value[h - 1].T <= first.Value[h].T + 1e-9d);+ }++ Assert.Equal(first.Value, second.Value);+ }+ }++ private static BrepBody CreateRandomAxisAlignedBox(Random random)+ {+ var minX = (random.NextDouble() * 12d) - 6d;+ var minY = (random.NextDouble() * 12d) - 6d;+ var minZ = (random.NextDouble() * 12d) - 6d;+ var sizeX = 0.2d + (random.NextDouble() * 4d);+ var sizeY = 0.2d + (random.NextDouble() * 4d);+ var sizeZ = 0.2d + (random.NextDouble() * 4d);+ return BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(minX, minX + sizeX, minY, minY + sizeY, minZ, minZ + sizeZ)).Value;+ }+}diff --git a/Aetheris.Kernel.Core.Tests/Brep/HardeningRegressionCorpusTests.cs b/Aetheris.Kernel.Core.Tests/Brep/HardeningRegressionCorpusTests.csnew file mode 100644index 00000000..5920d881--- /dev/null+++ b/Aetheris.Kernel.Core.Tests/Brep/HardeningRegressionCorpusTests.cs@@ -0,0 +1,79 @@+using Aetheris.Kernel.Core.Brep;+using Aetheris.Kernel.Core.Brep.Boolean;+using Aetheris.Kernel.Core.Brep.Features;+using Aetheris.Kernel.Core.Brep.Picking;+using Aetheris.Kernel.Core.Brep.Tessellation;+using Aetheris.Kernel.Core.Diagnostics;+using Aetheris.Kernel.Core.Topology;++namespace Aetheris.Kernel.Core.Tests.Brep;++public sealed class HardeningRegressionCorpusTests+{+ [Fact]+ public void Corpus_Primitives_BoxCylinderSphere_StayConstructible()+ {+ Assert.True(BrepPrimitives.CreateBox(2d, 3d, 4d).IsSuccess);+ Assert.True(BrepPrimitives.CreateCylinder(1d, 5d).IsSuccess);+ Assert.True(BrepPrimitives.CreateSphere(2d).IsSuccess);+ }++ [Fact]+ public void Corpus_Extrude_ValidAndInvalidDepth_AreStable()+ {+ var frame = HardeningRegressionFixtures.CanonicalFrame();+ var good = BrepExtrude.Create(HardeningRegressionFixtures.CanonicalExtrudeProfile(), frame, 3d);+ var bad = BrepExtrude.Create(HardeningRegressionFixtures.CanonicalExtrudeProfile(), frame, 0d);++ Assert.True(good.IsSuccess);+ Assert.False(bad.IsSuccess);+ Assert.Contains(bad.Diagnostics, d => d.Code == KernelDiagnosticCode.InvalidArgument);+ }++ [Fact]+ public void Corpus_Revolve_SupportedAndUnsupported_Subsets_AreStable()+ {+ var frame = HardeningRegressionFixtures.CanonicalFrame();+ var axis = new RevolveAxis3D(frame.Origin, frame.Normal.ToVector());++ var supported = BrepRevolve.Create(HardeningRegressionFixtures.CanonicalRevolveProfile, frame, axis, System.Math.PI * 2d);+ var unsupported = BrepRevolve.Create(HardeningRegressionFixtures.CanonicalRevolveProfile, frame, axis, System.Math.PI);++ Assert.True(supported.IsSuccess);+ Assert.False(unsupported.IsSuccess);+ Assert.Contains(unsupported.Diagnostics, d => d.Code == KernelDiagnosticCode.NotImplemented);+ }++ [Fact]+ public void Corpus_BoxBoolean_SupportedAndUnsupported_Matrix_AreStable()+ {+ var left = HardeningRegressionFixtures.OverlapLeftBox();+ var overlapRight = HardeningRegressionFixtures.OverlapRightBox();+ var touchingRight = HardeningRegressionFixtures.TouchingOnlyBox();+ var lShapeRight = HardeningRegressionFixtures.LShapeUnionRightBox();+ var contained = HardeningRegressionFixtures.ContainedBox();++ Assert.True(BrepBoolean.Intersect(left, overlapRight).IsSuccess);+ Assert.False(BrepBoolean.Intersect(left, touchingRight).IsSuccess);+ Assert.False(BrepBoolean.Union(left, lShapeRight).IsSuccess);++ var containmentUnion = BrepBoolean.Union(left, contained);+ Assert.True(containmentUnion.IsSuccess);+ }++ [Fact]+ public void Corpus_TessellationAndPick_FaceEdgeTieOrdering_StaysDeterministic()+ {+ var body = BrepPrimitives.CreateBox(2d, 2d, 2d).Value;+ var tessellation = BrepDisplayTessellator.Tessellate(body).Value;++ var first = BrepPicker.Pick(body, tessellation, HardeningRegressionFixtures.TopDownEdgeTieRay(), PickQueryOptions.Default with { IncludeBackfaces = true, EdgeTolerance = 1e-6d, SortTieTolerance = 1e-5d });+ var second = BrepPicker.Pick(body, tessellation, HardeningRegressionFixtures.TopDownEdgeTieRay(), PickQueryOptions.Default with { IncludeBackfaces = true, EdgeTolerance = 1e-6d, SortTieTolerance = 1e-5d });++ Assert.True(first.IsSuccess);+ Assert.True(second.IsSuccess);+ Assert.NotEmpty(first.Value);+ Assert.Equal(first.Value, second.Value);+ Assert.Equal(SelectionEntityKind.Edge, first.Value[0].EntityKind);+ }+}diff --git a/Aetheris.Kernel.Core.Tests/Brep/HardeningRegressionFixtures.cs b/Aetheris.Kernel.Core.Tests/Brep/HardeningRegressionFixtures.csnew file mode 100644index 00000000..625094e9--- /dev/null+++ b/Aetheris.Kernel.Core.Tests/Brep/HardeningRegressionFixtures.cs@@ -0,0 +1,39 @@+using Aetheris.Kernel.Core.Brep;+using Aetheris.Kernel.Core.Brep.Boolean;+using Aetheris.Kernel.Core.Brep.Features;+using Aetheris.Kernel.Core.Math;++namespace Aetheris.Kernel.Core.Tests.Brep;++internal static class HardeningRegressionFixtures+{+ internal static BrepBody OverlapLeftBox() => BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(0d, 4d, 0d, 4d, 0d, 4d)).Value;++ internal static BrepBody OverlapRightBox() => BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(2d, 6d, 1d, 3d, -1d, 2d)).Value;++ internal static BrepBody TouchingOnlyBox() => BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(4d, 6d, 0d, 4d, 0d, 4d)).Value;++ internal static BrepBody LShapeUnionRightBox() => BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(2d, 4d, 0d, 2d, 0d, 2d)).Value;++ internal static BrepBody ContainedBox() => BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(1d, 2d, 1d, 2d, 1d, 2d)).Value;++ internal static PolylineProfile2D CanonicalExtrudeProfile() => PolylineProfile2D.Rectangle(2d, 2d);++ internal static IReadOnlyList<ProfilePoint2D> CanonicalRevolveProfile =>+ [+ new ProfilePoint2D(1d, 0d),+ new ProfilePoint2D(1d, 2d),+ new ProfilePoint2D(0d, 2d),+ new ProfilePoint2D(0d, 0d),+ ];++ internal static ExtrudeFrame3D CanonicalFrame() =>+ new(+ Point3D.Origin,+ Direction3D.Create(new Vector3D(0d, 0d, 1d)),+ Direction3D.Create(new Vector3D(1d, 0d, 0d)));++ internal static Ray3D TopDownCenterRay() => new(new Point3D(0d, 0d, 5d), Direction3D.Create(new Vector3D(0d, 0d, -1d)));++ internal static Ray3D TopDownEdgeTieRay() => new(new Point3D(1d, 1d, 3d), Direction3D.Create(new Vector3D(0d, 0d, -1d)));+}diff --git a/Aetheris.Kernel.Core/Brep/Picking/BrepPicker.cs b/Aetheris.Kernel.Core/Brep/Picking/BrepPicker.csindex 7646ad2a..1cd40cfa 100644--- a/Aetheris.Kernel.Core/Brep/Picking/BrepPicker.cs+++ b/Aetheris.Kernel.Core/Brep/Picking/BrepPicker.cs@@ -427,8 +427,9 @@ public static class BrepPickerwhile (index < byT.Count){var groupEndExclusive = index + 1;+ var groupStartT = byT[index].T;while (groupEndExclusive < byT.Count- && System.Math.Abs(byT[groupEndExclusive].T - byT[groupEndExclusive - 1].T) <= tieTolerance)+ && System.Math.Abs(byT[groupEndExclusive].T - groupStartT) <= tieTolerance){groupEndExclusive++;}diff --git a/Aetheris.Server.Tests/KernelApiIntegrationTests.cs b/Aetheris.Server.Tests/KernelApiIntegrationTests.csindex 72df205e..00a658d1 100644--- a/Aetheris.Server.Tests/KernelApiIntegrationTests.cs+++ b/Aetheris.Server.Tests/KernelApiIntegrationTests.cs@@ -1,5 +1,6 @@using System.Net;using System.Net.Http.Json;+using System.Text;using Aetheris.Server.Contracts;using Microsoft.AspNetCore.Mvc.Testing;@@ -221,6 +222,67 @@ public sealed class KernelApiIntegrationTests : IClassFixture<WebApplicationFact});}+ [Fact]+ public async Task InvalidPrimitiveDimensions_ReturnStructuredBadRequestEnvelope()+ {+ var document = await CreateDocumentAsync("/api/v1/documents");+ var response = await _client.PostAsJsonAsync(+ $"/api/v1/documents/{document.Data!.DocumentId}/bodies/primitives/box",+ new BoxCreateRequestDto(-1d, 2d, 3d));++ Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);+ var payload = await response.Content.ReadFromJsonAsync<ApiResponseDto<object>>();+ Assert.NotNull(payload);+ Assert.False(payload!.Success);+ Assert.Null(payload.Data);+ Assert.NotEmpty(payload.Diagnostics);+ Assert.Contains(payload.Diagnostics, d => d.Code == "InvalidArgument");+ }++ [Fact]+ public async Task Transform_UnknownBody_ReturnsNotFoundEnvelope()+ {+ var document = await CreateDocumentAsync("/api/v1/documents");+ var missingBodyId = Guid.NewGuid();++ var response = await _client.PostAsJsonAsync(+ $"/api/v1/documents/{document.Data!.DocumentId}/bodies/{missingBodyId}/transform",+ new TranslateBodyRequestDto(new Vector3Dto(1d, 0d, 0d)));++ Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);+ var payload = await response.Content.ReadFromJsonAsync<ApiResponseDto<object>>();+ Assert.NotNull(payload);+ Assert.False(payload!.Success);+ Assert.Null(payload.Data);+ Assert.NotEmpty(payload.Diagnostics);+ }++ [Fact]+ public async Task Extrude_NullProfilePayload_ReturnsStructuredBadRequestEnvelope()+ {+ var document = await CreateDocumentAsync("/api/v1/documents");+ var json = """+ {+ "profile": null,+ "origin": {"x":0,"y":0,"z":0},+ "normal": {"x":0,"y":0,"z":1},+ "uAxis": {"x":1,"y":0,"z":0},+ "depth": 1.0+ }+ """;++ var response = await _client.PostAsync(+ $"/api/v1/documents/{document.Data!.DocumentId}/operations/extrude",+ new StringContent(json, Encoding.UTF8, "application/json"));++ Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);+ var payload = await response.Content.ReadFromJsonAsync<ApiResponseDto<object>>();+ Assert.NotNull(payload);+ Assert.False(payload!.Success);+ Assert.Null(payload.Data);+ Assert.Contains(payload.Diagnostics, d => d.Source == "operations.extrude");+ }+private async Task<ApiResponseDto<DocumentCreateResponseDto>> CreateDocumentAsync(string routePrefix){var response = await _client.PostAsJsonAsync(routePrefix, new DocumentCreateRequestDto("test"));diff --git a/Aetheris.Server/Api/KernelEndpoints.cs b/Aetheris.Server/Api/KernelEndpoints.csindex 8a5c2cd3..d8a15136 100644--- a/Aetheris.Server/Api/KernelEndpoints.cs+++ b/Aetheris.Server/Api/KernelEndpoints.cs@@ -75,6 +75,11 @@ public static class KernelEndpointsdocuments.MapPost("/{documentId:guid}/operations/extrude", (Guid documentId, ExtrudeRequestDto request, KernelDocumentStore store) =>WithDocument(store, documentId, document =>{+ if (request.Profile is null)+ {+ return ApiMappings.BadRequestFromMessage("Profile must be provided.", "operations.extrude");+ }+var profile = PolylineProfile2D.Create(request.Profile.Select(p => new ProfilePoint2D(p.X, p.Y)).ToArray());if (!profile.IsSuccess){@@ -98,6 +103,11 @@ public static class KernelEndpointsdocuments.MapPost("/{documentId:guid}/operations/revolve", (Guid documentId, RevolveRequestDto request, KernelDocumentStore store) =>WithDocument(store, documentId, document =>{+ if (request.Profile is null)+ {+ return ApiMappings.BadRequestFromMessage("Profile must be provided.", "operations.revolve");+ }+if (!Direction3D.TryCreate(new Vector3D(request.AxisDirection.X, request.AxisDirection.Y, request.AxisDirection.Z), out var axisDirection)){return ApiMappings.BadRequestFromMessage("AxisDirection must be non-zero and finite.", "operations.revolve");@@ -173,6 +183,11 @@ public static class KernelEndpointsdocuments.MapPost("/{documentId:guid}/bodies/{bodyId:guid}/transform", (Guid documentId, Guid bodyId, TranslateBodyRequestDto request, KernelDocumentStore store) =>WithDocument(store, documentId, document =>{+ if (request.Translation is null)+ {+ return ApiMappings.BadRequestFromMessage("Translation must be provided.", "documents.body");+ }+if (!document.ApplyBodyTranslation(bodyId, new Vector3D(request.Translation.X, request.Translation.Y, request.Translation.Z), out _)){return ApiMappings.NotFound($"Body '{bodyId}' was not found.", "documents.body");@@ -202,6 +217,11 @@ public static class KernelEndpointsdocuments.MapPost("/{documentId:guid}/bodies/{bodyId:guid}/pick", (Guid documentId, Guid bodyId, PickRequestDto request, KernelDocumentStore store) =>WithDocumentBody(store, documentId, bodyId, (document, body) =>{+ if (request.Direction is null)+ {+ return ApiMappings.BadRequestFromMessage("Direction must be provided.", "bodies.pick");+ }+if (!Direction3D.TryCreate(new Vector3D(request.Direction.X, request.Direction.Y, request.Direction.Z), out var direction)){return ApiMappings.BadRequestFromMessage("Direction must be non-zero and finite.", "bodies.pick");diff --git a/docs/milestones.md b/docs/milestones.mdindex 4c0febdc..8c8039a6 100644--- a/docs/milestones.md+++ b/docs/milestones.md@@ -189,3 +189,12 @@- [x] Adopt deterministic success semantics aligned with current backend behavior: keep original bodies and add a new boolean result body, refresh document summary, auto-select/tessellate the returned result body, and intentionally clear pick highlight/hits after success.- [x] Preserve failure stability: on unsupported/error responses the previous viewport/tessellation state is preserved while status/diagnostics update for observability.- [x] Defer boolean previews, feature history, undo/redo, gizmo-based selection, advanced naming/metadata workflows, and generalized boolean support beyond M13.++## M21 — Hardening Pass 1 (Regression Corpus + Crash Resistance)++- [x] Add a curated regression corpus for representative kernel/backend flows (primitives, extrude/revolve subsets, M13 boolean support boundaries, tessellation/picking contracts, and versioned envelope behavior).+- [x] Introduce deterministic hardening fixtures for repeatable scenarios (canonical box-pair booleans, extrude/revolve profiles, and pick rays).+- [x] Add bounded randomized stress checks with fixed seeds for stable areas (box construction, boolean classification behavior, and pick no-throw/order stability).+- [x] Harden routine failure paths to remain diagnostic-first and no-throw for malformed/unsupported requests.+- [x] Keep scope hardening-only: no new modeling capabilities or UI feature expansion.+- [x] Defer known fragilities (general booleans beyond axis-aligned single-box results, broad trimmed-surface tessellation fidelity, and advanced pick acceleration/performance work).