From a4d82bf45b46d3497df67f184595634d6fb7f353 Mon Sep 17 00:00:00 2001 From: Noah <2+noah@noreply.gitea.bluefla.re> Date: Tue, 3 Nov 2026 11:31:28 -0600 Subject: [PATCH] Attribute coverage to crates when llvm-cov strips the crates/ prefix The quality dashboard put every file under "other" because llvm-cov prints paths relative to their common prefix. Co-Authored-By: Claude Opus 5.5 --- ci/gen-badges.py | 6 ++++++ ci/test-bench-badge.py | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/ci/gen-badges.py b/ci/gen-badges.py index 35484843..264571c7 100644 --- a/ci/gen-badges.py +++ b/ci/gen-badges.py @@ -174,6 +174,12 @@ def coverage_by_file(summary_path: str | None, root: str) -> list[dict]: except ValueError: continue name = cols[0][len(root_abs):] if cols[0].startswith(root_abs) else cols[0] + # llvm-cov drops the prefix every file shares, so when only workspace + # crates are measured "crates/alkane-gui/src/x.rs" is printed as + # "alkane-gui/src/x.rs". Put the prefix back. + first = Path(name).parts[0] if Path(name).parts else "" + if not name.startswith("crates/") and (Path(root) / "crates" / first).is_dir(): + name = f"crates/{name}" rows.append({"file": name, "lines": lines, "missed": missed}) return rows diff --git a/ci/test-bench-badge.py b/ci/test-bench-badge.py index 76af8343..048b5c54 100644 --- a/ci/test-bench-badge.py +++ b/ci/test-bench-badge.py @@ -81,6 +81,17 @@ class BenchBadgeTests(unittest.TestCase): self.assertEqual(rows[0]["missed"], 60) self.assertEqual(gen_badges.crate_of(rows[1]["file"]), "alkane-core") + def test_coverage_table_restores_the_stripped_crates_prefix(self): + with tempfile.TemporaryDirectory(prefix="alkane-cov-") as directory: + (Path(directory) / "crates" / "alkane-cli").mkdir(parents=True) + summary = Path(directory) / "summary.txt" + summary.write_text( + "alkane-cli/src/main.rs 4 4 0.00% 1 1 0.00% 23 23 0.00%\n") + rows = gen_badges.coverage_by_file(str(summary), directory) + self.assertEqual(rows[0], {"file": "crates/alkane-cli/src/main.rs", + "lines": 23, "missed": 23}) + self.assertEqual(gen_badges.crate_of(rows[0]["file"]), "alkane-cli") + if __name__ == "__main__": unittest.main() -- 2.54.0