Skip to content

refactor(gcode): read G-code into the Motion IR at the CLI/API boundary (S-bnd) - #283

Merged
CameronBrooks11 merged 1 commit into
mainfrom
refactor/motion-ir-boundary-reader
Jun 28, 2026
Merged

CameronBrooks11 merged 1 commit into
mainfrom
refactor/motion-ir-boundary-reader

Conversation

@CameronBrooks11

Copy link
Copy Markdown
Member

S-bnd of #136 — closes #282.

Introduces fiberpath/gcode/reader.py::read_program, the single G-code text→Program adapter (inverse of serialize). The simulator and plotter now consume the typed Motion IR; the CLI simulate/plot and the /simulate+/plot routes parse once at the boundary. The two duplicated _detect_dialect copies and the plotter's ast.literal_eval header parse collapse into the reader — read_program is the only G-code text parser left (verifiable by grep).

Output-preserving by design

Both consumers reproduce today's numbers exactly (the simulator stays G92-blind — marked minimal: for S3; the plotter is unchanged), so the gate is a green sim_plot_snapshot.json with no regen — the proof the reader is faithful, mirroring #274's empty-diff gate. The deliberate metric deltas (G92-aware time, O1 unification) land next as isolated regens in S3 (simulator shares nominal_metrics) and S4 (plotter geometry).

Acceptance — all green

  • New tests/gcode/test_reader_roundtrip.py: serialize(read_program(g)) == g byte-for-byte on all 7 frozen goldens + unit tests (header, comment, G92, feed, mixed feed+motion, XYZ rejection).
  • test_example_goldens byte-equal (untouched) · sim_plot_snapshot.json green without FIBERPATH_UPDATE_GOLDENS.
  • 152 passed · ruff + ruff format + mypy clean · no OpenAPI drift (request/response contracts unchanged) · GUI {gcode}→/plot unaffected.

Part of #136. Followed by S3 (simulator), S4 (plotter), S5 (delete dead parsers + CI guard).

Introduce `read_program` — the single G-code text->Program adapter and the
inverse of `serialize` — so the simulator and plotter consume the typed Motion
IR instead of each re-parsing text. The CLI `simulate`/`plot` commands and the
`/simulate`+`/plot` routes parse once at the boundary; the external-`.gcode`
use case and the GUI `{gcode}->/plot` path are unchanged.

This slice is deliberately output-preserving: both consumers reproduce today's
numbers exactly (the simulator stays G92-blind, marked `minimal:` for S3; the
plotter is unchanged), so `sim_plot_snapshot.json` stays green without regen —
the proof that the reader is faithful, mirroring #274's empty-diff gate. The
new `test_reader_roundtrip` confirms `serialize(read_program(g)) == g`
byte-for-byte on all seven frozen goldens. The two `_detect_dialect` copies and
the plotter's `ast.literal_eval` header parse collapse into the reader.

The deliberate metric deltas (G92-aware time, O1 unification) follow as isolated
regens in S3 (simulator shares nominal_metrics) and S4 (plotter geometry).

Closes #282. Part of #136.
@CameronBrooks11
CameronBrooks11 merged commit 8964637 into main Jun 28, 2026
21 checks passed
@CameronBrooks11
CameronBrooks11 deleted the refactor/motion-ir-boundary-reader branch June 28, 2026 14:41
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.

S-bnd — one boundary G-code→Program reader; simulator & plotter go IR-native

1 participant