Refactor cargo wdk action unit tests#690
Conversation
|
@copilot resolve the merge conflicts in this pull request |
There was a problem hiding this comment.
Pull request overview
This PR refactors cargo-wdk’s build/package orchestration to improve unit-testability by introducing injectable runner types for the build and package tasks, and rewrites the BuildAction unit tests to use those runners and more targeted expectations.
Changes:
- Add
BuildTaskRunner/BuildTaskRunParamsandPackageTaskRunnerwrappers to enable dependency injection and mocking. - Update
BuildActionto accept runner instances (vianew_with_runners) and route build/package work through the runners. - Replace large, end-to-end style
BuildActiontests with a smaller orchestrator-focused suite + richerPackageTaskunit tests.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| crates/cargo-wdk/src/actions/build/build_task.rs | Introduces BuildTaskRunner and parameter struct to decouple BuildTask execution for mocking. |
| crates/cargo-wdk/src/actions/build/mod.rs | Refactors BuildAction to use injected runners for build/package phases. |
| crates/cargo-wdk/src/actions/build/package_task.rs | Adds PackageTaskRunner and significantly expands/reshapes PackageTask unit test coverage. |
| crates/cargo-wdk/src/actions/build/tests.rs | Refactors BuildAction tests to validate orchestration via mocked runners and targeted expectations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
2e2b890 to
7bc3ee6
Compare
7bc3ee6 to
402e170
Compare
402e170 to
e5eea7d
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #690 +/- ##
==========================================
+ Coverage 79.93% 81.84% +1.90%
==========================================
Files 26 26
Lines 5633 6290 +657
Branches 5633 6290 +657
==========================================
+ Hits 4503 5148 +645
Misses 1002 1002
- Partials 128 140 +12 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
e5eea7d to
b285c05
Compare
7f6d686 to
9954a35
Compare
Introduce BuildTaskRunner and PackageTaskRunner with #[automock] to decouple BuildAction orchestration tests from the full provider stack. BuildAction tests now mock runners instead of every individual provider, reducing tests.rs from ~3400 lines to ~700 lines while maintaining equivalent coverage through dedicated unit tests in build_task.rs and package_task.rs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: fa978dd1-9d61-4cea-a03a-7ebc914228fa
…due to expectation overrides
Group top-level orchestration tests into three submodules by scenario type: - standalone_driver_project: single-package driver builds - driver_workspace: multi-package Cargo workspace builds - emulated_workspace: filesystem-based emulated workspace builds No test logic changes; only structural reorganization for clarity. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: fa978dd1-9d61-4cea-a03a-7ebc914228fa
- Rename TestBuildAction to BuildActionHarness for consistency with PackageTaskHarness naming convention in the task layer. - Shorten test function names since submodule names already provide the 'given' context (e.g. standalone_driver_project::run_skips_probe...). - Rename test_build_action parameter to harness throughout. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: fa978dd1-9d61-4cea-a03a-7ebc914228fa
BuildTaskRunner::run previously collected the entire cargo message stream into a Vec, which forced every message to be parsed and allocated up front and prevented get_target_dir_from_output from short-circuiting once the matching cdylib artifact is found. Return Box<dyn Iterator<..>> instead so the runner forwards BuildTask::run's lazy stream while still being mockable (mockall cannot mock an opaque impl Trait return, but can mock a boxed trait object). BuildTask::run gains + use<> precise capturing so its owned, 'static iterator can move out of the temporary BuildTask and be boxed. Addresses PR review comment r3581534373. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: fa978dd1-9d61-4cea-a03a-7ebc914228fa
9954a35 to
c22da52
Compare
…in build action tests
… off. This replaces the earlier removed test "given_a_driver_project_when_sign_mode_is_off_then_signing_and_verification_steps_are_skipped"
…ce metadata handling
…d enhancing readability
…esses in PackageTaskRunner
Decouples
BuildActionfromBuildTask/PackageTaskusing mockable runnerabstractions (
#[automock]+mockall_double), and replaces the monolithicfull-pipeline tests with focused, layered unit tests split across the
orchestration, build-task, and package-task layers.
Test migration at a glance
actions/build/tests.rsactions/build/package_task.rsactions/build/build_task.rstests.rs— orchestration layer (40 → 25)Deleted (30)
29 monolithic full-pipeline tests that drove the real
BuildTask/PackageTaskend-to-end through mocked providers. Replaced by orchestration-onlytests plus dedicated task-layer unit tests:
given_*_when_*_then_*tests deleted.1 arch-probe helper test replaced by a focused probe unit test:
parses_target_when_features_specified→ replaced byget_target_arch_from_cargo_rustc::probe_forwards_features(see Added)Added (15)
14 orchestration-only tests that assert
BuildActionwires the mockBuildTaskRunner/PackageTaskRunnercorrectly, grouped into three submodulesby scenario:
standalone_driver_projectrun_orchestrates_build_and_package_when_target_arch_is_detectedrun_skips_probe_and_uses_explicit_target_archrun_skips_package_runner_for_non_driver_packagerun_skips_package_runner_when_no_cdylib_targetrun_forwards_locked_and_features_to_metadata— asserts--lockedand theselected features are forwarded into the metadata provider, the build runner,
and the
cargo rustcproberun_returns_wdk_metadata_parse_error_for_invalid_metadata— invalid/partialWDK metadata surfaces
BuildActionError::WdkMetadataParsedriver_workspacerun_returns_workspace_error_when_one_member_failsrun_orchestrates_only_targeted_memberrun_propagates_build_error_on_failurerun_returns_wdk_metadata_parse_error_for_conflicting_member_configs—distinct per-member WDK configs surface
WdkMetadataParserun_returns_wdk_metadata_parse_error_for_conflicting_root_and_member_configs—root vs member WDK config conflict surfaces
WdkMetadataParserun_builds_non_driver_only_workspace_from_root— non-driver-only workspace,cwd = root: builds, packaging skipped, success
run_builds_non_driver_only_workspace_from_member— non-driver-only workspace,cwd = member: builds, packaging skipped, success
emulated_workspacerun_builds_each_valid_project1 probe helper unit test (replaces the deleted
parses_target_when_features_specified):get_target_arch_from_cargo_rustcprobe_forwards_features— asserts non-default features reach thecargo rustcprobe invocation
Renamed
The 8 original orchestration tests were renamed from their initial
given_*_when_*_then_*form to conciserun_*names, since the enclosingsubmodule now carries the "given" scenario context:
standalone_driver_projectgiven_a_driver_project_when_target_arch_is_detected_then_build_action_orchestrates_build_and_packagerun_orchestrates_build_and_package_when_target_arch_is_detectedstandalone_driver_projectgiven_explicit_target_arch_when_building_then_probe_is_skipped_and_package_runner_uses_itrun_skips_probe_and_uses_explicit_target_archstandalone_driver_projectgiven_a_non_driver_package_when_building_then_package_runner_is_skippedrun_skips_package_runner_for_non_driver_packagestandalone_driver_projectgiven_a_driver_package_without_cdylib_when_building_then_package_runner_is_skippedrun_skips_package_runner_when_no_cdylib_targetdriver_workspacegiven_a_workspace_root_when_one_member_fails_then_workspace_error_is_returnedrun_returns_workspace_error_when_one_member_failsdriver_workspacegiven_a_workspace_member_directory_when_building_then_only_that_member_is_orchestratedrun_orchestrates_only_targeted_memberdriver_workspacegiven_a_workspace_member_when_build_runner_fails_then_the_build_error_is_propagatedrun_propagates_build_error_on_failureemulated_workspacegiven_an_emulated_workspace_when_running_then_each_valid_project_is_builtrun_builds_each_valid_projectRetained (10)
Unchanged unit tests for the two pure helpers, still in their existing submodules:
get_target_dir_from_output—unparsable_output_fails,no_matching_artifact_fails,matching_artifact_without_dll_fails,matching_dll_resolves_target_dirget_target_arch_from_cargo_rustc—parses_amd64,parses_arm64_with_whitespace_and_crlf,parses_arm64_with_internal_whitespace,unsupported_arch_returns_error,missing_target_arch_returns_error,invalid_utf8_returns_errorpackage_task.rs— package-task layer (6 → 19)Added (13)
New
PackageTaskunit tests built with thePackageTaskHarnessbuilder,exercising the packaging pipeline in isolation from
BuildAction:run_packages_driver_with_expected_operationsrun_verifies_signatures_when_enabledrun_skips_signing_and_verification_when_sign_mode_is_offrun_exports_certificate_from_store_when_it_already_existsrun_returns_error_when_inx_file_is_missingrun_returns_error_when_copying_driver_binary_failsrun_returns_error_when_stampinf_failsrun_returns_error_when_inf2cat_failsrun_returns_error_when_infverif_failsrun_returns_error_when_certmgr_failsrun_returns_error_when_makecert_failsrun_returns_error_when_signtool_failsrun_skips_infverif_for_samples_when_wdk_build_is_in_bugged_rangeRetained (6)
new_succeeds_for_valid_argsnew_panics_when_target_dir_is_not_absolutenew_panics_when_working_dir_is_not_absolutestampinf_version_overrides_with_env_varnamed_mutex::acquire_works_correctlynamed_mutex::acquire_works_when_abandonedbuild_task.rs— build-task layer (7 → 7, unchanged)Test set is unchanged by this PR:
new_succeeds_for_valid_argsnew_panics_when_working_dir_is_not_absoluterun_invokes_cargo_build_with_expected_args_and_returns_outputrun_returns_command_failed_error_with_empty_stdout_when_cargo_build_exits_nonzerorun_returns_io_error_when_cargo_build_command_invocation_failsrun_forwards_locked_to_cargo_invocation_when_locked_is_setrun_forwards_features_to_cargo_invocation_when_features_are_setNet effect
internals (packaging steps, command-failure paths, signing) are covered at their
own layer.
including WDK-metadata parse-failure propagation (asserted at the orchestration
layer) and every packaging command's failure path (asserted at the package
layer).
tests.rsshrank from ~3,680 to ~1,970 lines;package_task.rstest setup wasde-duplicated via shared harness helpers.
tests.rs40→25,package_task.rs6→19,
build_task.rs7→7), with packaging behavior now covered directly at thepackage-task layer instead of through full-pipeline orchestration tests.