rust: skip the coverage gate with no coverable lines
Assisted-by: Claude Opus 4.8 via Claude Code
change zpmkzyqukywvkmklvwonyqzxslyopwsz
commit 4165b621e74d8c59f9afb337b29c691b0f8146da
author Alpha Chen <alpha@kejadlen.dev>
date
parent mxzswzlv
diff --git a/ai/skills/rust/coverage.sh b/ai/skills/rust/coverage.sh
index 8034a431..631a3220 100755
--- a/ai/skills/rust/coverage.sh
+++ b/ai/skills/rust/coverage.sh
@@ -46,6 +46,22 @@ main() {
         .children | files
     ' <<<"$report"
 
+    # A crate with no coverable library lines yet (fresh scaffold)
+    # reports 0.0% for an empty set; that's a vacuous pass, not a failure.
+    local lines_total
+    lines_total=$(jq '.linesTotal' <<<"$report")
+    # Guard the arithmetic below: [[ -eq ]] evaluates a non-numeric string
+    # as 0, so a missing field would silently skip the gate.
+    if ! [[ "$lines_total" =~ ^[0-9]+$ ]]; then
+        echo "ERROR: expected a numeric linesTotal in the grcov report, got '${lines_total}'" >&2
+        echo "The report may not be covdir format — check grcov's --output-types flag." >&2
+        exit 1
+    fi
+    if [[ "$lines_total" -eq 0 ]]; then
+        echo "coverage: no coverable lines yet, skipping gate"
+        return 0
+    fi
+
     local coverage
     coverage=$(jq '.coveragePercent' <<<"$report")
     echo ""