Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Close silent-acceptance gaps found by the 2.0.0 fuzz pass
Claude25795d16af4d
diff --git a/Aetheris.CLI.Tests/SourceIntentClosureRegressionTests.cs b/Aetheris.CLI.Tests/SourceIntentClosureRegressionTests.csnew file mode 100644index 00000000..7b503708--- /dev/null+++ b/Aetheris.CLI.Tests/SourceIntentClosureRegressionTests.cs@@ -0,0 +1,67 @@+using Aetheris.CLI;++namespace Aetheris.CLI.Tests;++/// <summary>+/// Regressions from the 2.0.0 release fuzz pass: each case was silently accepted (validate exit 0)+/// before the fix. Source that the binder would ignore or that is outside the finite range must be+/// rejected with a diagnostic naming the problem.+/// </summary>+public sealed class SourceIntentClosureRegressionTests+{+ [Theory]+ // Non-finite numeric literals and the NaN/Infinity identifiers.+ [InlineData("Pipeline/line-arc-profile.firmament", "Line Bottom { length: 30mm }", "Line Bottom { length: 1e309mm }", "firmament-number-not-finite")]+ [InlineData("Pipeline/line-arc-profile.firmament", "Arc Right { Radius: 8mm;", "Arc Right { Radius: NaN;", "firmament-number-not-finite")]+ // Concept Path segment bodies (also used by circular sweep paths).+ [InlineData("Pipeline/line-arc-profile.firmament", "Arc Right { Radius: 8mm;", "Arc Right { Radiuz: 8mm;", "concept-path-field-unknown")]+ [InlineData("Features/Sweep/circular-line-sweep.firmament", "Line Stock { length: 40mm }", "Line Stock { length: 40mm; zzUnknownField: 3mm }", "concept-path-field-unknown")]+ // Pmi block fields.+ [InlineData("Templates/nested-template-pmi.firmament", " Pmi {", " Pmi { zzUnknownField: 3mm;", "firmament-v2-pmi-unknown-field")]+ // Profile body fields (From remains the derived-boundary form).+ [InlineData("Profiles/rect2-profile-extrusion.firmament", "Profile MainPlate using Rect2Layout {", "Profile MainPlate using Rect2Layout { zzUnknownField: 3mm;", "Profile:zzUnknownField")]+ // Modify targeting a composed body.+ [InlineData("Learn/03-machined-block.firmament", "Modify body {", "Modify body { zzUnknownField: 3mm;", "Modify:zzUnknownField")]+ // Hole<Shaft> inside a materialized Template struct.+ [InlineData("Templates/cnc-dfm-policy.firmament", "Hole<Shaft> Probe {", "Hole<Shaft> Probe { zzUnknownField: 3mm;", "Hole:zzUnknownField")]+ public void MutatedCanonicalSource_IsRejected(string fixture, string anchor, string replacement, string expectedCode)+ {+ var original = File.ReadAllText(Path.Combine(RepoRoot(), "fixtures", "Canonical", fixture));+ Assert.Contains(anchor, original, StringComparison.Ordinal);+ Assert.Equal(0, Validate(original, fixture).ExitCode);++ var index = original.IndexOf(anchor, StringComparison.Ordinal);+ var mutated = original[..index] + replacement + original[(index + anchor.Length)..];+ var (exitCode, output) = Validate(mutated, fixture);++ Assert.NotEqual(0, exitCode);+ Assert.Contains(expectedCode, output, StringComparison.Ordinal);+ }++ private static (int ExitCode, string Output) Validate(string source, string fixture)+ {+ // Keep the file beside the original so relative imports still resolve.+ var directory = Path.GetDirectoryName(Path.Combine(RepoRoot(), "fixtures", "Canonical", fixture))!;+ var path = Path.Combine(directory, $".closure-{Guid.NewGuid():N}.firmament");+ File.WriteAllText(path, source);+ try+ {+ var stdout = new StringWriter();+ var stderr = new StringWriter();+ var exitCode = CliRunner.Run(["validate", path], stdout, stderr);+ return (exitCode, stdout.ToString() + stderr);+ }+ finally+ {+ File.Delete(path);+ }+ }++ private static string RepoRoot()+ {+ var directory = new DirectoryInfo(AppContext.BaseDirectory);+ while (directory is not null && !File.Exists(Path.Combine(directory.FullName, "Aetheris.slnx")))+ directory = directory.Parent;+ return directory?.FullName ?? throw new InvalidOperationException("Repository root not found.");+ }+}diff --git a/Aetheris.CLI/Aetheris.CLI.csproj b/Aetheris.CLI/Aetheris.CLI.csprojindex 17621f47..e7733828 100644--- a/Aetheris.CLI/Aetheris.CLI.csproj+++ b/Aetheris.CLI/Aetheris.CLI.csproj@@ -38,4 +38,12 @@<ItemGroup><None Include="..\docs\release\Aetheris.CLI.README.md" Pack="true" PackagePath="\" Link="Aetheris.CLI.README.md" /></ItemGroup>+ <!-- Native packages such as SkiaSharp ship ~90 MB debug symbols per Windows RID. They are+ not needed at run time and push the tool package past nuget.org's 250 MB limit. -->+ <Target Name="ExcludeNativeDebugSymbols" AfterTargets="ResolvePackageAssets">+ <ItemGroup>+ <RuntimeTargetsCopyLocalItems Remove="@(RuntimeTargetsCopyLocalItems)" Condition="'%(Extension)' == '.pdb'" />+ <NativeCopyLocalItems Remove="@(NativeCopyLocalItems)" Condition="'%(Extension)' == '.pdb'" />+ </ItemGroup>+ </Target></Project>diff --git a/Aetheris.Kernel.Firmament.Tests/Assembly/CoaxialDatumTests.cs b/Aetheris.Kernel.Firmament.Tests/Assembly/CoaxialDatumTests.csindex e07082cb..f44a4261 100644--- a/Aetheris.Kernel.Firmament.Tests/Assembly/CoaxialDatumTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/Assembly/CoaxialDatumTests.cs@@ -117,7 +117,7 @@ public sealed class CoaxialDatumTests[InlineData("At: 7mm","At: 7mm; At: 8mm","assembly-datum-measure-invalid")][InlineData("Mate GripOnSpindle:","Mate SkirtOnSpindle:","assembly-datum-mate-duplicate")][InlineData("Clocking: 30deg","Clocking: 30deg; Support: true","assembly-datum-fields-invalid")]- [InlineData("Reference: [0,3,1]","Reference: [0,NaN,1]","assembly-datum-vector-invalid")]+ [InlineData("Reference: [0,3,1]","Reference: [0,NaN,1]","firmament-number-not-finite")][InlineData("Controls.VolumeKnob.Spindle]","Controls.VolumeKnob.Mount]","assembly-datum-member-outside-contract")][InlineData("Member: Controls.VolumeKnob.Spindle","Member: Controls.VolumeKnob.KnobSkirt.SpindleSeat","assembly-datum-member-scope")][InlineData("[Controls.VolumeKnob.Spindle]","[Controls.VolumeKnob.Spindle,Controls.Other.Spindle]","assembly-axis-revolute-member-count")]diff --git a/Aetheris.Kernel.Firmament.Tests/Assembly/LinearStationAuthoringTests.cs b/Aetheris.Kernel.Firmament.Tests/Assembly/LinearStationAuthoringTests.csindex 6d61572f..5bfa8be0 100644--- a/Aetheris.Kernel.Firmament.Tests/Assembly/LinearStationAuthoringTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/Assembly/LinearStationAuthoringTests.cs@@ -96,7 +96,7 @@ public sealed class LinearStationAuthoringTests{var parsed = new AssemblyM0Parser().Parse(Source.ReplaceRequired(from, to));Assert.False(parsed.IsSuccess);- Assert.Contains(parsed.Diagnostics, d => d.Message.Contains("firmament-concept-points-"));+ Assert.Contains(parsed.Diagnostics, d => d.Message.Contains("firmament-concept-points-") || d.Code == "firmament-number-not-finite");}[Fact]diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/ConceptIr.cs b/Aetheris.Kernel.Firmament/FirmamentV2/ConceptIr.csindex b66a98b3..4ba0b7d4 100644--- a/Aetheris.Kernel.Firmament/FirmamentV2/ConceptIr.cs+++ b/Aetheris.Kernel.Firmament/FirmamentV2/ConceptIr.cs@@ -311,8 +311,16 @@ internal static class ConceptIrResolverboxFields.Complete();var modifySyntax = syntaxDeclarations.FirstOrDefault(d => d.Type.Name.Text == "Modify" && d.Body?.Span.Start == modifyOpen);foreach (var statement in modifySyntax?.Body?.Statements ?? [])+ {if (statement is not DeclarationSyntax feature || !(feature.Type.Name.Text.Equals("Hole", StringComparison.OrdinalIgnoreCase) || feature.Type.Name.Text is "Pattern" or "EdgeFinish"))diagnostics.Add($"{FirmamentV2Parser.CanonicalDeclarationUnknown}:Modify:{(statement as DeclarationSyntax)?.Type.Name.Text ?? "expression"}");+ // The hole reader below looks fields up by name, so any other field would be+ // dropped silently. This path admits shaft holes with exactly these fields.+ else if (feature.Type.Name.Text.Equals("Hole", StringComparison.OrdinalIgnoreCase))+ foreach (var holeField in feature.Body?.Statements.OfType<FieldSyntax>() ?? [])+ if (!ConceptHoleFields.Any(name => FirmamentSyntaxFields.SameField(holeField.Name.Text, name)))+ diagnostics.Add($"{FirmamentV2Parser.CanonicalFieldUnknown}:Hole:{holeField.Name.Text}");+ }IReadOnlyList<double>? size = null;ConceptIrBox3Value? resolvedBounds = null;string boundsProvenance;@@ -433,6 +441,8 @@ internal static class ConceptIrResolverplane = resolved; return true;}+ private static readonly string[] ConceptHoleFields = ["From", "On", "Center", "Diameter", "End", "Termination"];+private static IReadOnlyList<FirmamentV2SemanticHoleDecl> ParseConceptHoles(string body,int bodyOffset,diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2MechanicalBinding.cs b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2MechanicalBinding.csindex e37b4295..a1e19da9 100644--- a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2MechanicalBinding.cs+++ b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2MechanicalBinding.cs@@ -574,6 +574,13 @@ public static partial class FirmamentV2Parsercase "Struct" when declaration.Annotation is not null: break;case "Struct" when !declaration.Modifiers.Any(m => m.Name.Text == "Concept"):BindMechanicalScope(declaration.Body?.Statements ?? [], diagnostics); break;+ case "Profile" when declaration.Body is not null:+ // A Profile body holds loops. Its readers look for Loop headers, so a+ // field here would otherwise be dropped without a diagnostic.+ // `From` is the derived-boundary form (`Profile copy { From: outline }`).+ foreach (var profileField in declaration.Body.Statements.OfType<FieldSyntax>().Where(f => !FirmamentSyntaxFields.SameField(f.Name.Text, "From")))+ diagnostics.Add($"{CanonicalFieldUnknown}:Profile:{profileField.Name.Text}");+ break;case "Box" or "Cylinder" or "Cone" or "Sphere" or "Ellipsoid" or "Polyhedron" or "Torus" or "RoundedBox" or "Frustum" or "StandardPart" or "ExactCoaxialPart":case "Plane" or "Axis" or "Axis2" or "Point2" or "Line2" or "CubicBezier2" or "Rect2" or "Square2" or "Triangle2" or "Polygon2" or "RegularPolygon2" or "Circle2" or "Ellipse2" or "Ellipse2Guide" or "Slot2" or "RoundedRect2" or "SmoothRoundedRect2" or "Path":case "Plateau" or "Concept" or "Struct" or "Profile" or "Span" or "Compose" or "Boss" or "Pocket" or "AddOffset" or "RemoveOffset" or "EdgeFinish" or "Extrude":diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Parser.cs b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Parser.csindex 71f237e6..f76835c4 100644--- a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Parser.cs+++ b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Parser.cs@@ -2350,6 +2350,12 @@ public static partial class FirmamentV2Parservar matches = PmiHeaderRegex.Matches(source);if (matches.Count == 0) return ([], null, null);if (matches.Count > 1) diagnostics.Add(PmiDuplicateBlock);+ // The entry reader below matches record headers, so anything else in the block+ // (a field, an expression) would otherwise be dropped without a diagnostic.+ foreach (var pmiBlock in FirmamentSyntaxTraversal.Declarations(FirmamentSyntaxParser.Parse(source).Document).Where(d => d.Type.Name.Text == "Pmi" && d.Name is null))+ foreach (var statement in pmiBlock.Body?.Statements ?? [])+ if (statement is FieldSyntax field) diagnostics.Add($"{PmiUnknownField}:{field.Name.Text}");+ else if (statement is not DeclarationSyntax { Name: not null }) diagnostics.Add($"{PmiUnknownField}:statement");var match = matches[0];var open = source.IndexOf('{', match.Index);var close = FindMatchingBrace(source, open);diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/ProfileAuthoringParser.cs b/Aetheris.Kernel.Firmament/FirmamentV2/ProfileAuthoringParser.csindex 5e409cf4..b472677b 100644--- a/Aetheris.Kernel.Firmament/FirmamentV2/ProfileAuthoringParser.cs+++ b/Aetheris.Kernel.Firmament/FirmamentV2/ProfileAuthoringParser.cs@@ -662,6 +662,14 @@ public static class ProfileAuthoringParsercurves = [new LineArcLineSegment2D(current, endpoint)]; headingDegrees = Heading(current, endpoint); return true;}var body = step.Body;+ if (step.Kind is "Line" or "Span" or "Arc")+ {+ // Segment bodies are read by name; reject anything the binder would silently ignore.+ string[] allowed = step.Kind == "Arc" ? ["Radius", "Turn"] : ["Turn", "Heading", "Length", "To"];+ var unknown = Regex.Matches(body ?? string.Empty, @"(?<![\w.])(?<n>[A-Za-z_]\w*)\s*:", RegexOptions.CultureInvariant)+ .Select(m => m.Groups["n"].Value).FirstOrDefault(n => !allowed.Contains(n, StringComparer.Ordinal));+ if (unknown is not null) { diagnostic = $"concept-path-field-unknown:{path}:{step.Name}:{unknown}:allowed={string.Join(",", allowed)}"; return false; }+ }var turn = Property(body, "Turn"); var absolute = Property(body, "Heading"); var length = Property(body, "Length"); var to = Property(body, "To");if (step.Kind is "Line" or "Span"){diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/Syntax/FirmamentSyntaxParser.cs b/Aetheris.Kernel.Firmament/FirmamentV2/Syntax/FirmamentSyntaxParser.csindex d8ca8c9f..16f4d93c 100644--- a/Aetheris.Kernel.Firmament/FirmamentV2/Syntax/FirmamentSyntaxParser.cs+++ b/Aetheris.Kernel.Firmament/FirmamentV2/Syntax/FirmamentSyntaxParser.cs@@ -414,6 +414,8 @@ public static class FirmamentSyntaxParser{var t = Current; at++;left = new LiteralSyntax(t.Kind == SyntaxTokenKind.String ? LiteralKind.String : t.Kind == SyntaxTokenKind.Number ? LiteralKind.Number : LiteralKind.Boolean, t.Text, t.Span);+ if (t.Kind == SyntaxTokenKind.Number && !IsFiniteNumber(t.Text))+ Error("firmament-number-not-finite", $"'{t.Text}' is outside the finite double range. Use a finite value.", t.Span);if (t.Kind == SyntaxTokenKind.Number && Current.Kind == SyntaxTokenKind.Number && Current.Text.StartsWith('.')&& (t.Span.Start + t.Span.Length) == Current.Span.Start && t.Text.Count(c => c == '.') == 1){ at++; left = new LiteralSyntax(LiteralKind.Version, source[start..(Previous.Span.Start + Previous.Span.Length)], Span(start)); }@@ -449,6 +451,10 @@ public static class FirmamentSyntaxParserelse if (Current.Kind == SyntaxTokenKind.Identifier){var name = Identifier(); left = new ReferenceSyntax(name, name.Span);+ // .NET parses "NaN" and "Infinity" as numbers, so a value reader that falls back to+ // double.TryParse would turn these names into non-finite geometry input.+ if (double.TryParse(name.Text, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out _))+ Error("firmament-number-not-finite", $"'{name.Text}' is not a finite number. Use a finite value.", name.Span);var compatibilityDepthEnd = name.Text == "depth" && at >= 3 && tokens[at - 2].Text == ":" && tokens[at - 3].Text is "end" or "End";if ((name.Text is "Blind" or "CenteredAt" || compatibilityDepthEnd) && !Is("(") && !Is(">") && !Is(",") && !LineBreak){@@ -657,6 +663,8 @@ public static class FirmamentSyntaxParserat++;}}+ private static bool IsFiniteNumber(string text) =>+ !double.TryParse(text, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out var value) || double.IsFinite(value);private ParseFailure Fail(string code, string message) { Error(code, message, Current.Span); return new(); }private void Error(string code, string message, FirmamentV2SourceSpan span){diff --git a/Aetheris.Kernel.Firmament/Materializer/PrismaticProfileComposition.cs b/Aetheris.Kernel.Firmament/Materializer/PrismaticProfileComposition.csindex 3b132951..772654be 100644--- a/Aetheris.Kernel.Firmament/Materializer/PrismaticProfileComposition.cs+++ b/Aetheris.Kernel.Firmament/Materializer/PrismaticProfileComposition.cs@@ -1130,6 +1130,13 @@ public static class PrismaticProfileCompositionParserprivate static string BindExternalModifyFeatures(string source, string composeName, string composeBody, List<string> diagnostics){var boundFeatures = new List<string>();+ // Modify holds feature declarations only. The readers below look for feature+ // headers, so a stray field in the block would otherwise vanish.+ foreach (var modifySyntax in FirmamentV2.Syntax.FirmamentSyntaxTraversal.Declarations(FirmamentV2.Syntax.FirmamentSyntaxParser.Parse(source).Document)+ .Where(d => d.Type.Name.Text == "Modify" && d.Name?.Text == composeName))+ foreach (var statement in modifySyntax.Body?.Statements ?? [])+ if (statement is FirmamentV2.Syntax.FieldSyntax field) diagnostics.Add($"{FirmamentV2Parser.CanonicalFieldUnknown}:Modify:{field.Name.Text}");+ else if (statement is not FirmamentV2.Syntax.DeclarationSyntax) diagnostics.Add(FirmamentV2Parser.CanonicalModifyMalformed);foreach (Match modify in ModifyHead.Matches(source)){var body = Block(source, source.IndexOf('{', modify.Index));