Skip to content

cargo-wdk: gate mockall/mockall_double behind cfg(test), move to dev-… - #719

Open
Ksenox (ksenoxhq) wants to merge 2 commits into
microsoft:mainfrom
ksenoxhq:fix-651-mockall-dev-deps
Open

cargo-wdk: gate mockall/mockall_double behind cfg(test), move to dev-…#719
Ksenox (ksenoxhq) wants to merge 2 commits into
microsoft:mainfrom
ksenoxhq:fix-651-mockall-dev-deps

Conversation

@ksenoxhq

Copy link
Copy Markdown

Moves mockall and mockall_double from [dependencies] to [dev-dependencies] in cargo-wdk, and gates their usage behind cfg(test) / cfg_attr(test, ...) in provider modules (exec.rs, wdk_build.rs, metadata.rs, fs.rs) and consumer modules (build/mod.rs, build_task.rs, package_task.rs, actions/new/mod.rs, actions/clean/mod.rs, cli.rs), following the pattern from PR #476.

Verified:

  • cargo check and cargo test --no-run pass on x86_64-pc-windows-gnu
  • cargo clippy --all-targets clean
  • test results unchanged vs unmodified main

Fixes #651

Copilot AI lite review requested due to automatic review settings August 14, 2026 20:10

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 updates cargo-wdk to ensure mockall and mockall_double are only pulled in for tests, aligning the provider/consumer mocking pattern with cfg(test) gating so production builds don’t depend on mock crates.

Changes:

  • Moved mockall and mockall_double from [dependencies] to [dev-dependencies] in crates/cargo-wdk/Cargo.toml.
  • Gated provider-side mockall::automock usage behind #[cfg(test)] and applied #[cfg_attr(test, automock)] on provider impl blocks.
  • Gated consumer-side mockall_double::double usage behind #[cfg(test)] and applied #[cfg_attr(test, double)] to provider imports.

Reviewed changes

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

Show a summary per file
File Description
crates/cargo-wdk/Cargo.toml Moves mock crates to dev-dependencies to avoid shipping them in non-test builds.
crates/cargo-wdk/src/providers/exec.rs Gates automock import and uses cfg_attr(test, automock) for test-only mock generation.
crates/cargo-wdk/src/providers/fs.rs Gates automock import and uses cfg_attr(test, automock) for test-only mock generation.
crates/cargo-wdk/src/providers/metadata.rs Gates automock import and uses cfg_attr(test, automock) for test-only mock generation.
crates/cargo-wdk/src/providers/wdk_build.rs Gates automock import and uses cfg_attr(test, automock) for test-only mock generation.
crates/cargo-wdk/src/cli.rs Gates double import and uses cfg_attr(test, double) for test-only provider doubling.
crates/cargo-wdk/src/actions/new/mod.rs Gates double import and uses cfg_attr(test, double) for test-only provider doubling.
crates/cargo-wdk/src/actions/clean/mod.rs Gates double import and uses cfg_attr(test, double) for test-only provider doubling.
crates/cargo-wdk/src/actions/build/mod.rs Gates double import and uses cfg_attr(test, double) for test-only provider doubling.
crates/cargo-wdk/src/actions/build/build_task.rs Gates double import and uses cfg_attr(test, double) for test-only provider doubling.
crates/cargo-wdk/src/actions/build/package_task.rs Gates double import and uses cfg_attr(test, double) for test-only provider doubling.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 21 to 23
use anyhow::Result;
#[cfg(test)]
use mockall::automock;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in f49f4af — gated the clippy::ref_option_ref allow behind cfg_attr(test, ...) in exec.rs, since it's only needed for the automock-generated mock code which is now test-only.

@ksenoxhq
Ksenox (ksenoxhq) force-pushed the fix-651-mockall-dev-deps branch from b663f91 to cd6eb76 Compare August 14, 2026 20:18
Copilot AI review requested due to automatic review settings August 14, 2026 21:59
@ksenoxhq

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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 11 out of 11 changed files in this pull request and generated no new comments.

Suppressed comments (3)

crates/cargo-wdk/src/providers/wdk_build.rs:11

  • Now that automock is only enabled under cfg(test), the module-wide #![allow(dead_code)] and #![allow(clippy::unused_self)] likely no longer need to apply to non-test builds. Consider changing them to #![cfg_attr(test, allow(...))] so production builds still benefit from these warnings.
// The intellisense confusion seems to come from automock
#![allow(dead_code)]
#![allow(clippy::unused_self)]
#[cfg(test)]
use mockall::automock;

crates/cargo-wdk/src/actions/build/mod.rs:28

  • cfg(test) is not enabled when this crate is compiled as a dependency of an integration test crate, so integration tests won’t get #[double]/generated doubles with this approach. If integration tests need doubles, consider gating doubles behind a Cargo feature (e.g. cfg_attr(any(test, feature = \"mocks\"), double)) and enabling that feature for integration tests.
#[cfg(test)]
use mockall_double::double;

crates/cargo-wdk/src/actions/build/mod.rs:38

  • cfg(test) is not enabled when this crate is compiled as a dependency of an integration test crate, so integration tests won’t get #[double]/generated doubles with this approach. If integration tests need doubles, consider gating doubles behind a Cargo feature (e.g. cfg_attr(any(test, feature = \"mocks\"), double)) and enabling that feature for integration tests.
#[cfg_attr(test, double)]
use crate::providers::{exec::CommandExec, fs::Fs, metadata::Metadata, wdk_build::WdkBuild};

Copilot AI review requested due to automatic review settings August 14, 2026 22:01

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 11 out of 11 changed files in this pull request and generated 2 comments.

Comment on lines +27 to 28
#[cfg(test)]
use mockall_double::double;
Comment on lines +37 to 38
#[cfg_attr(test, double)]
use crate::providers::{exec::CommandExec, fs::Fs, metadata::Metadata, wdk_build::WdkBuild};
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.

[cargo-wdk] Gate mockall/mockall_double behind cfg(test), move to [dev-dependencies], and clean up the provider/consumer mocking pattern

2 participants