Skip to content

fix(cli,core): npm --scene/--view parity, GLB sRGB->linear, clamp warnings, and strict exit code 3 (Fixes #58, #82, #83, #84) - #101

Merged
wrong-nebula merged 2 commits into
wrong-nebula:mainfrom
capncoconut:fix/tier1-cli-glb-diagnostics
Dec 4, 2026

Conversation

@capncoconut

Copy link
Copy Markdown
Contributor

Summary

Resolves four focused CLI, export, and diagnostic issues with regression tests, zero external dependencies, and 0 extra forma-mcp schema tokens:

1. npm/WASM CLI --scene rendering & --view parity (Fixes #58)

  • Wired bin/forma.mjs so --scene routes --render through session.exportScenePngBytes(renderSize, renderView) and --draw through session.exportSceneSvg(), bringing the npm CLI in line with the native Rust CLI (crates/forma-cli/src/main.rs).
  • Added --view <quad|front|back|right|left|top|iso> support to forma-wasm (forma_session_export_png_view, forma_session_export_scene_png_view), lib/edge.mjs, lib/index.d.ts, bin/forma.mjs, and docs/reference/cli.md (plus Scene::render_preview_scene_view_bytes).

2. Consistent sRGB color space between PNG preview and glTF 2.0 baseColorFactor (Fixes #82)

  • Added exact IEC 61966-2-1 srgb_to_linear / linear_to_srgb helpers in crates/forma-core/src/export.rs.
  • Converted Material::color RGB channels from sRGB to linear when writing baseColorFactor in both single-part (write_glb_bytes_with_unit) and multi-part scene (write_scene_glb_bytes_with_unit) GLB exporters (alpha stays linear per glTF 2.0 spec).
  • Converted baseColorFactor RGB channels from linear back to sRGB in crates/forma-core/src/import.rs so GLB export → import round-trips losslessly and imported models preview accurately.

3. Emit clamp warnings for out-of-range subsurf(levels) and bevel(w, segs) (Fixes #83)

  • subsurf(levels > 4) now emits subsurf: levels=<N> clamped to 4 (supported range 0..=4) in both Forma-Pipe (pipeline.rs) and Compact DSL (Scene::subsurf).
  • bevel_edges_with_warning (crates/forma-core/src/ops.rs) now reports warnings when segs is clamped outside 1..=8 or when width is clamped to fit edge geometry across all three bevel paths (try_bevel_vertical_prism, try_bevel_z_rims, bevel_general_polyhedron), and Scene::bevel propagates them to eval_warnings.

4. Return documented exit code 3 on --strict invariant failures (Fixes #84)

  • Added forma_lang::is_invariant_violation_err and updated both native crates/forma-cli/src/main.rs and WASM bin/forma.mjs so strict invariant rollbacks (SceneError::InvariantViolation) exit with code 3 while script/syntax/I/O errors keep exiting with code 1 and invalid CLI usage exits 2.
  • Updated docs/reference/cli.md exit code table for consistency.

(Note: wasm/forma.wasm is intentionally left unmodified in git so CI rebuilds and wasm-opt -Oz optimizes it cleanly, matching recent PRs; also made the SKILL.md fence regex in tests/npm_smoke.mjs handle CRLF checkouts on Windows.)

Verification

  • Added test_issue_82_glb_base_color_srgb_to_linear_roundtrip in crates/forma-core/tests/kernel_tests.rs.
  • Added issue_83_subsurf_levels_and_bevel_width_emit_clamp_warnings in crates/forma-lang/tests/audit_regressions.rs.
  • Added crates/forma-cli/tests/cli_exit_codes.rs covering exit codes 0, 1, 2, and 3 (text and --json).
  • Extended tests/npm_smoke.mjs to test --scene multi-part PNG/SVG, --view, and exit codes 1/2/3 on bin/forma.mjs.
  • Ran full Rust CI suite:
    cargo test --locked --release -p forma-core -p forma-lang -p forma-cli -p forma-mcp -p forma-server -- --skip test_10000_fuzzed_modeling_operations_zero_crashes_zero_nans
    → All passed.
  • Rebuilt forma-wasm (--profile wasm-release --target wasm32-unknown-unknown) and ran node tests/npm_smoke.mjs:
    → 5/5 passed (then reverted wasm/forma.wasm before committing).

# Conflicts:
#	crates/forma-cli/src/main.rs
#	crates/forma-core/src/scene.rs
#	crates/forma-core/tests/kernel_tests.rs
#	crates/forma-lang/tests/audit_regressions.rs
#	lib/index.d.ts
#	tests/npm_smoke.mjs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants