Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Add STEP242 audit harness and importer hardening

Yuechen Li4cd7b709f587
diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.cs
index 588369d0..3bf24237 100644
--- a/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.cs
@@ -54,7 +54,7 @@ public sealed class Step242ImporterTests
var diagnostic = Assert.Single(import.Diagnostics);
Assert.Equal(KernelDiagnosticCode.InvalidArgument, diagnostic.Code);
Assert.Equal(KernelDiagnosticSeverity.Error, diagnostic.Severity);
- Assert.Equal("Parser", diagnostic.Source);
+ Assert.StartsWith("Parser", diagnostic.Source, StringComparison.Ordinal);
}
[Fact]
@@ -68,8 +68,49 @@ public sealed class Step242ImporterTests
var diagnostic = Assert.Single(import.Diagnostics);
Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);
Assert.Equal(KernelDiagnosticSeverity.Error, diagnostic.Severity);
- Assert.Equal("Entity:1", diagnostic.Source);
+ Assert.Equal("Importer.EntityFamily", diagnostic.Source);
Assert.Contains("unsupported", diagnostic.Message, StringComparison.OrdinalIgnoreCase);
}
+ [Fact]
+ public void ImportBody_MissingSolidRoot_ReturnsDeterministicTopologyRootDiagnostic()
+ {
+ const string noRoot = "ISO-10303-21;\nHEADER;\nENDSEC;\nDATA;\n#1=CARTESIAN_POINT($,(0,0,0));\nENDSEC;\nEND-ISO-10303-21;";
+
+ var import = Step242Importer.ImportBody(noRoot);
+
+ Assert.False(import.IsSuccess);
+ var diagnostic = Assert.Single(import.Diagnostics);
+ Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);
+ Assert.Equal("Importer.TopologyRoot", diagnostic.Source);
+ Assert.StartsWith("Missing MANIFOLD_SOLID_BREP", diagnostic.Message, StringComparison.Ordinal);
+ }
+
+ [Fact]
+ public void ImportBody_MultipleSolidRoots_ReturnsDeterministicSingleSolidDiagnostic()
+ {
+ const string multiRoot = "ISO-10303-21;\nHEADER;\nENDSEC;\nDATA;\n#1=MANIFOLD_SOLID_BREP('a',#3);\n#2=MANIFOLD_SOLID_BREP('b',#3);\n#3=CLOSED_SHELL($,());\nENDSEC;\nEND-ISO-10303-21;";
+
+ var import = Step242Importer.ImportBody(multiRoot);
+
+ Assert.False(import.IsSuccess);
+ var diagnostic = Assert.Single(import.Diagnostics);
+ Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);
+ Assert.Equal("Importer.SingleSolid", diagnostic.Source);
+ Assert.StartsWith("Multiple MANIFOLD_SOLID_BREP", diagnostic.Message, StringComparison.Ordinal);
+ }
+
+ [Fact]
+ public void ImportBody_DegenerateDirection_ReturnsDiagnosticWithoutThrowing()
+ {
+ const string degenerateDirection = "ISO-10303-21;\nHEADER;\nENDSEC;\nDATA;\n#1=MANIFOLD_SOLID_BREP('solid',#2);\n#2=CLOSED_SHELL($,(#3));\n#3=ADVANCED_FACE((#4),#5,.T.);\n#4=FACE_OUTER_BOUND($,#6,.T.);\n#5=PLANE($,#20);\n#6=EDGE_LOOP($,(#7));\n#7=ORIENTED_EDGE($,$,$,#8,.T.);\n#8=EDGE_CURVE($,#9,#10,#11,.T.);\n#9=VERTEX_POINT($,#12);\n#10=VERTEX_POINT($,#13);\n#11=LINE($,#12,#14);\n#12=CARTESIAN_POINT($,(0,0,0));\n#13=CARTESIAN_POINT($,(1,0,0));\n#14=VECTOR($,#15,1.0);\n#15=DIRECTION($,(1,0,0));\n#20=AXIS2_PLACEMENT_3D($,#12,#21,#22);\n#21=DIRECTION($,(0,0,0));\n#22=DIRECTION($,(1,0,0));\nENDSEC;\nEND-ISO-10303-21;";
+
+ var import = Step242Importer.ImportBody(degenerateDirection);
+
+ Assert.False(import.IsSuccess);
+ var diagnostic = Assert.Single(import.Diagnostics);
+ Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);
+ Assert.Equal("Importer.Geometry.Direction", diagnostic.Source);
+ Assert.StartsWith("Degenerate direction vector", diagnostic.Message, StringComparison.Ordinal);
+ }
}
diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242NistAuditHarnessTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242NistAuditHarnessTests.cs
new file mode 100644
index 00000000..da75ef63
--- /dev/null
+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242NistAuditHarnessTests.cs
@@ -0,0 +1,303 @@
+using System.Security.Cryptography;
+using System.Text;
+using System.Text.Json;
+using Aetheris.Kernel.Core.Brep;
+using Aetheris.Kernel.Core.Brep.Picking;
+using Aetheris.Kernel.Core.Brep.Tessellation;
+using Aetheris.Kernel.Core.Diagnostics;
+using Aetheris.Kernel.Core.Math;
+using Aetheris.Kernel.Core.Step242;
+
+namespace Aetheris.Kernel.Core.Tests.Step242;
+
+public sealed class Step242NistAuditHarnessTests
+{
+ private static readonly JsonSerializerOptions JsonOptions = new()
+ {
+ PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
+ WriteIndented = true
+ };
+
+ [Fact]
+ public void NistCorpus_AuditReport_IsByteStableAcrossConsecutiveRuns_AndMatchesSnapshot()
+ {
+ var first = BuildAuditReportJson();
+ var second = BuildAuditReportJson();
+
+ Assert.Equal(first, second);
+
+ var snapshotPath = Path.Combine(RepoRoot(), "testdata", "step242", "manifests", "nist.v0.report.json");
+ var expected = File.ReadAllText(snapshotPath, Encoding.UTF8);
+ if (!string.Equals(expected, first, StringComparison.Ordinal))
+ {
+ if (string.Equals(Environment.GetEnvironmentVariable("AETHERIS_UPDATE_STEP242_SNAPSHOT"), "1", StringComparison.Ordinal))
+ {
+ File.WriteAllText(snapshotPath, first, new UTF8Encoding(false));
+ return;
+ }
+
+ var hint = FirstDiffHint(expected, first);
+ Assert.Fail($"NIST audit snapshot mismatch. {hint}");
+ }
+ }
+
+ private static string BuildAuditReportJson()
+ {
+ var nistRoot = Path.Combine(RepoRoot(), "testdata", "step242", "nist");
+ var files = Directory
+ .EnumerateFiles(nistRoot, "*.stp", SearchOption.AllDirectories)
+ .Select(path => Path.GetRelativePath(RepoRoot(), path).Replace('\\', '/'))
+ .OrderBy(path => path, StringComparer.Ordinal)
+ .ToArray();
+
+ var entries = new List<Step242NistAuditEntry>(files.Length);
+ foreach (var relativePath in files)
+ {
+ entries.Add(RunOne(relativePath));
+ }
+
+ Assert.All(entries, entry => Assert.False(entry.ExceptionEscaped));
+
+ foreach (var entry in entries.Where(e => string.Equals(e.Status, "success", StringComparison.Ordinal)))
+ {
+ Assert.NotNull(entry.CanonicalSha256);
+ Assert.Matches("^[0-9a-f]{64}$", entry.CanonicalSha256!);
+ }
+
+ return JsonSerializer.Serialize(entries, JsonOptions) + "\n";
+ }
+
+ private static Step242NistAuditEntry RunOne(string relativePath)
+ {
+ var fullPath = Path.Combine(RepoRoot(), relativePath.Replace('/', Path.DirectorySeparatorChar));
+ var info = new FileInfo(fullPath);
+ var text = File.ReadAllText(fullPath, Encoding.UTF8);
+
+ try
+ {
+ var import = Step242Importer.ImportBody(text);
+ if (!import.IsSuccess)
+ {
+ return BuildFailureEntry(relativePath, info.Length, import.Diagnostics, DetermineImportFailureLayer(import.Diagnostics));
+ }
+
+ var body = import.Value;
+ var validation = BrepBindingValidator.Validate(body, requireAllEdgeAndFaceBindings: true);
+ if (!validation.IsSuccess)
+ {
+ return BuildFailureEntry(relativePath, info.Length, validation.Diagnostics, "validator", body);
+ }
+
+ var tessellation = BrepDisplayTessellator.Tessellate(body);
+ if (!tessellation.IsSuccess)
+ {
+ return BuildFailureEntry(relativePath, info.Length, tessellation.Diagnostics, "tessellator", body);
+ }
+
+ var smokeRay = new Ray3D(new Point3D(0.25d, 0.25d, 250d), Direction3D.Create(new Vector3D(0d, 0d, -1d)));
+ var pick = BrepPicker.Pick(body, tessellation.Value, smokeRay, PickQueryOptions.Default with { NearestOnly = true });
+ if (!pick.IsSuccess)
+ {
+ return BuildFailureEntry(relativePath, info.Length, pick.Diagnostics, "picker", body, tessellation.Value);
+ }
+
+ if (pick.Value.Count == 0)
+ {
+ return BuildFailureEntry(
+ relativePath,
+ info.Length,
+ [new KernelDiagnostic(KernelDiagnosticCode.InvalidArgument, KernelDiagnosticSeverity.Error, "Picker smoke ray produced no hit.", "Audit.Picker")],
+ "picker",
+ body,
+ tessellation.Value);
+ }
+
+ var export = Step242Exporter.ExportBody(body);
+ if (!export.IsSuccess)
+ {
+ return BuildFailureEntry(relativePath, info.Length, export.Diagnostics, "exporter", body, tessellation.Value);
+ }
+
+ return new Step242NistAuditEntry(
+ FileId(relativePath),
+ relativePath,
+ (int)info.Length,
+ "success",
+ FirstFailureLayer: "",
+ FirstDiagnostic(import.Diagnostics),
+ DiagnosticCount: import.Diagnostics.Count,
+ ExceptionEscaped: false,
+ TopologyCounts: new Step242TopologyCounts(body.Topology.Vertices.Count(), body.Topology.Edges.Count(), body.Topology.Faces.Count()),
+ TessellationCounts: new Step242TessellationCounts(tessellation.Value.FacePatches.Count, tessellation.Value.EdgePolylines.Count),
+ CanonicalSha256: ComputeSha256LowerHex(export.Value));
+ }
+ catch (Exception ex)
+ {
+ return new Step242NistAuditEntry(
+ FileId(relativePath),
+ relativePath,
+ (int)info.Length,
+ Status: "importFail",
+ FirstFailureLayer: "importer-topology",
+ FirstDiagnostic: new Step242AuditDiagnostic("InvalidArgument", "Audit.Exception", Truncate(ex.Message)),
+ DiagnosticCount: 1,
+ ExceptionEscaped: true,
+ TopologyCounts: Step242TopologyCounts.Zero,
+ TessellationCounts: Step242TessellationCounts.Zero,
+ CanonicalSha256: null);
+ }
+ }
+
+ private static Step242NistAuditEntry BuildFailureEntry(
+ string relativePath,
+ long sizeBytes,
+ IReadOnlyList<KernelDiagnostic> diagnostics,
+ string layer,
+ BrepBody? body = null,
+ DisplayTessellationResult? tessellation = null)
+ {
+ var first = FirstDiagnostic(diagnostics);
+ var status = string.Equals(layer, "parser", StringComparison.Ordinal) ? "parseFail" : "importFail";
+
+ return new Step242NistAuditEntry(
+ FileId(relativePath),
+ relativePath,
+ (int)sizeBytes,
+ status,
+ layer,
+ first,
+ diagnostics.Count,
+ ExceptionEscaped: false,
+ TopologyCounts: body is null
+ ? Step242TopologyCounts.Zero
+ : new Step242TopologyCounts(body.Topology.Vertices.Count(), body.Topology.Edges.Count(), body.Topology.Faces.Count()),
+ TessellationCounts: tessellation is null
+ ? Step242TessellationCounts.Zero
+ : new Step242TessellationCounts(tessellation.FacePatches.Count, tessellation.EdgePolylines.Count),
+ CanonicalSha256: null);
+ }
+
+ private static Step242AuditDiagnostic FirstDiagnostic(IReadOnlyList<KernelDiagnostic> diagnostics)
+ {
+ if (diagnostics.Count == 0)
+ {
+ return new Step242AuditDiagnostic("Unknown", "Audit.None", "No diagnostics.");
+ }
+
+ var d = diagnostics[0];
+ return new Step242AuditDiagnostic(d.Code.ToString(), NormalizeSource(d.Source ?? string.Empty), StableMessagePrefix(d.Message));
+ }
+
+ private static string DetermineImportFailureLayer(IReadOnlyList<KernelDiagnostic> diagnostics)
+ {
+ if (diagnostics.Count == 0)
+ {
+ return "importer-topology";
+ }
+
+ var source = diagnostics[0].Source ?? string.Empty;
+ if (source.StartsWith("Parser", StringComparison.Ordinal))
+ {
+ return "parser";
+ }
+
+ if (source.StartsWith("Importer.Geometry", StringComparison.Ordinal))
+ {
+ return "importer-geometry";
+ }
+
+ return "importer-topology";
+ }
+
+ private static string NormalizeSource(string source)
+ {
+ var split = source.IndexOf('|', StringComparison.Ordinal);
+ return split > 0 ? source[..split] : source;
+ }
+
+ private static string StableMessagePrefix(string message)
+ {
+ var idx = message.IndexOf(':');
+ if (idx > 0)
+ {
+ return message[..idx];
+ }
+
+ return Truncate(message);
+ }
+
+ private static string Truncate(string value)
+ {
+ const int max = 120;
+ return value.Length <= max ? value : value[..max];
+ }
+
+ private static string ComputeSha256LowerHex(string text)
+ {
+ var bytes = Encoding.UTF8.GetBytes(text);
+ var hash = SHA256.HashData(bytes);
+ return Convert.ToHexString(hash).ToLowerInvariant();
+ }
+
+ private static string FileId(string relativePath)
+ {
+ var stem = Path.GetFileNameWithoutExtension(relativePath);
+ var folder = Path.GetDirectoryName(relativePath)?.Replace('\\', '/').Replace('/', '_') ?? string.Empty;
+ return string.IsNullOrWhiteSpace(folder) ? stem : $"{folder}_{stem}";
+ }
+
+ private static string RepoRoot()
+ {
+ var directory = new DirectoryInfo(AppContext.BaseDirectory);
+ while (directory is not null)
+ {
+ if (File.Exists(Path.Combine(directory.FullName, "Aetheris.slnx")))
+ {
+ return directory.FullName;
+ }
+
+ directory = directory.Parent;
+ }
+
+ throw new InvalidOperationException("Unable to locate repository root.");
+ }
+
+ private static string FirstDiffHint(string expected, string actual)
+ {
+ var max = System.Math.Min(expected.Length, actual.Length);
+ for (var i = 0; i < max; i++)
+ {
+ if (expected[i] != actual[i])
+ {
+ return $"First difference at byte {i}: expected '{expected[i]}', actual '{actual[i]}'.";
+ }
+ }
+
+ return $"Length differs: expected {expected.Length}, actual {actual.Length}.";
+ }
+
+ private sealed record Step242NistAuditEntry(
+ string FileId,
+ string Path,
+ int SizeBytes,
+ string Status,
+ string FirstFailureLayer,
+ Step242AuditDiagnostic FirstDiagnostic,
+ int DiagnosticCount,
+ bool ExceptionEscaped,
+ Step242TopologyCounts TopologyCounts,
+ Step242TessellationCounts TessellationCounts,
+ string? CanonicalSha256);
+
+ private sealed record Step242AuditDiagnostic(string Code, string Source, string MessagePrefix);
+
+ private sealed record Step242TopologyCounts(int Vertices, int Edges, int Faces)
+ {
+ public static Step242TopologyCounts Zero { get; } = new(0, 0, 0);
+ }
+
+ private sealed record Step242TessellationCounts(int FacePatches, int EdgePolylines)
+ {
+ public static Step242TessellationCounts Zero { get; } = new(0, 0);
+ }
+}
diff --git a/Aetheris.Kernel.Core/Step242/Step242Importer.cs b/Aetheris.Kernel.Core/Step242/Step242Importer.cs
index e539eba8..ff413b47 100644
--- a/Aetheris.Kernel.Core/Step242/Step242Importer.cs
+++ b/Aetheris.Kernel.Core/Step242/Step242Importer.cs
@@ -19,7 +19,20 @@ public static class Step242Importer
return KernelResult<BrepBody>.Failure(parseResult.Diagnostics);
}
- return MapSubset(parseResult.Value);
+ try
+ {
+ return MapSubset(parseResult.Value);
+ }
+ catch (Exception ex) when (ex is ArgumentException or InvalidOperationException)
+ {
+ return KernelResult<BrepBody>.Failure([
+ new KernelDiagnostic(
+ KernelDiagnosticCode.InvalidArgument,
+ KernelDiagnosticSeverity.Error,
+ $"Importer rejected parseable STEP input: {ex.Message}",
+ "Importer.Guardrail")
+ ]);
+ }
}
private static KernelResult<BrepBody> MapSubset(Step242ParsedDocument document)
@@ -27,15 +40,25 @@ public static class Step242Importer
var unsupportedEntity = document.Entities.FirstOrDefault(IsClearlyUnsupportedEntity);
if (unsupportedEntity is not null)
{
- return Failure($"Entity '{unsupportedEntity.Name}' is unsupported in M23 import subset.", $"Entity:{unsupportedEntity.Id}");
+ return Failure($"Entity family '{unsupportedEntity.Name}' is unsupported in M23 import subset.", SourceFor(unsupportedEntity.Id, "Importer.EntityFamily"));
}
- var brepEntity = document.Entities.FirstOrDefault(e => string.Equals(e.Name, "MANIFOLD_SOLID_BREP", StringComparison.OrdinalIgnoreCase));
- if (brepEntity is null)
+ var manifoldSolidBreps = document.Entities
+ .Where(e => string.Equals(e.Name, "MANIFOLD_SOLID_BREP", StringComparison.OrdinalIgnoreCase))
+ .ToList();
+
+ if (manifoldSolidBreps.Count == 0)
{
- return Failure("Missing MANIFOLD_SOLID_BREP root entity.", "Importer");
+ return Failure("Missing MANIFOLD_SOLID_BREP root entity.", "Importer.TopologyRoot");
}
+ if (manifoldSolidBreps.Count > 1)
+ {
+ return Failure("Multiple MANIFOLD_SOLID_BREP roots are unsupported in M23 import subset.", "Importer.SingleSolid");
+ }
+
+ var brepEntity = manifoldSolidBreps[0];
+
var shellRefResult = Step242SubsetDecoder.ReadReference(brepEntity, 1, "MANIFOLD_SOLID_BREP shell");
if (!shellRefResult.IsSuccess)
{
@@ -274,7 +297,7 @@ public static class Step242Importer
if (!sameSenseResult.Value)
{
return KernelResult<EdgeId>.Failure([
- new KernelDiagnostic(KernelDiagnosticCode.NotImplemented, KernelDiagnosticSeverity.Error, "EDGE_CURVE with same_sense=.F. is unsupported in M23 subset.", $"Entity:{edgeCurveEntity.Id}")
+ new KernelDiagnostic(KernelDiagnosticCode.NotImplemented, KernelDiagnosticSeverity.Error, "EDGE_CURVE with same_sense=.F. is unsupported in M23 subset.", SourceFor(edgeCurveEntity.Id, "Importer.EdgeCurveSense"))
]);
}
@@ -353,4 +376,6 @@ public static class Step242Importer
private static KernelResult<BrepBody> Failure(string message, string source) =>
KernelResult<BrepBody>.Failure([new KernelDiagnostic(KernelDiagnosticCode.NotImplemented, KernelDiagnosticSeverity.Error, message, source)]);
+
+ private static string SourceFor(int _entityId, string stableSource) => stableSource;
}
diff --git a/Aetheris.Kernel.Core/Step242/Step242SubsetDecoder.cs b/Aetheris.Kernel.Core/Step242/Step242SubsetDecoder.cs
index 8bc90114..9ab35529 100644
--- a/Aetheris.Kernel.Core/Step242/Step242SubsetDecoder.cs
+++ b/Aetheris.Kernel.Core/Step242/Step242SubsetDecoder.cs
@@ -208,7 +208,14 @@ internal static class Step242SubsetDecoder
return KernelResult<PlaneSurface>.Failure(refDirResult.Diagnostics);
}
- return KernelResult<PlaneSurface>.Success(new PlaneSurface(originResult.Value, normalResult.Value, refDirResult.Value));
+ try
+ {
+ return KernelResult<PlaneSurface>.Success(new PlaneSurface(originResult.Value, normalResult.Value, refDirResult.Value));
+ }
+ catch (ArgumentException)
+ {
+ return FailurePlane("Degenerate AXIS2_PLACEMENT_3D produced invalid plane basis.", SourceFor(planeEntity.Id, "Importer.Geometry.Plane"));
+ }
}
private static KernelResult<Point3D> ReadCartesianPoint(Step242ParsedEntity pointEntity, string context)
@@ -252,7 +259,14 @@ internal static class Step242SubsetDecoder
return KernelResult<Direction3D>.Failure(pointResult.Diagnostics);
}
- return KernelResult<Direction3D>.Success(Direction3D.Create(pointResult.Value - Point3D.Origin));
+ try
+ {
+ return KernelResult<Direction3D>.Success(Direction3D.Create(pointResult.Value - Point3D.Origin));
+ }
+ catch (ArgumentException)
+ {
+ return FailureDirection("Degenerate direction vector is not supported.", SourceFor(directionEntity.Id, "Importer.Geometry.Direction"));
+ }
}
private static KernelResult<double> ReadNumber(Step242Value value, string context, int entityId)
@@ -280,6 +294,12 @@ internal static class Step242SubsetDecoder
private static KernelResult<double> FailureNumber(string message, string source) => Failure<double>(message, source);
+ private static KernelResult<Direction3D> FailureDirection(string message, string source) => Failure<Direction3D>(message, source);
+
+ private static KernelResult<PlaneSurface> FailurePlane(string message, string source) => Failure<PlaneSurface>(message, source);
+
+ private static string SourceFor(int _entityId, string stableSource) => stableSource;
+
private static KernelResult<T> Failure<T>(string message, string source) =>
KernelResult<T>.Failure([new KernelDiagnostic(KernelDiagnosticCode.NotImplemented, KernelDiagnosticSeverity.Error, message, source)]);
}
diff --git a/Aetheris.Kernel.Core/Step242/Step242SubsetParser.cs b/Aetheris.Kernel.Core/Step242/Step242SubsetParser.cs
index bd54f79f..946f1d88 100644
--- a/Aetheris.Kernel.Core/Step242/Step242SubsetParser.cs
+++ b/Aetheris.Kernel.Core/Step242/Step242SubsetParser.cs
@@ -48,7 +48,7 @@ internal static class Step242SubsetParser
if (duplicateId is not null)
{
- return Failure($"Duplicate entity id #{duplicateId.Key} detected.", "Parser");
+ return Failure($"Duplicate entity id #{duplicateId.Key} detected.", "Parser.Semantics");
}
return KernelResult<Step242ParsedDocument>.Success(new Step242ParsedDocument(entities));
@@ -341,7 +341,7 @@ internal static class Step242SubsetParser
_index++;
}
- private Step242ParseException Error(string message) => new($"{message} (position {_index}).", "Parser");
+ private Step242ParseException Error(string message) => new($"{message} (position {_index}).", "Parser.Lexer");
}
}
diff --git a/docs/milestones.md b/docs/milestones.md
index b516d901..b4df3b94 100644
--- a/docs/milestones.md
+++ b/docs/milestones.md
@@ -278,3 +278,12 @@
- [x] Remove Debug/Status from the primary viewer surface and keep diagnostics/debug detail in the Modeling Demo tab.
- [x] Keep STEP import/export and canonical hash behavior functionally unchanged while restructuring only frontend layout/presentation.
- [x] Add frontend tests for tab switching, viewer vs modeling control visibility, and canonical hash visibility in the Viewer tab.
+
+## M31 — STEP242 v0 Audit Harness + Deterministic Diagnostics + No-Throw Guardrails
+
+- [x] Add deterministic NIST STEP242 audit harness coverage that scans `testdata/step242/nist/**/*.stp` in lexical path order and emits a stable report shape.
+- [x] Commit a deterministic expected report snapshot at `testdata/step242/manifests/nist.v0.report.json` and enforce byte-identical reruns in tests.
+- [x] Harden `Step242Importer.ImportBody` with no-throw guardrails for parseable input by converting mapper exceptions into deterministic diagnostics.
+- [x] Enforce strict single-solid contract (`MANIFOLD_SOLID_BREP` count must be exactly one) with deterministic diagnostics for missing/multiple roots.
+- [x] Normalize stable diagnostic buckets for parser/importer-topology/importer-geometry expected-fail reporting.
+- [x] Explicitly keep non-goals unchanged for M31: no new STEP geometry families, no assembly/product semantics, and no healing/repair support.
diff --git a/testdata/step242/manifests/nist.v0.report.json b/testdata/step242/manifests/nist.v0.report.json
new file mode 100644
index 00000000..691b917b
--- /dev/null
+++ b/testdata/step242/manifests/nist.v0.report.json
@@ -0,0 +1,410 @@
+[
+ {
+ "fileId": "testdata_step242_nist_CTC_nist_ctc_01_asme1_ap242-e1",
+ "path": "testdata/step242/nist/CTC/nist_ctc_01_asme1_ap242-e1.stp",
+ "sizeBytes": 391739,
+ "status": "parseFail",
+ "firstFailureLayer": "parser",
+ "firstDiagnostic": {
+ "code": "InvalidArgument",
+ "source": "Parser.Lexer",
+ "messagePrefix": "Expected identifier. (position 507)."
+ },
+ "diagnosticCount": 1,
+ "exceptionEscaped": false,
+ "topologyCounts": {
+ "vertices": 0,
+ "edges": 0,
+ "faces": 0
+ },
+ "tessellationCounts": {
+ "facePatches": 0,
+ "edgePolylines": 0
+ },
+ "canonicalSha256": null
+ },
+ {
+ "fileId": "testdata_step242_nist_CTC_nist_ctc_02_asme1_ap242-e2",
+ "path": "testdata/step242/nist/CTC/nist_ctc_02_asme1_ap242-e2.stp",
+ "sizeBytes": 1958442,
+ "status": "parseFail",
+ "firstFailureLayer": "parser",
+ "firstDiagnostic": {
+ "code": "InvalidArgument",
+ "source": "Parser.Lexer",
+ "messagePrefix": "Expected identifier. (position 3413)."
+ },
+ "diagnosticCount": 1,
+ "exceptionEscaped": false,
+ "topologyCounts": {
+ "vertices": 0,
+ "edges": 0,
+ "faces": 0
+ },
+ "tessellationCounts": {
+ "facePatches": 0,
+ "edgePolylines": 0
+ },
+ "canonicalSha256": null
+ },
+ {
+ "fileId": "testdata_step242_nist_CTC_nist_ctc_03_asme1_ap242-e2",
+ "path": "testdata/step242/nist/CTC/nist_ctc_03_asme1_ap242-e2.stp",
+ "sizeBytes": 667521,
+ "status": "parseFail",
+ "firstFailureLayer": "parser",
+ "firstDiagnostic": {
+ "code": "InvalidArgument",
+ "source": "Parser.Lexer",
+ "messagePrefix": "Expected identifier. (position 2099)."
+ },
+ "diagnosticCount": 1,
+ "exceptionEscaped": false,
+ "topologyCounts": {
+ "vertices": 0,
+ "edges": 0,
+ "faces": 0
+ },
+ "tessellationCounts": {
+ "facePatches": 0,
+ "edgePolylines": 0
+ },
+ "canonicalSha256": null
+ },
+ {
+ "fileId": "testdata_step242_nist_CTC_nist_ctc_04_asme1_ap242-e1",
+ "path": "testdata/step242/nist/CTC/nist_ctc_04_asme1_ap242-e1.stp",
+ "sizeBytes": 1265846,
+ "status": "parseFail",
+ "firstFailureLayer": "parser",
+ "firstDiagnostic": {
+ "code": "InvalidArgument",
+ "source": "Parser.Lexer",
+ "messagePrefix": "Expected identifier. (position 547)."
+ },
+ "diagnosticCount": 1,
+ "exceptionEscaped": false,
+ "topologyCounts": {
+ "vertices": 0,
+ "edges": 0,
+ "faces": 0
+ },
+ "tessellationCounts": {
+ "facePatches": 0,
+ "edgePolylines": 0
+ },
+ "canonicalSha256": null
+ },
+ {
+ "fileId": "testdata_step242_nist_CTC_nist_ctc_05_asme1_ap242-e1",
+ "path": "testdata/step242/nist/CTC/nist_ctc_05_asme1_ap242-e1.stp",
+ "sizeBytes": 863826,
+ "status": "parseFail",
+ "firstFailureLayer": "parser",
+ "firstDiagnostic": {
+ "code": "InvalidArgument",
+ "source": "Parser.Lexer",
+ "messagePrefix": "Unsupported value token \u0027N\u0027. (position 415)."
+ },
+ "diagnosticCount": 1,
+ "exceptionEscaped": false,
+ "topologyCounts": {
+ "vertices": 0,
+ "edges": 0,
+ "faces": 0
+ },
+ "tessellationCounts": {
+ "facePatches": 0,
+ "edgePolylines": 0
+ },
+ "canonicalSha256": null
+ },
+ {
+ "fileId": "testdata_step242_nist_FTC_nist_ftc_06_asme1_ap242-e2",
+ "path": "testdata/step242/nist/FTC/nist_ftc_06_asme1_ap242-e2.stp",
+ "sizeBytes": 1960222,
+ "status": "parseFail",
+ "firstFailureLayer": "parser",
+ "firstDiagnostic": {
+ "code": "InvalidArgument",
+ "source": "Parser.Lexer",
+ "messagePrefix": "Expected identifier. (position 4921)."
+ },
+ "diagnosticCount": 1,
+ "exceptionEscaped": false,
+ "topologyCounts": {
+ "vertices": 0,
+ "edges": 0,
+ "faces": 0
+ },
+ "tessellationCounts": {
+ "facePatches": 0,
+ "edgePolylines": 0
+ },
+ "canonicalSha256": null
+ },
+ {
+ "fileId": "testdata_step242_nist_FTC_nist_ftc_07_asme1_ap242-e2",
+ "path": "testdata/step242/nist/FTC/nist_ftc_07_asme1_ap242-e2.stp",
+ "sizeBytes": 1459346,
+ "status": "parseFail",
+ "firstFailureLayer": "parser",
+ "firstDiagnostic": {
+ "code": "InvalidArgument",
+ "source": "Parser.Lexer",
+ "messagePrefix": "Expected identifier. (position 547)."
+ },
+ "diagnosticCount": 1,
+ "exceptionEscaped": false,
+ "topologyCounts": {
+ "vertices": 0,
+ "edges": 0,
+ "faces": 0
+ },
+ "tessellationCounts": {
+ "facePatches": 0,
+ "edgePolylines": 0
+ },
+ "canonicalSha256": null
+ },
+ {
+ "fileId": "testdata_step242_nist_FTC_nist_ftc_08_asme1_ap242-e1-tg",
+ "path": "testdata/step242/nist/FTC/nist_ftc_08_asme1_ap242-e1-tg.stp",
+ "sizeBytes": 2120356,
+ "status": "parseFail",
+ "firstFailureLayer": "parser",
+ "firstDiagnostic": {
+ "code": "InvalidArgument",
+ "source": "Parser.Lexer",
+ "messagePrefix": "Expected identifier. (position 1030)."
+ },
+ "diagnosticCount": 1,
+ "exceptionEscaped": false,
+ "topologyCounts": {
+ "vertices": 0,
+ "edges": 0,
+ "faces": 0
+ },
+ "tessellationCounts": {
+ "facePatches": 0,
+ "edgePolylines": 0
+ },
+ "canonicalSha256": null
+ },
+ {
+ "fileId": "testdata_step242_nist_FTC_nist_ftc_08_asme1_ap242-e2",
+ "path": "testdata/step242/nist/FTC/nist_ftc_08_asme1_ap242-e2.stp",
+ "sizeBytes": 4658022,
+ "status": "parseFail",
+ "firstFailureLayer": "parser",
+ "firstDiagnostic": {
+ "code": "InvalidArgument",
+ "source": "Parser.Lexer",
+ "messagePrefix": "Unsupported value token \u0027*\u0027. (position 438)."
+ },
+ "diagnosticCount": 1,
+ "exceptionEscaped": false,
+ "topologyCounts": {
+ "vertices": 0,
+ "edges": 0,
+ "faces": 0
+ },
+ "tessellationCounts": {
+ "facePatches": 0,
+ "edgePolylines": 0
+ },
+ "canonicalSha256": null
+ },
+ {
+ "fileId": "testdata_step242_nist_FTC_nist_ftc_09_asme1_ap242-e1",
+ "path": "testdata/step242/nist/FTC/nist_ftc_09_asme1_ap242-e1.stp",
+ "sizeBytes": 6057450,
+ "status": "parseFail",
+ "firstFailureLayer": "parser",
+ "firstDiagnostic": {
+ "code": "InvalidArgument",
+ "source": "Parser.Lexer",
+ "messagePrefix": "Expected identifier. (position 746)."
+ },
+ "diagnosticCount": 1,
+ "exceptionEscaped": false,
+ "topologyCounts": {
+ "vertices": 0,
+ "edges": 0,
+ "faces": 0
+ },
+ "tessellationCounts": {
+ "facePatches": 0,
+ "edgePolylines": 0
+ },
+ "canonicalSha256": null
+ },
+ {
+ "fileId": "testdata_step242_nist_FTC_nist_ftc_10_asme1_ap242-e2",
+ "path": "testdata/step242/nist/FTC/nist_ftc_10_asme1_ap242-e2.stp",
+ "sizeBytes": 1855829,
+ "status": "parseFail",
+ "firstFailureLayer": "parser",
+ "firstDiagnostic": {
+ "code": "InvalidArgument",
+ "source": "Parser.Lexer",
+ "messagePrefix": "Expected identifier. (position 553)."
+ },
+ "diagnosticCount": 1,
+ "exceptionEscaped": false,
+ "topologyCounts": {
+ "vertices": 0,
+ "edges": 0,
+ "faces": 0
+ },
+ "tessellationCounts": {
+ "facePatches": 0,
+ "edgePolylines": 0
+ },
+ "canonicalSha256": null
+ },
+ {
+ "fileId": "testdata_step242_nist_FTC_nist_ftc_11_asme1_ap242-e2",
+ "path": "testdata/step242/nist/FTC/nist_ftc_11_asme1_ap242-e2.stp",
+ "sizeBytes": 1920822,
+ "status": "parseFail",
+ "firstFailureLayer": "parser",
+ "firstDiagnostic": {
+ "code": "InvalidArgument",
+ "source": "Parser.Lexer",
+ "messagePrefix": "Unsupported value token \u0027*\u0027. (position 498)."
+ },
+ "diagnosticCount": 1,
+ "exceptionEscaped": false,
+ "topologyCounts": {
+ "vertices": 0,
+ "edges": 0,
+ "faces": 0
+ },
+ "tessellationCounts": {
+ "facePatches": 0,
+ "edgePolylines": 0
+ },
+ "canonicalSha256": null
+ },
+ {
+ "fileId": "testdata_step242_nist_STC_nist_stc_06_asme1_ap242-e3",
+ "path": "testdata/step242/nist/STC/nist_stc_06_asme1_ap242-e3.stp",
+ "sizeBytes": 993459,
+ "status": "parseFail",
+ "firstFailureLayer": "parser",
+ "firstDiagnostic": {
+ "code": "InvalidArgument",
+ "source": "Parser.Lexer",
+ "messagePrefix": "Expected identifier. (position 414)."
+ },
+ "diagnosticCount": 1,
+ "exceptionEscaped": false,
+ "topologyCounts": {
+ "vertices": 0,
+ "edges": 0,
+ "faces": 0
+ },
+ "tessellationCounts": {
+ "facePatches": 0,
+ "edgePolylines": 0
+ },
+ "canonicalSha256": null
+ },
+ {
+ "fileId": "testdata_step242_nist_STC_nist_stc_07_asme1_ap242-e3",
+ "path": "testdata/step242/nist/STC/nist_stc_07_asme1_ap242-e3.stp",
+ "sizeBytes": 1927905,
+ "status": "parseFail",
+ "firstFailureLayer": "parser",
+ "firstDiagnostic": {
+ "code": "InvalidArgument",
+ "source": "Parser.Lexer",
+ "messagePrefix": "Unsupported value token \u0027P\u0027. (position 686)."
+ },
+ "diagnosticCount": 1,
+ "exceptionEscaped": false,
+ "topologyCounts": {
+ "vertices": 0,
+ "edges": 0,
+ "faces": 0
+ },
+ "tessellationCounts": {
+ "facePatches": 0,
+ "edgePolylines": 0
+ },
+ "canonicalSha256": null
+ },
+ {
+ "fileId": "testdata_step242_nist_STC_nist_stc_08_asme1_ap242-e3",
+ "path": "testdata/step242/nist/STC/nist_stc_08_asme1_ap242-e3.stp",
+ "sizeBytes": 2239112,
+ "status": "parseFail",
+ "firstFailureLayer": "parser",
+ "firstDiagnostic": {
+ "code": "InvalidArgument",
+ "source": "Parser.Lexer",
+ "messagePrefix": "Unsupported value token \u0027S\u0027. (position 4808)."
+ },
+ "diagnosticCount": 1,
+ "exceptionEscaped": false,
+ "topologyCounts": {
+ "vertices": 0,
+ "edges": 0,
+ "faces": 0
+ },
+ "tessellationCounts": {
+ "facePatches": 0,
+ "edgePolylines": 0
+ },
+ "canonicalSha256": null
+ },
+ {
+ "fileId": "testdata_step242_nist_STC_nist_stc_09_asme1_ap242-e3",
+ "path": "testdata/step242/nist/STC/nist_stc_09_asme1_ap242-e3.stp",
+ "sizeBytes": 5237528,
+ "status": "parseFail",
+ "firstFailureLayer": "parser",
+ "firstDiagnostic": {
+ "code": "InvalidArgument",
+ "source": "Parser.Lexer",
+ "messagePrefix": "Expected identifier. (position 734)."
+ },
+ "diagnosticCount": 1,
+ "exceptionEscaped": false,
+ "topologyCounts": {
+ "vertices": 0,
+ "edges": 0,
+ "faces": 0
+ },
+ "tessellationCounts": {
+ "facePatches": 0,
+ "edgePolylines": 0
+ },
+ "canonicalSha256": null
+ },
+ {
+ "fileId": "testdata_step242_nist_STC_nist_stc_10_asme1_ap242-e2",
+ "path": "testdata/step242/nist/STC/nist_stc_10_asme1_ap242-e2.stp",
+ "sizeBytes": 4807322,
+ "status": "parseFail",
+ "firstFailureLayer": "parser",
+ "firstDiagnostic": {
+ "code": "InvalidArgument",
+ "source": "Parser.Lexer",
+ "messagePrefix": "Unsupported value token \u0027*\u0027. (position 1005)."
+ },
+ "diagnosticCount": 1,
+ "exceptionEscaped": false,
+ "topologyCounts": {
+ "vertices": 0,
+ "edges": 0,
+ "faces": 0
+ },
+ "tessellationCounts": {
+ "facePatches": 0,
+ "edgePolylines": 0
+ },
+ "canonicalSha256": null
+ }
+]