-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
Problem
The manifest handling logic in tests/steps/process_steps.rs (lines 56-92) has several issues that need to be addressed:
Issues Identified
-
Mutable borrow issue: Line 56 takes a mutable reference to CLI, but line 71 attempts to clone from it whilst still borrowed mutably.
-
Missing error context: File operations lack proper error context as required by the coding guidelines.
-
Overly complex path resolution: The manifest path handling could be simplified.
Current Code
The problematic code in lines 56-92 of tests/steps/process_steps.rs:
let cli = world.cli.as_mut().expect("cli");
// Ensure a manifest exists at the path expected by the CLI.
let dir = world.temp.as_ref().expect("temp dir");
let manifest_path = if cli.file.is_absolute() {
cli.file.clone()
} else {
dir.path().join(&cli.file)
};
if !manifest_path.exists() {
let mut file = NamedTempFile::new_in(dir.path()).expect("manifest");
support::write_manifest(&mut file);
// Persist the temporary file to the desired manifest path.
file.persist(&manifest_path).expect("persist manifest");
}
cli.file.clone_from(&manifest_path);Proposed Solution
Apply the following changes to fix the mutable borrow issue and improve error handling:
let dir = world.temp.as_ref().expect("temp dir");
let manifest_path = {
let cli = world.cli.as_ref().expect("cli");
if cli.file.is_absolute() {
cli.file.clone()
} else {
dir.path().join(&cli.file)
}
};
if !manifest_path.exists() {
let mut file = NamedTempFile::new_in(dir.path())
.expect("Failed to create temporary manifest file");
support::write_manifest(&mut file);
file.persist(&manifest_path)
.expect("Failed to persist manifest file");
}
let cli = world.cli.as_mut().expect("cli");
cli.file.clone_from(&manifest_path);Benefits
- Fixes the mutable borrow issue by properly scoping the CLI references
- Improves error messages with more descriptive context
- Simplifies the path resolution logic
- Maintains the same functionality while being more robust
References
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels