From a711d128f7c41e86b3e3c69c1f94058e78a146c2 Mon Sep 17 00:00:00 2001 From: sloemodzn Date: Sat, 22 Aug 2026 18:01:33 +0530 Subject: [PATCH] fix(health): recognize Ruby _spec.rb test pairing --- .../core/src/repowise/core/analysis/health/engine.py | 1 + tests/unit/health/test_paired_test_basenames.py | 10 ++++++++++ tests/unit/server/mcp/test_risk.py | 2 ++ 3 files changed, 13 insertions(+) diff --git a/packages/core/src/repowise/core/analysis/health/engine.py b/packages/core/src/repowise/core/analysis/health/engine.py index b5167a5d1..0962fc242 100644 --- a/packages/core/src/repowise/core/analysis/health/engine.py +++ b/packages/core/src/repowise/core/analysis/health/engine.py @@ -289,6 +289,7 @@ def _has_paired_test_file(rel_path: str, path_basenames: set[str]) -> bool: candidates = { f"test_{stem}.py", f"{stem}_test{test_suffix}", + f"{stem}_spec{test_suffix}", f"{stem}.test.ts", f"{stem}.test.tsx", f"{stem}.test.js", diff --git a/tests/unit/health/test_paired_test_basenames.py b/tests/unit/health/test_paired_test_basenames.py index f72030b39..aec7c0b58 100644 --- a/tests/unit/health/test_paired_test_basenames.py +++ b/tests/unit/health/test_paired_test_basenames.py @@ -24,6 +24,7 @@ def _reference_has_paired_test_file(rel_path: str, all_paths: set[str]) -> bool: candidates = { f"test_{stem}.py", f"{stem}_test.py", + f"{stem}_spec.rb", f"{stem}.test.ts", f"{stem}.test.tsx", f"{stem}.test.js", @@ -102,3 +103,12 @@ def test_basenames_split_on_forward_slash_only(self) -> None: def test_empty_paths(self) -> None: assert _path_basenames(set()) == set() assert not _has_paired_test_file("anything.py", set()) + + def test_ruby_and_crystal_underscore_spec_pairing(self) -> None: + """Ruby's _spec.rb (and Crystal's _spec.cr) is a paired test (#1768).""" + ruby = {"spec/user_spec.rb"} + assert _has_paired_test_file("lib/user.rb", _path_basenames(ruby)) + crystal = {"spec/user_spec.cr"} + assert _has_paired_test_file("src/user.cr", _path_basenames(crystal)) + # Same stem, dot form, must NOT count for Ruby's underscore layout. + assert not _has_paired_test_file("lib/user.rb", _path_basenames({"spec/user.spec.rb"})) diff --git a/tests/unit/server/mcp/test_risk.py b/tests/unit/server/mcp/test_risk.py index 23dc953bd..abe92ef88 100644 --- a/tests/unit/server/mcp/test_risk.py +++ b/tests/unit/server/mcp/test_risk.py @@ -236,6 +236,8 @@ def test_classify_bus_factor_unknown_team_size_keeps_behaviour(): ("lib/user.dart", "test/user_test.dart"), ("lib/user.ex", "test/user_test.exs"), ("src/user.rs", "tests/user_test.rs"), + ("lib/user.rb", "spec/user_spec.rb"), + ("src/user.cr", "spec/user_spec.cr"), ], ) def test_health_filename_heuristic_supports_suffix_test_conventions(source, test):