test: hermetic fake OrcaSlicer stub; de-mock slice tests - #90
Merged
Conversation
`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%)
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.
What
Adds a hermetic fake OrcaSlicer (roadmap C.4) under
tests/fakes/orca_stuband rewires slice tests to run the real slicer subprocess path instead of mockingsubprocess.Popen/os.path.exists.Why
slicer/output.py._finalize_slicehad 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 surfacecmd_slicebuilds (--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).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).sys.executable+ the script path — anshwrapper (chmod +x) on POSIX, a.cmdbatch file on Windows — soPopencan run it directly with no shebang/exec-bit reliance on Windows.settings_ctx(orca_slicer=..., profiles_dir=...)DI seam. Nobambu_cli/changes.Coverage delta on
bambu_cli/slicer/(full suite, term-missing)output.pycmd.pyPlus the real
_run_orcaslicerprocess/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. Existingtest_slice_cmd.pyunit tests are kept where they assert argv assembly / profile-resolution branches.Sabotage-verified
not _real_errfrom the benign-RC guard ->test_real_error_with_gl_noise_is_not_benignfailed._is_valid_sliced_3mfgate ->test_corrupt_output_file_aborts_and_is_removedfailed.git diff bambu_cli/is empty.Notes
test_docs_consistency.pygreen). CHANGELOG intentionally untouched (test-infra only; avoids the duplicate-[Unreleased]squash hazard with fix: job --dry-run would_slice matches real-run slicing decision #88/refactor: single shared verify_cert_fingerprint for mqtt/ftps/camera pin checks #89 open).recursive-include tests *.pyalready ships the stub in the sdist;package_contents_smoke/privacy_smokepass.