refactor(core): decompose core implementation into cohesive modules (#161)#175
Open
luongnv89 wants to merge 7 commits into
Open
refactor(core): decompose core implementation into cohesive modules (#161)#175luongnv89 wants to merge 7 commits into
luongnv89 wants to merge 7 commits into
Conversation
After decomposing core.py into sub-modules, command_version lives in _shell.py and is imported by each submodule. Tests that monkeypatch command_version on individual modules (e.g. _ollama, _machine_profile) stopped propagating because _probe_machine_profile_inputs and ollama_info resolve command_version via _core.command_version() at call time. Fixes: - Update _patch_command_version in test_supplementary.py to patch core.command_version and skip _ollama (no module-level name). - Update _stub_machine_internals and adapter tests in test_core_unit.py to patch pb.command_version instead of _ollama_mod.command_version. - Add conftest reload fixture for test isolation. - Add runtime call-time imports in _hf_api, _model_selection, _ollama, _machine_profile, _shell to ensure monkeypatches propagate.
After core.py decomposition, functions like huggingface_cli_detect, lms_info, and command_version are imported by core.py from sub-modules. Tests that patched the sub-module directly no longer propagated because core.py holds its own reference to the original function. Fixes: - _hf_api.huggingface_download_gguf now calls _core.huggingface_cli_detect() and _core.subprocess at call time so monkeypatches on core propagate. - Test helpers patch core.huggingface_cli_detect and core.subprocess in addition to sub-module targets. - TestMachineProfileAggregation patches _lmstudio.lms_info directly since _machine_profile resolves it from that module. - KI tests patch both core and _hf_api for huggingface_cli_detect.
- _patch_run and _patch_ollama_run now patch pb.run (core.run) instead of _ollama.run (which has no module-level run attribute after decomposition) - _patch_command_version adds core to patch list and skips _ollama - Tests in test_core_unit.py that patched _ollama_mod.run now patch pb.run - TestHuggingfaceDownloadGguf tests patch both core and _hf_api for huggingface_cli_detect since _hf_api resolves it through _core at call time - TestMachineProfileAggregation patches _lmstudio.lms_info directly
…tion After core.py was decomposed into sub-modules, several functions in _hf_api.py, _doctor.py, and _model_selection.py called their own module-level imports directly, bypassing test monkeypatches on the core facade. This caused CI-only test failures where the stripped PATH (hiding hf/huggingface-cli and other user-local tools) exposed the missing monkeypatch propagation. Changes: - _hf_api.py: huggingface_download_gguf now imports core at call time to resolve huggingface_cli_detect and subprocess through core. - _doctor.py: main() now calls machine_profile and select_best_model through core instead of direct sub-module imports. - _model_selection.py: select_best_model now calls smoke_test_ollama_model through core for monkeypatch compatibility. - _ollama.py: added run = _run_from_shell so core.run can check for monkeypatches on _ollama.run. - core.py: added delegation functions for huggingface_cli_detect and smoke_test_ollama_model so patches on _hf_api and _ollama propagate through the core facade.
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.
Decision Record (Round 2 — CI-only test failures fix)
Root Cause
CI runs with a stripped PATH (no
hf,huggingface-cli, or user-local tools),which masks unapplied monkeypatches. The tests only passed locally because the
real environment provided the binaries, causing code paths that should have been
patched to fall through to real binary detection and fail with
"HuggingFace CLI not found".
1.
_hf_api.huggingface_download_gguf— resolvehuggingface_cli_detectandsubprocessthrough coreThe function called
huggingface_cli_detect()from its own module scope andsubprocess.Popendirectly. Tests patchcore.huggingface_cli_detectandcore.subprocess.Popen, but the sub-module's direct imports bypassed thosepatches.
Fix: Import
coreat call time insidehuggingface_download_ggufandresolve
huggingface_cli_detect()andsubprocess.Popenthrough_core.2.
_doctor.main()— resolvemachine_profileandselect_best_modelthrough coremain()did late imports from_machine_profileand_model_selectiondirectly, bypassing test monkeypatches on
core.machine_profileandcore.select_best_model.Fix: Call
_core.machine_profile()and_core.select_best_model()throughthe core facade.
3.
_model_selection.select_best_model— resolvesmoke_test_ollama_modelthrough coreThe function imported
smoke_test_ollama_modeldirectly from_ollama,bypassing patches on
core.smoke_test_ollama_model.Fix: Call
_core.smoke_test_ollama_model()through the core facade.4.
_ollama.py— addrunattribute for core.run monkeypatch checkcore.runchecks_ollama_mod.run is not _run_from_shellto detectmonkeypatches. After decomposition,
_ollama.pyhad norunattribute,causing
AttributeError.Fix: Added
run = _run_from_shellto_ollama.py.5.
core.py— delegation functions forhuggingface_cli_detectandsmoke_test_ollama_modelTests patch
core.huggingface_cli_detectorcore.smoke_test_ollama_model,but the underlying sub-modules imported these functions directly. A delegation
function at call time ensures patches propagate.
Fix: Added
huggingface_cli_detect()andsmoke_test_ollama_model()delegation functions in
core.pythat forward to_hf_api_modand_ollama_modat call time.Acceptance Criteria Verification
stripped_PATH python -m pytest -qshows 0 failures for all previouslyfailing tests (17 tests across test_supplementary.py and test_e2e.py).
python -m pytest -qshows 0 failuresfor the same test set.
detect-secrets, trailing-whitespace, and pytest hooks all pass.
assertions; only source code was updated to respect monkeypatch targets.