#!/usr/bin/env python3 """Report host production-line coverage from cargo llvm-cov's LCOV export. Inline test modules and dedicated test/support files are excluded. Native adapter code and defensive error paths remain in the denominator. Each host file must reach 90%; missing source records are an error, not zero-length successes. """ import argparse from pathlib import Path parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("lcov", type=Path) args = parser.parse_args() root = Path(__file__).resolve().parent.parent host = root / "crates/core/src/ui/host" sources = [host.with_suffix(".rs"), *sorted(host.glob("*.rs"))] sources = [path for path in sources if path.name != "test_support.rs"] limits = {} for path in sources: lines = path.read_text().splitlines() # Host inline test modules are terminal; a test-only module declaration # elsewhere must not hide production code from the report. limits[path] = next((i + 1 for i, line in enumerate(lines) if line == "mod tests {" and i > 0 and lines[i - 1] == "#[cfg(test)]"), len(lines) + 1) coverage = {} source = None for line in args.lcov.read_text().splitlines(): if line.startswith("SF:"): source = Path(line[3:]).resolve() if source in limits: coverage.setdefault(source, {}) elif source in limits and line.startswith("DA:"): number, count = map(int, line[3:].split(",")[:2]) if number < limits[source]: coverage[source][number] = coverage[source].get(number, 0) + count passed = True total = covered = 0 for path in sources: counts = coverage.get(path, {}) hits = sum(count > 0 for count in counts.values()) percentage = 100 * hits / len(counts) if counts else 0 print(f"{str(path.relative_to(root)):50} {hits:4}/{len(counts):4} {percentage:6.2f}%") passed &= bool(counts) and percentage >= 90 total += len(counts) covered += hits print(f"Total: {covered}/{total} ({100 * covered / total if total else 0:.2f}%)") raise SystemExit(0 if passed else 1)