fix: add --all to cargo fmt in script/test and autoformat codebase
cargo fmt without --all fails with "Failed to find targets" in workspace repos. This was blocking every story's gates. Also ran cargo fmt --all to fix all existing formatting issues. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -59,12 +59,16 @@ fn read_cached_coverage(project_root: &std::path::Path) -> String {
|
||||
fn read_coverage_report(path: &std::path::Path) -> String {
|
||||
let content = match std::fs::read_to_string(path) {
|
||||
Ok(c) => c,
|
||||
Err(e) => return format!("**Coverage (cached)**\n\nError reading `.coverage_report.json`: {e}"),
|
||||
Err(e) => {
|
||||
return format!("**Coverage (cached)**\n\nError reading `.coverage_report.json`: {e}");
|
||||
}
|
||||
};
|
||||
|
||||
let report: CoverageReport = match serde_json::from_str(&content) {
|
||||
Ok(r) => r,
|
||||
Err(e) => return format!("**Coverage (cached)**\n\nFailed to parse `.coverage_report.json`: {e}"),
|
||||
Err(e) => {
|
||||
return format!("**Coverage (cached)**\n\nFailed to parse `.coverage_report.json`: {e}");
|
||||
}
|
||||
};
|
||||
|
||||
format_coverage_report(&report)
|
||||
@@ -81,13 +85,22 @@ fn format_coverage_report(report: &CoverageReport) -> String {
|
||||
// Top 5 lowest-covered files (already sorted ascending in the JSON, but sort
|
||||
// defensively here so the display is correct even if the file was hand-edited).
|
||||
let mut sorted: Vec<&FileCoverage> = report.files.iter().collect();
|
||||
sorted.sort_by(|a, b| a.coverage.partial_cmp(&b.coverage).unwrap_or(std::cmp::Ordering::Equal));
|
||||
sorted.sort_by(|a, b| {
|
||||
a.coverage
|
||||
.partial_cmp(&b.coverage)
|
||||
.unwrap_or(std::cmp::Ordering::Equal)
|
||||
});
|
||||
|
||||
let targets: Vec<&FileCoverage> = sorted.into_iter().take(5).collect();
|
||||
if !targets.is_empty() {
|
||||
out.push_str("\n**Top 5 files needing coverage:**\n");
|
||||
for (i, file) in targets.iter().enumerate() {
|
||||
out.push_str(&format!("{}. {} — {:.1}%\n", i + 1, file.path, file.coverage));
|
||||
out.push_str(&format!(
|
||||
"{}. {} — {:.1}%\n",
|
||||
i + 1,
|
||||
file.path,
|
||||
file.coverage
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,8 +175,13 @@ fn run_coverage(project_root: &std::path::Path) -> String {
|
||||
// Replace the "cached" label with "fresh".
|
||||
result = result.replacen("Coverage (cached)", "Coverage (fresh)", 1);
|
||||
// Replace the cached hint with a pass/fail indicator.
|
||||
let pass_indicator = if out.status.success() { "PASS" } else { "FAIL: coverage below threshold" };
|
||||
result = result.replacen("*Run `coverage run` for fresh results.*", pass_indicator, 1);
|
||||
let pass_indicator = if out.status.success() {
|
||||
"PASS"
|
||||
} else {
|
||||
"FAIL: coverage below threshold"
|
||||
};
|
||||
result =
|
||||
result.replacen("*Run `coverage run` for fresh results.*", pass_indicator, 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -322,9 +340,18 @@ mod tests {
|
||||
let output = handle_coverage(&ctx).unwrap();
|
||||
|
||||
assert!(output.contains("72.5"), "should include overall: {output}");
|
||||
assert!(output.contains("60.0"), "should include threshold: {output}");
|
||||
assert!(output.contains("15.0"), "should include lowest-covered file pct: {output}");
|
||||
assert!(output.contains("server/src/low.rs"), "should include lowest-covered file path: {output}");
|
||||
assert!(
|
||||
output.contains("60.0"),
|
||||
"should include threshold: {output}"
|
||||
);
|
||||
assert!(
|
||||
output.contains("15.0"),
|
||||
"should include lowest-covered file pct: {output}"
|
||||
);
|
||||
assert!(
|
||||
output.contains("server/src/low.rs"),
|
||||
"should include lowest-covered file path: {output}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -348,9 +375,18 @@ mod tests {
|
||||
let output = handle_coverage(&ctx).unwrap();
|
||||
|
||||
assert!(output.contains("a.rs"), "should show lowest file: {output}");
|
||||
assert!(output.contains("e.rs"), "should show 5th lowest file: {output}");
|
||||
assert!(!output.contains("f.rs"), "should not show 6th file: {output}");
|
||||
assert!(!output.contains("g.rs"), "should not show 7th file: {output}");
|
||||
assert!(
|
||||
output.contains("e.rs"),
|
||||
"should show 5th lowest file: {output}"
|
||||
);
|
||||
assert!(
|
||||
!output.contains("f.rs"),
|
||||
"should not show 6th file: {output}"
|
||||
);
|
||||
assert!(
|
||||
!output.contains("g.rs"),
|
||||
"should not show 7th file: {output}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -466,15 +502,24 @@ mod tests {
|
||||
overall: 66.25,
|
||||
threshold: 60.0,
|
||||
files: vec![
|
||||
FileCoverage { path: "a.rs".to_string(), coverage: 10.0 },
|
||||
FileCoverage { path: "b.rs".to_string(), coverage: 80.0 },
|
||||
FileCoverage {
|
||||
path: "a.rs".to_string(),
|
||||
coverage: 10.0,
|
||||
},
|
||||
FileCoverage {
|
||||
path: "b.rs".to_string(),
|
||||
coverage: 80.0,
|
||||
},
|
||||
],
|
||||
};
|
||||
let result = format_coverage_report(&report);
|
||||
assert!(result.contains("66.2"), "should show overall: {result}");
|
||||
assert!(result.contains("60.0"), "should show threshold: {result}");
|
||||
assert!(result.contains("a.rs"), "should show lowest file: {result}");
|
||||
assert!(result.contains("10.0"), "should show lowest file pct: {result}");
|
||||
assert!(
|
||||
result.contains("10.0"),
|
||||
"should show lowest file pct: {result}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -490,9 +535,18 @@ Frontend line coverage: 70.0%\n\
|
||||
PASS: Coverage 66.25% meets threshold 60.00%\n\
|
||||
";
|
||||
let result = parse_coverage_output(sample, true);
|
||||
assert!(result.contains("62.5"), "should include Rust coverage: {result}");
|
||||
assert!(result.contains("70.0"), "should include Frontend coverage: {result}");
|
||||
assert!(result.contains("66.25"), "should include Overall coverage: {result}");
|
||||
assert!(
|
||||
result.contains("62.5"),
|
||||
"should include Rust coverage: {result}"
|
||||
);
|
||||
assert!(
|
||||
result.contains("70.0"),
|
||||
"should include Frontend coverage: {result}"
|
||||
);
|
||||
assert!(
|
||||
result.contains("66.25"),
|
||||
"should include Overall coverage: {result}"
|
||||
);
|
||||
assert!(result.contains("PASS"), "should indicate PASS: {result}");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user