Skip to content

Conversation

@svasista-ms
Copy link
Contributor

Calling std::fs::create_dir_all from the NewAction::copy_cargo_config method led to bypassing the Fs provider mock during test execution. This led to creation of temporary directories:

image

In this PR, a create_dir_all method is added to Fs provider and all direct calls to std::fs::create_dir_all have been replaced by this method. This allows the mocks to work as expected during test execution.

Copilot AI review requested due to automatic review settings December 29, 2025 09:58
Copy link
Contributor

Copilot AI left a comment

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 fixes a testing issue where direct calls to std::fs::create_dir_all bypassed the Fs provider mock during test execution, causing unwanted temporary directory creation. The solution introduces a new create_dir_all method to the Fs provider and replaces all direct calls with this mockable version.

  • Added create_dir_all method to the Fs provider with proper error handling
  • Replaced direct std::fs::create_dir_all call in NewAction::copy_cargo_config with the new provider method
  • Updated test mocks to properly expect create_dir_all calls

Reviewed changes

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

File Description
crates/cargo-wdk/src/providers/fs.rs Added create_dir_all method to the Fs provider and updated imports to include create_dir_all from std::fs
crates/cargo-wdk/src/actions/new/mod.rs Removed direct std::fs::create_dir_all import and replaced usage with self.fs.create_dir_all, updated test mock expectations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +51 to +53
pub fn create_dir_all(&self, path: &Path) -> Result<(), FileError> {
create_dir_all(path).map_err(|e| FileError::CreateDirError(path.to_owned(), e))
}
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

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

The error variant CreateDirError is used for both create_dir and create_dir_all operations. While this works, it would be clearer to introduce a separate error variant like CreateDirAllError to distinguish between single-level directory creation failures and recursive directory creation failures. This would make error messages more precise and help with debugging.

Copilot uses AI. Check for mistakes.
Comment on lines +832 to +835
let expected_cargo_dir = cargo_dir;
self.mock_fs
.expect_create_dir_all()
.withf(move |path| path == expected_cargo_dir)
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

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

The variable expected_cargo_dir is redundantly assigned from cargo_dir. This intermediate assignment doesn't add value and can be simplified by using cargo_dir.clone() directly in the closure or cloning only when needed.

Suggested change
let expected_cargo_dir = cargo_dir;
self.mock_fs
.expect_create_dir_all()
.withf(move |path| path == expected_cargo_dir)
self.mock_fs
.expect_create_dir_all()
.withf(move |path| path == cargo_dir)

Copilot uses AI. Check for mistakes.
@codecov-commenter
Copy link

codecov-commenter commented Dec 29, 2025

Codecov Report

❌ Patch coverage is 81.81818% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.67%. Comparing base (c3c1223) to head (e0188c7).

Files with missing lines Patch % Lines
crates/cargo-wdk/src/actions/new/mod.rs 87.50% 0 Missing and 1 partial ⚠️
crates/cargo-wdk/src/providers/fs.rs 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #602      +/-   ##
==========================================
+ Coverage   82.66%   82.67%   +0.01%     
==========================================
  Files          25       25              
  Lines        7137     7147      +10     
  Branches     7137     7147      +10     
==========================================
+ Hits         5900     5909       +9     
  Misses       1108     1108              
- Partials      129      130       +1     

☔ View full report in Codecov by Sentry.
📢 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.

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