Skip to content

Commit 36c35d2

Browse files
committed
cargo-rail: docs cleaning; test cleaning
1 parent 22d5a79 commit 36c35d2

32 files changed

+394
-353
lines changed

src/cargo/manifest.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub struct CargoTransform {
2626
}
2727

2828
impl CargoTransform {
29+
/// Create a new CargoTransform from workspace metadata
2930
pub fn new(workspace_metadata: WorkspaceMetadata) -> Self {
3031
let mut workspace_versions = HashMap::new();
3132
let mut workspace_paths = HashMap::new();
@@ -205,6 +206,9 @@ impl CargoTransform {
205206
}
206207

207208
impl CargoTransform {
209+
/// Transform a Cargo.toml for split repository
210+
///
211+
/// Converts workspace inheritance and path dependencies to standalone format
208212
pub fn transform_to_split(&self, content: &str, _context: &TransformContext) -> RailResult<String> {
209213
let mut doc: DocumentMut = content.parse().context("Failed to parse Cargo.toml")?;
210214

@@ -220,6 +224,9 @@ impl CargoTransform {
220224
Ok(doc.to_string())
221225
}
222226

227+
/// Transform a Cargo.toml back to monorepo format
228+
///
229+
/// Converts version dependencies to path dependencies for workspace members
223230
pub fn transform_to_mono(&self, content: &str, _context: &TransformContext) -> RailResult<String> {
224231
let mut doc: DocumentMut = content.parse().context("Failed to parse Cargo.toml")?;
225232

src/cargo/metadata.rs

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ impl WorkspaceMetadata {
5555
// Basic Package Access
5656
// ============================================================================
5757

58+
/// Get all workspace member packages
5859
pub fn list_crates(&self) -> Vec<&Package> {
5960
self.metadata.workspace_packages()
6061
}
6162

63+
/// Find a package by name in the workspace
6264
pub fn get_package(&self, name: &str) -> Option<&Package> {
6365
self
6466
.metadata
@@ -67,6 +69,7 @@ impl WorkspaceMetadata {
6769
.find(|pkg| pkg.name == name)
6870
}
6971

72+
/// Get the workspace root directory path
7073
pub fn workspace_root(&self) -> &std::path::Path {
7174
self.metadata.workspace_root.as_std_path()
7275
}
@@ -202,19 +205,6 @@ mod tests {
202205
assert!(missing.is_none(), "Non-existent package should be None");
203206
}
204207

205-
#[test]
206-
fn test_workspace_root() {
207-
let metadata = create_test_metadata();
208-
let root = metadata.workspace_root();
209-
210-
// Should return valid path
211-
assert!(root.exists(), "Workspace root should exist");
212-
assert!(root.is_dir(), "Workspace root should be directory");
213-
214-
// Should contain Cargo.toml
215-
assert!(root.join("Cargo.toml").exists(), "Should have Cargo.toml");
216-
}
217-
218208
// ============================================================================
219209
// Tier 2: Feature & Target Analysis
220210
// ============================================================================
@@ -272,43 +262,10 @@ mod tests {
272262
assert!(empty_features.is_ok(), "Should load with empty features list");
273263
}
274264

275-
#[test]
276-
fn test_metadata_json() {
277-
let metadata = create_test_metadata();
278-
let raw = metadata.metadata_json();
279-
280-
// Should have access to raw metadata
281-
assert!(!raw.packages.is_empty(), "Raw metadata should have packages");
282-
}
283-
284265
// ============================================================================
285266
// Feature Unification Tests
286267
// ============================================================================
287268

288-
#[test]
289-
fn test_get_resolved_features_for_package() {
290-
let metadata = create_test_metadata();
291-
292-
// Test with a known external dependency (serde)
293-
// We know cargo-rail depends on serde
294-
if let Some(features) = metadata.get_resolved_features_for_package("serde") {
295-
// Resolved features should be a set
296-
assert!(
297-
!features.is_empty() || features.is_empty(),
298-
"Features set should be valid"
299-
);
300-
301-
// serde commonly has these features in resolved graph
302-
// (may vary based on what other crates enable)
303-
// Just verify we got a valid HashSet
304-
let _features_vec: Vec<String> = features.into_iter().collect();
305-
} else {
306-
// It's ok if serde doesn't have resolved features in test context
307-
// (might not be in resolve graph if running with limited metadata)
308-
println!("Note: serde not found in resolved graph (test may need full metadata)");
309-
}
310-
}
311-
312269
#[test]
313270
fn test_get_resolved_features_returns_none_for_workspace_members() {
314271
let metadata = create_test_metadata();

src/cargo/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313
//! - `unify` - Workspace dependency unification engine (replaces cargo-hakari)
1414
//! - `validate` - Optional per-target validation with Rayon parallelism
1515
16+
/// Lossless Cargo.toml transformation
1617
pub mod manifest;
18+
/// Comprehensive cargo_metadata wrapper
1719
pub mod metadata;
20+
/// Workspace dependency unification engine
1821
pub mod unify;
22+
/// Per-target validation with parallel execution
1923
pub mod validate;
2024

2125
pub use manifest::{CargoTransform, TransformContext};

src/cargo/unify/mod.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -276,15 +276,6 @@ mod tests {
276276
WorkspaceMetadata::load(&current_dir).unwrap()
277277
}
278278

279-
#[test]
280-
fn test_unify_config_default() {
281-
let config = UnifyConfig::default();
282-
assert!(matches!(config.strategy, UnifyStrategy::All));
283-
assert!(!config.allow_renamed); // Renamed deps not allowed by default
284-
assert!(config.exclude.is_empty());
285-
assert!(config.include.is_empty());
286-
}
287-
288279
#[test]
289280
fn test_analyze_workspace() {
290281
let metadata = create_test_metadata();

src/cargo/unify/types.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,12 @@ pub struct UnificationPlan {
9696
#[derive(Debug, Clone)]
9797
pub enum MemberEdit {
9898
/// Convert dependency to workspace = true
99-
UseWorkspace { dep_name: String, kind: DependencyKind },
99+
UseWorkspace {
100+
/// Dependency name
101+
dep_name: String,
102+
/// Dependency kind
103+
kind: DependencyKind,
104+
},
100105
}
101106

102107
/// Severity of a unification issue

src/cargo/validate.rs

Lines changed: 8 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,26 @@ use std::sync::{Arc, Mutex};
1313
/// Result of validating a single target
1414
#[derive(Debug, Clone)]
1515
pub struct TargetValidationResult {
16+
/// Target triple being validated
1617
pub target: String,
18+
/// Whether validation succeeded
1719
pub success: bool,
20+
/// Error message if validation failed
1821
pub error: Option<String>,
22+
/// Warning messages from cargo metadata
1923
pub warnings: Vec<String>,
2024
}
2125

2226
/// Summary of all target validations
2327
#[derive(Debug)]
2428
pub struct ValidationSummary {
29+
/// Individual validation results for each target
2530
pub results: Vec<TargetValidationResult>,
31+
/// Total number of targets validated
2632
pub total_targets: usize,
33+
/// Number of successful validations
2734
pub successful: usize,
35+
/// Number of failed validations
2836
pub failed: usize,
2937
}
3038

@@ -225,56 +233,4 @@ mod tests {
225233
assert!(!result.success, "Invalid target should fail");
226234
assert!(result.error.is_some(), "Should have an error message");
227235
}
228-
229-
#[test]
230-
fn test_validation_summary_all_passed() {
231-
let summary = ValidationSummary {
232-
results: vec![
233-
TargetValidationResult {
234-
target: "target1".to_string(),
235-
success: true,
236-
error: None,
237-
warnings: vec![],
238-
},
239-
TargetValidationResult {
240-
target: "target2".to_string(),
241-
success: true,
242-
error: None,
243-
warnings: vec![],
244-
},
245-
],
246-
total_targets: 2,
247-
successful: 2,
248-
failed: 0,
249-
};
250-
251-
assert!(summary.all_passed());
252-
assert!(summary.failed_targets().is_empty());
253-
}
254-
255-
#[test]
256-
fn test_validation_summary_some_failed() {
257-
let summary = ValidationSummary {
258-
results: vec![
259-
TargetValidationResult {
260-
target: "target1".to_string(),
261-
success: true,
262-
error: None,
263-
warnings: vec![],
264-
},
265-
TargetValidationResult {
266-
target: "target2".to_string(),
267-
success: false,
268-
error: Some("Failed".to_string()),
269-
warnings: vec![],
270-
},
271-
],
272-
total_targets: 2,
273-
successful: 1,
274-
failed: 1,
275-
};
276-
277-
assert!(!summary.all_passed());
278-
assert_eq!(summary.failed_targets(), vec!["target2"]);
279-
}
280236
}

src/change_detection/classify.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ pub enum ChangeKind {
1717
},
1818

1919
/// Test code (does not affect downstream crates)
20-
Test { kind: TestKind },
20+
Test {
21+
/// Type of test
22+
kind: TestKind,
23+
},
2124

2225
/// Examples (compile but don't affect dependencies)
2326
Example,
@@ -26,7 +29,10 @@ pub enum ChangeKind {
2629
BuildScript,
2730

2831
/// Configuration files
29-
Config { kind: ConfigKind },
32+
Config {
33+
/// Type of configuration file
34+
kind: ConfigKind,
35+
},
3036

3137
/// Documentation only (no rebuild/retest needed)
3238
Documentation,

src/commands/init.rs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -661,37 +661,6 @@ pub fn run_init_standalone(
661661
#[cfg(test)]
662662
mod tests {
663663
use super::*;
664-
use std::fs;
665-
use tempfile::TempDir;
666-
667-
#[test]
668-
fn test_check_existing_config() {
669-
let temp_dir = TempDir::new().unwrap();
670-
671-
// No config exists
672-
assert!(check_existing_config(temp_dir.path()).is_none());
673-
674-
// Create config at .config/rail.toml
675-
let config_dir = temp_dir.path().join(".config");
676-
fs::create_dir(&config_dir).unwrap();
677-
fs::write(config_dir.join("rail.toml"), "").unwrap();
678-
679-
assert!(check_existing_config(temp_dir.path()).is_some());
680-
}
681-
682-
#[test]
683-
fn test_ensure_output_dir() {
684-
let temp_dir = TempDir::new().unwrap();
685-
let output_path = temp_dir.path().join(".config/rail.toml");
686-
687-
// Directory doesn't exist yet
688-
assert!(!output_path.parent().unwrap().exists());
689-
690-
ensure_output_dir(&output_path).unwrap();
691-
692-
// Directory should now exist
693-
assert!(output_path.parent().unwrap().exists());
694-
}
695664

696665
#[test]
697666
fn test_serialize_config_with_comments() {

src/commands/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,25 @@
1919
//!
2020
//! All commands accept `&WorkspaceContext` to avoid redundant workspace loads.
2121
22+
/// Find crates affected by changes
2223
pub mod affected;
24+
/// Common utilities for command implementations
2325
pub mod common;
26+
/// Initialize cargo-rail configuration
2427
pub mod init;
28+
/// Release planning and publishing
2529
pub mod release;
30+
/// Split crates into standalone repositories
2631
pub mod split;
32+
/// Show split/sync status for all crates
2733
pub mod status;
34+
/// Bidirectional sync between monorepo and split repos
2835
pub mod sync;
36+
/// Smart test runner for affected crates
2937
pub mod test;
38+
/// Workspace dependency unification commands
3039
pub mod unify;
40+
/// Watch mode for continuous testing
3141
pub mod watch;
3242

3343
pub use affected::run_affected;

src/commands/status.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,22 @@ pub enum SyncStatus {
2424
/// Up to date
2525
UpToDate,
2626
/// Ahead of remote (N commits)
27-
Ahead { commits: u64 },
27+
Ahead {
28+
/// Number of commits ahead
29+
commits: u64,
30+
},
2831
/// Behind remote (N commits)
29-
Behind { commits: u64 },
32+
Behind {
33+
/// Number of commits behind
34+
commits: u64,
35+
},
3036
/// Diverged (ahead and behind)
31-
Diverged { ahead: u64, behind: u64 },
37+
Diverged {
38+
/// Number of commits ahead
39+
ahead: u64,
40+
/// Number of commits behind
41+
behind: u64,
42+
},
3243
}
3344

3445
/// Status information for a single crate

0 commit comments

Comments
 (0)