fix: parser correctness + CLI error UX - #6
Merged
Conversation
Parser correctness (ThreeMFMeshParser, STLParser, GCodeParser): - Guard Int(Float) traps in STL vertex quantize and G-code ETA — a crafted file (NaN/Inf/huge coords) crashed the Quick Look preview (DoS). - Compose 3MF <component> transforms for inline and separate-file assemblies, cycle-guarded. Previously component transforms were dropped and only the first sub-mesh rendered, so assemblies appeared at the origin / incomplete. - Inherit object-level material (pid/pindex) so single-color core-spec objects render colored instead of gray. CLI error UX (Sources/CLI): - resolveFormat throws a clear "unsupported format" error (listing .3mf/.stl/ .gcode) instead of a misleading .3mf parse failure on unknown extensions. - resolveSize rejects non-numeric / <=0 / oversized --size instead of a silent 512 default or a broken 0x0 render. - Fix stale usage text and batch error type; document exit codes (0/1/2). - Make CLI logic unit-testable (CLI.swift compiled into the test target). Adds regression tests across every fix. 73 tests, 0 failures.
Pre-existing repo-wide lint drift: CI installs swiftformat unpinned (`brew install swiftformat`), and a newer release added stricter default rules (wrapIfStatementBodies, docComments, elseOnSameLine, …). 18/35 files fell out of conformance — most untouched by this PR. This is the first PR to run test.yml since the drift (Dependabot PRs only touched .github/workflows). Mechanical, format-only (no logic change); `swiftformat Sources Tests --lint` now passes clean. Tests unchanged: 73 passing. Note: CI should pin the swiftformat version to prevent this recurring (requires the `workflow` scope to edit .github/workflows/test.yml).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Non-crash correctness fixes across the 3MF/STL/G-code parsers, plus CLI error-UX hardening. Split out from the session's audit work. Bambu/Orca (the primary path) is unaffected — verified by the existing color/plate suites staying green.
Parser correctness
STLParser,GCodeParser): a crafted file with NaN/Inf/huge coordinates could trapInt32(Float)/Int(Float)and crash the Quick Look preview (a DoS). STL vertex quantize and the G-code ETA now guardisFinite+ clamp.<component>transform composition (ThreeMFMeshParser): component transforms were parsed but never applied — multi-part assemblies rendered at the origin, and only the first sub-mesh appeared. Now recursively expanded and composed (inline + separate-file), cycle-guarded against circular references.<object pid pindex>was ignored, so single-color core-spec exports rendered gray. Triangles now inherit the object default.CLI error UX (
Sources/CLI)Unsupported file format: .txt (expected .3mf, .stl, or .gcode)instead of a misleading ".3mf archive" error.--sizevalidates (rejects non-numeric /0/ oversized) instead of a silent 512 default or a broken 0×0 render.0success ·1runtime ·2usage).CLI.swiftcompiled into the test target).Tests
Regression tests added for every fix (STL/G-code crash inputs, component composition inline + separate-file, object-level material, CLI resolveFormat/resolveSize/missing/unsupported). 73 tests, 0 failures via
xcodebuild ... -scheme ThreeMFTests test. CLI also verified end-to-end against the built binary (messages + exit codes).