Fix temp file cleanup and coverage threshold comparison

- Add explicit unlink of temp file on moveFileZ failure to prevent orphaned files
- Fix coverage fraction calculation: use 0..1 range not 0..100 to match opts.fractions format

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Claude Bot
2025-10-26 02:21:09 +00:00
parent 087cc8e03a
commit dead574e16

View File

@@ -1262,6 +1262,8 @@ pub const CommandLineReporter = struct {
.auto,
),
) catch |err| {
// Clean up the temporary file before exiting
_ = bun.sys.unlink(cobertura_name);
Output.err(err, "Failed to save cobertura.xml file", .{});
Global.exit(1);
};
@@ -1273,17 +1275,17 @@ pub const CommandLineReporter = struct {
var has_low_coverage = false;
for (cobertura_reports.items) |*report| {
// Check if this report fails the coverage thresholds
const functions_pct = if (report.functions.items.len > 0)
@as(f64, @floatFromInt(report.functions_which_have_executed.count())) / @as(f64, @floatFromInt(report.functions.items.len)) * 100.0
// Check if this report fails the coverage thresholds (fractions are 0..1)
const functions_frac = if (report.functions.items.len > 0)
@as(f64, @floatFromInt(report.functions_which_have_executed.count())) / @as(f64, @floatFromInt(report.functions.items.len))
else
100.0;
const lines_pct = if (report.executable_lines.count() > 0)
@as(f64, @floatFromInt(report.lines_which_have_executed.count())) / @as(f64, @floatFromInt(report.executable_lines.count())) * 100.0
1.0;
const lines_frac = if (report.executable_lines.count() > 0)
@as(f64, @floatFromInt(report.lines_which_have_executed.count())) / @as(f64, @floatFromInt(report.executable_lines.count()))
else
100.0;
1.0;
if (functions_pct < fraction_threshold.functions or lines_pct < fraction_threshold.lines) {
if (functions_frac < fraction_threshold.functions or lines_frac < fraction_threshold.lines) {
has_low_coverage = true;
break;
}