Skip to content

Refactor cargo wdk action unit tests#690

Open
krishnakumar4a4 wants to merge 12 commits into
microsoft:mainfrom
krishnakumar4a4:refactor-cargo-wdk-action-unit-tests
Open

Refactor cargo wdk action unit tests#690
krishnakumar4a4 wants to merge 12 commits into
microsoft:mainfrom
krishnakumar4a4:refactor-cargo-wdk-action-unit-tests

Conversation

@krishnakumar4a4

@krishnakumar4a4 krishnakumar4a4 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

This pull request refactors the build and package execution flow to improve testability and code structure. The main change is introducing BuildTaskRunner and PackageTaskRunner as injectable dependencies, allowing for easier mocking in tests. The BuildAction struct now accepts these runners, and their usage replaces direct instantiation of BuildTask and PackageTask.

Here are the overall test coverage stats

File Layer Before After Added Deleted
actions/build/tests.rs Orchestration 40 25 15 30
actions/build/package_task.rs Package task 6 19 13 0
actions/build/build_task.rs Build task 7 7 0 0
  1. Deleted 30 existing tests covering build action, build and task layers together and replaced them with 15 newer tests only focussed on action layer mocking the task layers. The tests were organised into 3 sub modules standalone_driver_project, driver_workspace and emulated_workspace.
  2. 13 new tests were added to package_task module which were originally being covered in build action unit tests. A module level mutex TEST_MUTEX was added to serialize execution of certain tests as one of the test stampinf_version_overrides_with_env_var mutates process-global STAMPINF_VERSION env var
  3. No new tests were added to build_task module.

Copilot AI review requested due to automatic review settings June 25, 2026 07:06
@krishnakumar4a4

Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/BuildTaskRunParams and PackageTaskRunner wrappers to enable dependency injection and mocking.
  • Update BuildAction to accept runner instances (via new_with_runners) and route build/package work through the runners.
  • Replace large, end-to-end style BuildAction tests with a smaller orchestrator-focused suite + richer PackageTask unit 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.

Comment thread crates/cargo-wdk/src/actions/build/build_task.rs Outdated
Comment thread crates/cargo-wdk/src/actions/build/build_task.rs
Comment thread crates/cargo-wdk/src/actions/build/package_task.rs Outdated
Copilot AI review requested due to automatic review settings July 14, 2026 17:17
@krishnakumar4a4
krishnakumar4a4 force-pushed the refactor-cargo-wdk-action-unit-tests branch from 2e2b890 to 7bc3ee6 Compare July 14, 2026 17:17
@krishnakumar4a4
krishnakumar4a4 force-pushed the refactor-cargo-wdk-action-unit-tests branch from 7bc3ee6 to 402e170 Compare July 14, 2026 17:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 14, 2026 17:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.

Comment thread crates/cargo-wdk/src/actions/build/build_task.rs Outdated
Copilot AI review requested due to automatic review settings July 14, 2026 18:06
@krishnakumar4a4
krishnakumar4a4 force-pushed the refactor-cargo-wdk-action-unit-tests branch from 402e170 to e5eea7d Compare July 14, 2026 18:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

Comment thread crates/cargo-wdk/src/actions/build/build_task.rs
Comment thread crates/cargo-wdk/src/actions/build/package_task.rs
@codecov-commenter

codecov-commenter commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.64662% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.84%. Comparing base (21ec8f8) to head (dcaf613).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crates/cargo-wdk/src/actions/build/package_task.rs 98.56% 1 Missing and 8 partials ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI review requested due to automatic review settings July 15, 2026 03:29
@krishnakumar4a4
krishnakumar4a4 force-pushed the refactor-cargo-wdk-action-unit-tests branch from e5eea7d to b285c05 Compare July 15, 2026 03:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

Comment thread crates/cargo-wdk/src/actions/build/tests.rs
Comment thread crates/cargo-wdk/src/actions/build/package_task.rs
Copilot AI review requested due to automatic review settings July 15, 2026 04:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

Comment thread crates/cargo-wdk/src/actions/build/tests.rs
Comment thread crates/cargo-wdk/src/actions/build/tests.rs
Copilot AI review requested due to automatic review settings July 15, 2026 10:50
@krishnakumar4a4
krishnakumar4a4 force-pushed the refactor-cargo-wdk-action-unit-tests branch from 7f6d686 to 9954a35 Compare July 15, 2026 10:50
krishnakumar4a4 and others added 6 commits July 15, 2026 18:24
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
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
Copilot AI review requested due to automatic review settings July 15, 2026 14:36
@krishnakumar4a4
krishnakumar4a4 force-pushed the refactor-cargo-wdk-action-unit-tests branch from 9954a35 to c22da52 Compare July 15, 2026 14:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 9 comments.

Comment thread crates/cargo-wdk/src/actions/build/package_task.rs Outdated
Comment thread crates/cargo-wdk/src/actions/build/package_task.rs Outdated
Comment thread crates/cargo-wdk/src/actions/build/package_task.rs Outdated
Comment thread crates/cargo-wdk/src/actions/build/package_task.rs Outdated
Comment thread crates/cargo-wdk/src/actions/build/package_task.rs Outdated
Comment thread crates/cargo-wdk/src/actions/build/package_task.rs Outdated
Comment thread crates/cargo-wdk/src/actions/build/package_task.rs Outdated
Comment thread crates/cargo-wdk/src/actions/build/package_task.rs Outdated
Comment thread crates/cargo-wdk/src/actions/build/package_task.rs Outdated
Copilot AI review requested due to automatic review settings July 15, 2026 15:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 11 comments.

Comment thread crates/cargo-wdk/src/actions/build/package_task.rs Outdated
Comment thread crates/cargo-wdk/src/actions/build/package_task.rs Outdated
Comment thread crates/cargo-wdk/src/actions/build/package_task.rs Outdated
Comment thread crates/cargo-wdk/src/actions/build/package_task.rs Outdated
Comment thread crates/cargo-wdk/src/actions/build/package_task.rs Outdated
Comment thread crates/cargo-wdk/src/actions/build/package_task.rs Outdated
Comment thread crates/cargo-wdk/src/actions/build/package_task.rs Outdated
Comment thread crates/cargo-wdk/src/actions/build/package_task.rs Outdated
Comment thread crates/cargo-wdk/src/actions/build/tests.rs
Comment thread crates/cargo-wdk/src/actions/build/tests.rs
Copilot AI review requested due to automatic review settings July 16, 2026 04:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated no new comments.

@krishnakumar4a4
krishnakumar4a4 marked this pull request as ready for review July 16, 2026 04:11
… off.

This replaces the earlier removed test "given_a_driver_project_when_sign_mode_is_off_then_signing_and_verification_steps_are_skipped"
Copilot AI review requested due to automatic review settings July 16, 2026 08:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 16, 2026 12:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated no new comments.

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.

3 participants