Skip to content

Add unit tests for phase handlers: _phase_prepare_source, _phase_prepare_build, _phase_build, _phase_process_install_deps #1137

@LalatenduMohanty

Description

@LalatenduMohanty

PR #1116 converted the recursive bootstrap to an iterative state machine. The new tests/test_bootstrapper_iterative.py covers the state machine infrastructure (BootstrapPhase, WorkItem, _track_why, _dispatch_phase, _handle_phase_error, LIFO loop integration) well, but the four phase handlers that contain the actual build orchestration logic lack direct unit tests. They are only exercised indirectly through integration tests that mock _dispatch_phase away.

Each method has multiple branches that should be tested individually:

_phase_prepare_source (4 tests)

  • Prebuilt pathpbi_pre_built=True: calls _download_prebuilt, skips to PROCESS_INSTALL_DEPS, build_result.source_type == PREBUILT, no dep items returned
  • Source, no cache_find_cached_wheel → (None, None): calls _download_source + _prepare_source, sets build_env/sdist_root_dir/unpack_dir, phase → PREPARE_BUILD, returns BUILD_SYSTEM dep items
  • Source, cached wheel_find_cached_wheel → (wheel, unpacked): skips download/prepare, sets cached_wheel_filename, uses unpacked / unpacked.stem as sdist root
  • Bad sdist_root pathsdist_root_dir.parent.parent != work_dir: raises ValueError

_phase_prepare_build (3 tests)

  • With backend + sdist deps — installs system deps via build_env.install, extracts backend/sdist deps, returns [item, *BUILD_BACKEND items, *BUILD_SDIST items], phase → BUILD
  • No extra deps — backend and sdist deps are empty, returns [item] only
  • Install verificationbuild_env.install called exactly once with system deps

_phase_build (3 tests)

  • Disjoint deps — backend/sdist deps disjoint from system deps → build_env.install called with remaining deps
  • Overlapping deps — backend/sdist deps overlap system deps → build_env.install NOT called (deps already installed)
  • build_env propagationresult.build_env is item.build_env (missing from existing test)

_phase_process_install_deps (7 tests)

  • Normal path — hooks succeed, dep extraction succeeds, build order written, returns [item_at_COMPLETE, *INSTALL dep items]
  • Hook error, test mode — records failure_type="hook", dep extraction and build order still proceed
  • Hook error, normal mode — exception propagates
  • Dep extraction error, test mode — records failure_type="dependency_extraction", uses empty dep list, build order still written
  • Dep extraction error, normal mode — exception propagates
  • No install deps — returns [item] only, phase is COMPLETE
  • Build order_add_to_build_order called with correct source_type, prebuilt flag, and constraint

Notes

  • The existing _make_build_item helper in test_bootstrapper_iterative.py can be extended to set up build_env, sdist_root_dir, and build_result fields for these tests.
  • Each phase handler should be tested in isolation by mocking the lower-level methods it calls (_download_prebuilt, _find_cached_wheel, _download_source, dependencies.get_build_*_dependencies, hooks.run_post_bootstrap_hooks, etc.).
  • The existing test_phase_build_produces_source_build_result in test_bootstrapper.py covers the happy path for _phase_build but misses the dep-overlap and build_env propagation branches listed above.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions