Skip to content

Refactor cargo wdk action unit tests#690

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

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

Conversation

@krishnakumar4a4

Copy link
Copy Markdown
Contributor

This pull request refactors the build and packaging workflow in the cargo-wdk crate to improve testability and modularity. The primary changes introduce runner structs for both build and package tasks, enabling dependency injection and easier mocking during testing. The construction of BuildAction is also updated to accept these runners, and the internal logic is adjusted to use them.

Refactoring for testability and modularity:

  • Introduced BuildTaskRunner and BuildTaskRunParams structs, along with a run method and #[automock] attribute to facilitate mocking and dependency injection for build tasks (build_task.rs).
  • Introduced PackageTaskRunner and updated usage to allow for similar dependency injection for package tasks (mod.rs). [1] [2]

Changes to BuildAction construction and usage:

  • Updated BuildAction to accept runner instances (BuildTaskRunner and PackageTaskRunner), added a new_with_runners constructor, and refactored the main constructor to use it (mod.rs). [1] [2]
  • Refactored the main build and package logic to use the new runners and parameter structs instead of directly instantiating and calling the task types (mod.rs). [1] [2]

General code cleanup:

  • Added #![allow(dead_code)] and #![allow(clippy::unused_self)] to suppress related warnings in build_task.rs.
  • Cleaned up imports to reflect the new runner-based structure (mod.rs). [1] [2]

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 on lines +8 to +10
#![allow(dead_code)]
#![allow(clippy::unused_self)]

Comment on lines +52 to +67
pub fn run<'a>(
&self,
params: &BuildTaskRunParams<'a>,
command_exec: &CommandExec,
) -> Result<Vec<Result<Message, std::io::Error>>, BuildTaskError> {
BuildTask::new(
params.package_name,
params.working_dir,
params.profile,
params.target_arch,
params.verbosity_level,
command_exec,
)
.run()
.map(Iterator::collect)
}
Comment on lines +10 to +12
#![allow(dead_code)]
#![allow(clippy::unused_self)]

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.

2 participants