Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(health): recognize test coverage a name-pairing heuristic can't see (#1707)

Laentir Valetov9b8c153fc069
diff --git a/packages/core/src/repowise/core/ingestion/languages/registry.py b/packages/core/src/repowise/core/ingestion/languages/registry.py
index e1325dfd7..864a1e959 100644
--- a/packages/core/src/repowise/core/ingestion/languages/registry.py
+++ b/packages/core/src/repowise/core/ingestion/languages/registry.py
@@ -289,6 +289,29 @@ class LanguageRegistry:
result.setdefault(ext, pattern)
return result
+ def camel_test_prefix_res_by_extension(self) -> dict[str, re.Pattern[str]]:
+ """Per-extension case-sensitive camel-boundary test-prefix regexes.
+
+ The mirror of :meth:`camel_test_res_by_extension` for languages
+ whose test-program convention names the file ``Test<Subject>``
+ rather than ``<Subject>Test``. Each language's ``test_camel_prefixes``
+ compile to one anchored pattern (``^(?:Test)(?=[A-Z])``) keyed by
+ that language's own extensions — the uppercase-boundary lookahead is
+ what keeps ``Testing.dpr`` and bare ``Test.dpr`` out.
+ """
+ result: dict[str, re.Pattern[str]] = {}
+ for spec in self._specs.values():
+ if not spec.test_camel_prefixes:
+ continue
+ # Longest-first so a longer prefix wins inside the alternation.
+ alternation = "|".join(
+ sorted(spec.test_camel_prefixes, key=lambda pfx: (-len(pfx), pfx))
+ )
+ pattern = re.compile(rf"^(?:{alternation})(?=[A-Z])")
+ for ext in spec.extensions:
+ result.setdefault(ext, pattern)
+ return result
+
def camel_fixture_res_by_extension(self) -> dict[str, re.Pattern[str]]:
"""Per-extension case-sensitive camel-boundary fixture-suffix regexes.
diff --git a/packages/core/src/repowise/core/ingestion/languages/spec.py b/packages/core/src/repowise/core/ingestion/languages/spec.py
index cd55a3f9b..230c20bc6 100644
--- a/packages/core/src/repowise/core/ingestion/languages/spec.py
+++ b/packages/core/src/repowise/core/ingestion/languages/spec.py
@@ -78,6 +78,16 @@ class LanguageSpec:
# ``Test.java`` never do (conventions match with their own case).
test_camel_suffixes: tuple[str, ...] = () # ("Test", "Tests", "IT")
+ # Case-sensitive camel-boundary test PREFIXES — the mirror of
+ # ``test_camel_suffixes`` for languages whose test-program convention
+ # names the file ``Test<Subject>`` rather than ``<Subject>Test``.
+ # ``TestKeymap.dpr`` matches (Delphi's standalone console-test-program
+ # convention: one ``Test<Unit>.dpr`` per unit under test, sometimes
+ # exercising several units at once); ``Testing.dpr`` and bare
+ # ``Test.dpr`` never do (conventions match with their own case, and
+ # need a following uppercase letter to be a real word boundary).
+ test_camel_prefixes: tuple[str, ...] = () # ("Test",)
+
# Case-sensitive camel-boundary suffixes marking test *fixture* files
# ("ParameterizedTypeFixtures.java") — support data living in the test
# tree. A fixtures file provides data, it doesn't verify behavior, so
diff --git a/packages/core/src/repowise/core/ingestion/languages/specs/pascal.py b/packages/core/src/repowise/core/ingestion/languages/specs/pascal.py
index 77c709973..24ceef2b5 100644
--- a/packages/core/src/repowise/core/ingestion/languages/specs/pascal.py
+++ b/packages/core/src/repowise/core/ingestion/languages/specs/pascal.py
@@ -69,5 +69,16 @@ SPEC = LanguageSpec(
"TObject", "TInterfacedObject", "TPersistent", "TComponent",
"IUnknown", "IInterface", "IDispatch",
}),
+ # Delphi/FPC has no same-directory same-stem test-file convention (no
+ # ``uFoo.pas`` <-> ``uFoo_test.pas``): a unit is exercised by a
+ # standalone console test *program* named ``Test<Unit>.dpr`` -- one
+ # test project per unit, or sometimes one project exercising several
+ # related units together -- typically living in its own directory
+ # (this repo's own validation corpus keeps them under ``src/tools/``,
+ # separate from ``src/Core/``). ``Test`` is a prefix, not a suffix, so
+ # this is the mirror of the suffix-shaped ``FooTest.java`` convention:
+ # ``TestKeymap.dpr`` matches, ``Testing.dpr`` and bare ``Test.dpr``
+ # don't (see ``test_camel_prefixes`` on ``LanguageSpec``).
+ test_camel_prefixes=("Test",),
color_hex="#E3352E",
)
diff --git a/packages/core/src/repowise/core/test_paths.py b/packages/core/src/repowise/core/test_paths.py
index 66ecdcb5a..fb81234d5 100644
--- a/packages/core/src/repowise/core/test_paths.py
+++ b/packages/core/src/repowise/core/test_paths.py
@@ -100,6 +100,7 @@ class _Conventions:
stem_suffixes: tuple[str, ...]
infixes: tuple[str, ...]
camel_res: dict[str, re.Pattern[str]]
+ camel_prefix_res: dict[str, re.Pattern[str]]
support_stems: frozenset[str]
support_camel_res: dict[str, re.Pattern[str]]
dir_paths: tuple[tuple[str, ...], ...]
@@ -126,6 +127,7 @@ def _conventions() -> _Conventions:
stem_suffixes=REGISTRY.test_stem_suffixes(),
infixes=REGISTRY.test_infixes(),
camel_res=REGISTRY.camel_test_res_by_extension(),
+ camel_prefix_res=REGISTRY.camel_test_prefix_res_by_extension(),
support_stems=REGISTRY.test_fixture_stems(),
support_camel_res=REGISTRY.camel_fixture_res_by_extension(),
# Multi-segment test roots (src/test/java, src/it/scala) and the
@@ -168,8 +170,13 @@ def _is_test_name(filename: str) -> bool:
or any(infix in lowered for infix in rules.infixes)
):
return True
- camel_re = rules.camel_res.get(PurePosixPath(lowered).suffix)
- return camel_re is not None and camel_re.search(PurePosixPath(filename).stem) is not None
+ ext = PurePosixPath(lowered).suffix
+ original_stem = PurePosixPath(filename).stem
+ camel_re = rules.camel_res.get(ext)
+ if camel_re is not None and camel_re.search(original_stem) is not None:
+ return True
+ camel_prefix_re = rules.camel_prefix_res.get(ext)
+ return camel_prefix_re is not None and camel_prefix_re.search(original_stem) is not None
def _is_support_name(filename: str) -> bool:
diff --git a/tests/unit/ingestion/test_language_capabilities.py b/tests/unit/ingestion/test_language_capabilities.py
index 5ee7ad0bc..53b27f241 100644
--- a/tests/unit/ingestion/test_language_capabilities.py
+++ b/tests/unit/ingestion/test_language_capabilities.py
@@ -106,6 +106,14 @@ class TestParityGoldens:
assert camel[".java"].pattern == r"(?<=[a-z0-9])(?:Tests|Test|IT)$"
assert camel[".scala"].pattern == r"(?<=[a-z0-9])(?:Suite|Spec|Test)$"
+ def test_camel_prefix_extension_map(self) -> None:
+ # Case-sensitive camel-boundary test prefixes per language -- the
+ # mirror of test_camel_suffix_extension_map for languages whose test
+ # program is named Test<Subject> rather than <Subject>Test.
+ camel = REGISTRY.camel_test_prefix_res_by_extension()
+ assert set(camel) == {".pas", ".pp", ".dpr", ".dpk", ".lpr"}
+ assert camel[".dpr"].pattern == r"^(?:Test)(?=[A-Z])"
+
def test_test_dir_paths_union(self) -> None:
assert REGISTRY.test_dir_paths() == (
# "src/*Test" = Gradle source-set wildcard (src/commonTest,
diff --git a/tests/unit/test_test_paths.py b/tests/unit/test_test_paths.py
index 21db24813..74027cec0 100644
--- a/tests/unit/test_test_paths.py
+++ b/tests/unit/test_test_paths.py
@@ -141,3 +141,20 @@ def test_case_sensitive_rules_stay_case_sensitive() -> None:
assert is_test_path("src/FooTest.java")
assert not is_test_path("src/latest.java")
assert not is_test_path("src/Test.java")
+
+
+def test_camel_prefix_rule_mirrors_the_suffix_rule() -> None:
+ """``TestKeymap.dpr`` is a test (Pascal's camel-boundary prefix
+ convention); ``Testing.dpr`` and bare ``Test.dpr`` are not.
+
+ The prefix rule needs an uppercase boundary right after "Test", the
+ mirror of the suffix rule's lowercase-boundary requirement.
+ """
+ assert is_test_path("src/tools/TestKeymap.dpr", "pascal")
+ assert not is_test_path("src/tools/Testing.dpr", "pascal")
+ assert not is_test_path("src/tools/Test.dpr", "pascal")
+ # Case-sensitive and scoped to Pascal's own extensions -- a bare
+ # lowercase-boundary word never matches, and the convention doesn't
+ # leak onto an unrelated extension.
+ assert not is_test_path("src/testkeymap.dpr", "pascal")
+ assert not is_test_path("src/TestKeymap.txt", "pascal")