Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ run:

# Run all tests with coverage
test:
cargo llvm-cov --features test-helpers --ignore-filename-regex "ports/fakes"
./scripts/check_coverage.sh
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

Running ./scripts/check_coverage.sh makes just test depend on external tools like jq in addition to cargo-llvm-cov. Consider updating the workflow/docs/dev tooling to ensure jq is available (or have the script emit a clear install hint), otherwise just test may fail unexpectedly on fresh machines/CI images.

Copilot uses AI. Check for mistakes.

# Lint (zero warnings enforced)
lint:
Expand Down
42 changes: 42 additions & 0 deletions scripts/check_coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
set -euo pipefail

export PATH="$HOME/.cargo/bin:$PATH"

echo "Running cargo-llvm-cov (generating JSON report)..."
# Generate JSON + text report; do not fail immediately so we can print friendly summary
cargo llvm-cov --features test-helpers --ignore-filename-regex "ports/fakes" --json --output-path cov.json || true

if [ ! -f cov.json ]; then
echo "ERROR: cov.json not found. cargo-llvm-cov failed to produce JSON output."
exit 1
Comment on lines +7 to +12
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

The cargo llvm-cov ... || true suppresses test/coverage command failures, and since the script doesn’t remove any existing cov.json first, a failed run can still pass by reading a stale cov.json from a previous successful run. Capture the exit code, delete/overwrite cov.json before running, and fail the script if cargo llvm-cov fails (after printing any available summary).

Copilot uses AI. Check for mistakes.
fi

# Extract totals
lines_count=$(jq -r '.data[0].totals.lines.count' cov.json)
lines_covered=$(jq -r '.data[0].totals.lines.covered' cov.json)
lines_percent=$(jq -r '.data[0].totals.lines.percent' cov.json)
functions_percent=$(jq -r '.data[0].totals.functions.percent' cov.json)
regions_percent=$(jq -r '.data[0].totals.regions.percent' cov.json)
Comment on lines +15 to +20
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

This script assumes jq is installed, but there’s no preflight check, so the failure mode is a terse jq: command not found. Add a command -v jq check with a clear error message (or document/install it via the dev tooling) so just test fails with actionable guidance.

Copilot uses AI. Check for mistakes.

# Normalize null to 0
lines_percent=${lines_percent:-0}
functions_percent=${functions_percent:-0}
regions_percent=${regions_percent:-0}
Comment on lines +22 to +25
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

The “Normalize null to 0” logic doesn’t work as written: jq -r will emit the literal string null when a field is missing, and ${lines_percent:-0} won’t replace that. Handle the null string explicitly (or make jq default to 0) to avoid printing null% and to keep comparisons predictable.

Copilot uses AI. Check for mistakes.

printf "\nCoverage summary:\n"
printf " Lines: %s%% (%s/%s)\n" "$lines_percent" "$lines_covered" "$lines_count"
printf " Functions: %s%%\n" "$functions_percent"
printf " Regions: %s%%\n" "$regions_percent"

# Enforce threshold
threshold=90
# Use awk for numeric comparison (handles floats)
cmp=$(awk -v p="$lines_percent" -v t="$threshold" 'BEGIN{ if (p+0 >= t+0) print 0; else print 1 }')
if [ "$cmp" -eq 0 ]; then
echo "Coverage check: PASS (>= ${threshold}%)"
exit 0
else
echo "Coverage check: FAIL (< ${threshold}%)"
exit 1
fi