Skip to content

test: hermetic fake OrcaSlicer stub; de-mock slice tests - #90

Merged
DLANSAMA merged 4 commits into
mainfrom
test/hermetic-orca-stub
Jul 30, 2026
Merged

test: hermetic fake OrcaSlicer stub; de-mock slice tests#90
DLANSAMA merged 4 commits into
mainfrom
test/hermetic-orca-stub

Conversation

@DLANSAMA

Copy link
Copy Markdown
Owner

What

Adds a hermetic fake OrcaSlicer (roadmap C.4) under tests/fakes/orca_stub and rewires slice tests to run the real slicer subprocess path instead of mocking subprocess.Popen / os.path.exists.

Why

slicer/output.py._finalize_slice had the worst mutation gap in the suite (~21%) because its exit-code/3MF-validation branches were only reachable through heavy mocking. The stub lets tests drive those branches through a real process.

How it works

  • tests/fakes/orca_stub/orca_stub.py — a standalone script that mimics the exact Orca CLI surface cmd_slice builds (--load-settings, --load-filaments, --slice, --export-3mf, --outputdir). It recovers the output path the same way the real CLI resolves it and writes a structurally valid sliced .3mf (OPC zip with [Content_Types].xml + 3D/3dmodel.model + Metadata/plate_1.gcode).
  • Scenarios selected via ORCA_STUB_SCENARIO: success, benign_gl (non-zero exit + valid 3mf + GL/thumbnail noise), fail_real_gl (GL noise plus a real slicing error — must not be treated as benign), empty_output, corrupt_output, missing_output, fail, garbage_stdout, progress, hang (timeout).
  • Cross-platform: the launcher embeds sys.executable + the script path — an sh wrapper (chmod +x) on POSIX, a .cmd batch file on Windows — so Popen can run it directly with no shebang/exec-bit reliance on Windows.
  • Wiring uses the existing settings_ctx(orca_slicer=..., profiles_dir=...) DI seam. No bambu_cli/ changes.

Coverage delta on bambu_cli/slicer/ (full suite, term-missing)

file before after
output.py 79.8% 92.7%
cmd.py 78.8% 80.6%

Plus the real _run_orcaslicer process/stdout-pump loop (previously # pragma: no cover) now actually executes. Overall coverage 84.32% -> 84.81% (floor 83).

Tests

tests/test_slice_stub_integration.py (13 tests): valid-3mf write, JSON success envelope, progress/garbage-stdout pump robustness, benign-GL success, real-error-not-benign, non-zero failure (+ JSON error envelope), empty/corrupt/missing-output aborts (+ partial-file removal), timeout, and a marker-file check proving the fake binary was actually invoked. Existing test_slice_cmd.py unit tests are kept where they assert argv assembly / profile-resolution branches.

Sabotage-verified

  • Removed not _real_err from the benign-RC guard -> test_real_error_with_gl_noise_is_not_benign failed.
  • Disabled the zero-RC _is_valid_sliced_3mf gate -> test_corrupt_output_file_aborts_and_is_removed failed.
  • Both restored; git diff bambu_cli/ is empty.

Notes

DLANSAMA added 4 commits July 29, 2026 14:44
`plate job/send <url> --dry-run` predicted `would_slice` from the raw URL-path
extension, which is absent for Printables model pages and extension-less direct
links. In those cases the predictor returned `would_slice: false`, but the real
run downloads a model file (the downloader falls back to `.stl` when it cannot
infer an extension) and slices it — so the dry-run pre-check disagreed with what
actually happened.

Fix: share one slicing predicate between the predictor and the doer.

- `_ext_would_slice(ext)` in bambu_cli/job/predict.py is now the single rule
  (`ext in SLICEABLE_EXTENSIONS`, applied to the single-suffix `_file_extension`
  so `foo.gcode.3mf` stays print-ready). The real-run local, ZIP-member, and
  post-download branches in orchestrate.py all route through it.
- `_predicted_download_slice_extension(url, args)` resolves the URL's predicted
  extension by reusing the downloader's own `_download_source_extension`, which
  falls back to `.stl` for sources whose extension is unknowable offline. `--name`
  is intentionally ignored because the real download overrides the `--name`
  extension with the URL/resolved-name extension.

`would_slice` remains a boolean; no JSON shape or schema change.

Tests: extended the direct-URL dry-run matrix (.stl/.step/.obj/.zip/.3mf and
.gcode.3mf), added Printables-model-URL and extension-less-URL predictions, a
predictor/doer shared-predicate equivalence test, local .gcode.3mf print-ready,
and a ZIP-member matrix (.stl slices, .3mf/.gcode.3mf do not). Strengthened the
Printables dry-run agent smoke to assert would_slice=True.
Add tests/fakes/orca_stub — a standalone fake OrcaSlicer script invoked as
the real slicer binary via a cross-platform launcher (sys.executable + script
path; sh wrapper on POSIX, .cmd on Windows). It reproduces the narrow Orca CLI
contract cmd_slice drives (--load-settings/--load-filaments/--slice/
--export-3mf/--outputdir) and selects scenarios by env var: success, benign
headless-GL non-zero exit, empty/corrupt/missing output, hard failure,
real-error-with-GL-noise, garbage stdout, progress, and hang (timeout).

tests/test_slice_stub_integration.py runs cmd_slice end-to-end against the stub
with a real profiles_dir + STL under tmp_path and no subprocess/os.path.exists
mocking, exercising the real _run_orcaslicer process loop (previously skipped
via pragma) and _finalize_slice parsing branches. slicer/output.py line
coverage rises 79.8% -> 92.7%.

No bambu_cli/ changes: settings_ctx (orca_slicer/profiles_dir) is the existing
DI seam. Docs (quality-roadmap C.4, test-backlog, mutation-baseline) updated;
snapshot counts refreshed to the measured 1032 collected / 1031 passing.
…apshots (re-measured: 1065 collected / 1064 passing, 84.9%)
@DLANSAMA
DLANSAMA merged commit a2fc4dd into main Jul 30, 2026
6 checks passed
@DLANSAMA
DLANSAMA deleted the test/hermetic-orca-stub branch July 30, 2026 01:02
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