Skip to content

fix: parser correctness + CLI error UX - #6

Merged
guanchzhou merged 2 commits into
mainfrom
parser-correctness-and-cli-ux
Aug 3, 2026
Merged

fix: parser correctness + CLI error UX#6
guanchzhou merged 2 commits into
mainfrom
parser-correctness-and-cli-ux

Conversation

@guanchzhou

Copy link
Copy Markdown
Owner

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

  • Int(Float) crash guards (STLParser, GCodeParser): a crafted file with NaN/Inf/huge coordinates could trap Int32(Float)/Int(Float) and crash the Quick Look preview (a DoS). STL vertex quantize and the G-code ETA now guard isFinite + clamp.
  • 3MF <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-level material inheritance: <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 extensions get a clear Unsupported file format: .txt (expected .3mf, .stl, or .gcode) instead of a misleading ".3mf archive" error.
  • --size validates (rejects non-numeric / 0 / oversized) instead of a silent 512 default or a broken 0×0 render.
  • Fixed stale usage text and a mislabeled batch error; documented exit codes (0 success · 1 runtime · 2 usage).
  • CLI logic is now unit-testable (CLI.swift compiled 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).

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).
@guanchzhou
guanchzhou merged commit 760f752 into main Aug 3, 2026
3 checks passed
@guanchzhou
guanchzhou deleted the parser-correctness-and-cli-ux branch August 4, 2026 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant