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(core): read PascalCase suite folders, Gradle test fixtures and QA projects as tests (#2913)

Raghav Chamadiya73595b5c83a4
diff --git a/packages/core/src/repowise/core/analysis/dead_code/constants.py b/packages/core/src/repowise/core/analysis/dead_code/constants.py
index 3f769dbe0..2387bdd34 100644
--- a/packages/core/src/repowise/core/analysis/dead_code/constants.py
+++ b/packages/core/src/repowise/core/analysis/dead_code/constants.py
@@ -161,18 +161,10 @@ _NEVER_FLAG_PATTERNS: tuple[str, ...] = (
"*/Styles/*.xaml",
"*/Resources/*.xaml",
# ---- Test infrastructure conventions -----------------------------
- # Test classes are loaded by the runner via attribute reflection. Both
- # locations and suffixes are matched, to catch tests at arbitrary paths.
- "*Tests/*.cs",
- "*.Tests/*.cs",
- "*UnitTests/*.cs",
- "*.UnitTests/*.cs",
- "*IntegrationTests/*.cs",
- "*.IntegrationTests/*.cs",
- "*FuzzTests/*.cs",
- "*.FuzzTests/*.cs",
- "*UITests/*.cs",
- "*.UITests/*.cs",
+ # Test classes are loaded by the runner via attribute reflection. The
+ # plural suite folders (``Foo.Tests/``, ``UnitTests/``, ``UITests/``) are
+ # test paths (``test_paths``), which every dead-code pass already skips;
+ # these are the shapes it does not read as tests.
"*UITest/*.cs",
"*UITestAutomation/*.cs",
# Singular forms.
diff --git a/packages/core/src/repowise/core/ingestion/languages/specs/java.py b/packages/core/src/repowise/core/ingestion/languages/specs/java.py
index bc3e3f8fc..e2e300ded 100644
--- a/packages/core/src/repowise/core/ingestion/languages/specs/java.py
+++ b/packages/core/src/repowise/core/ingestion/languages/specs/java.py
@@ -70,7 +70,14 @@ SPEC = LanguageSpec(
# Test-data files (gson's ParameterizedTypeFixtures.java) — support
# data in the test tree, never the suite's face in the tour.
fixture_camel_suffixes=("Fixture", "Fixtures"),
- test_dir_paths=("src/test/java", "src/it/java", "src/integrationtest/java"),
+ # ``src/testFixtures`` is the Gradle java-test-fixtures source set: helpers
+ # other projects' tests consume, never shipped.
+ test_dir_paths=(
+ "src/test/java",
+ "src/it/java",
+ "src/integrationtest/java",
+ "src/testfixtures/java",
+ ),
# JPMS/javadoc descriptors — source files that declare, not implement.
descriptor_filenames=("module-info.java", "package-info.java"),
extensions=frozenset({".java"}),
diff --git a/packages/core/src/repowise/core/ingestion/languages/specs/kotlin.py b/packages/core/src/repowise/core/ingestion/languages/specs/kotlin.py
index 4968b107e..aefab32ec 100644
--- a/packages/core/src/repowise/core/ingestion/languages/specs/kotlin.py
+++ b/packages/core/src/repowise/core/ingestion/languages/specs/kotlin.py
@@ -10,7 +10,7 @@ SPEC = LanguageSpec(
# roots — the "src/*Test" wildcard covers multiplatform/custom test
# sourcesets (src/commonTest, src/jvmTest, src/integrationTest, …).
test_camel_suffixes=("Test", "Tests", "Spec"),
- test_dir_paths=("src/test/kotlin", "src/*Test"),
+ test_dir_paths=("src/test/kotlin", "src/testfixtures/kotlin", "src/*Test"),
entry_point_patterns=("Main.kt", "Application.kt"),
extensions=frozenset({".kt", ".kts"}),
grammar_package="tree_sitter_kotlin",
diff --git a/packages/core/src/repowise/core/test_paths.py b/packages/core/src/repowise/core/test_paths.py
index 87ef8c5bb..340d679fb 100644
--- a/packages/core/src/repowise/core/test_paths.py
+++ b/packages/core/src/repowise/core/test_paths.py
@@ -68,6 +68,21 @@ _TEST_DIR_TOKENS: frozenset[str] = frozenset(
# far more often than it names a suite.
_TEST_DIR_HEAD_WORDS: frozenset[str] = frozenset({"tests", "e2e"})
+# The same head written in PascalCase or camelCase, one word with no separator:
+# ``UnitTests/``, ``UITests/``, ``FuzzTests/``, ``AdvancedPaste.UnitTests/``.
+# Plural only, for the reason above (``HitTest/`` is a UI feature), and matched
+# on the original case so ``contests/`` stays one lowercase word. Ceiling: a
+# product folder that names a kind of test it runs for users (``LoadTests/``,
+# ``ABTests/``, ``PenTests/``) reads as a test tree too; none seen so far.
+_CAMEL_TESTS_HEAD_RE = re.compile(r"[A-Za-z0-9]Tests$")
+
+# Gradle QA builds keep integration suites and the plugins they load in their
+# own projects: ``qa/<project>/src/<source set>/<java|resources|...>``. The full
+# JVM source-set shape is required, so a ``qa/`` package of tooling
+# (``packages/qa/cli/src/main.ts``) stays production.
+_TEST_PROJECT_CONTAINER = "qa"
+_JVM_SOURCE_ROOTS: frozenset[str] = frozenset({"java", "kotlin", "groovy", "scala", "resources"})
+
# GitHub's repository-metadata directory; see ``_classify``.
_REPO_METADATA_DIR = ".github"
@@ -248,8 +263,16 @@ def _is_test_dir(
segments: list[str], original: list[str], filename: str, language: str | None
) -> bool:
"""Whether any directory segment marks this path as sitting in a test tree."""
- rules = _conventions()
- lang_tokens = rules.lang_dir_tokens.get((language or "").lower(), frozenset())
+ return _has_test_segment(segments, original, filename, language) or _has_test_layout(
+ segments, original
+ )
+
+
+def _has_test_segment(
+ segments: list[str], original: list[str], filename: str, language: str | None
+) -> bool:
+ """Whether one directory's own name says it holds tests."""
+ lang_tokens = _conventions().lang_dir_tokens.get((language or "").lower(), frozenset())
# ``spec/`` needs corroboration from somewhere: the language declaring the
# token, a test- or support-shaped filename, or a scaffolding dir beneath it
# (``spec/support/helper.rb`` is RSpec whatever the filename says, and
@@ -259,34 +282,60 @@ def _is_test_dir(
or _is_support_name(filename)
or any(seg in _SUPPORT_DIR_TOKENS for seg in segments)
)
- for seg in segments:
- if seg in _TEST_DIR_TOKENS:
- return True
- words = _words(seg)
- head = words[-1] if words else ""
- if head in _TEST_DIR_HEAD_WORDS:
- return True
- if head in _AMBIGUOUS_TEST_DIR_TOKENS and (head in lang_tokens or corroborated):
- return True
-
- for needle in rules.dir_paths:
- span = len(needle)
- if span <= len(segments) and any(
- tuple(segments[i : i + span]) == needle for i in range(len(segments) - span + 1)
- ):
- return True
-
- for prefix_seg, camel_suffix in rules.dir_wildcards:
- for i in range(len(segments) - 1):
- nxt = original[i + 1]
- if (
- segments[i] == prefix_seg
- and nxt.endswith(camel_suffix)
- and len(nxt) > len(camel_suffix)
- ):
- return True
-
- return any(seg.endswith(rules.dir_suffixes) for seg in original)
+ return any(
+ _is_test_segment(seg, orig, lang_tokens, corroborated)
+ for seg, orig in zip(segments, original, strict=True)
+ )
+
+
+def _is_test_segment(seg: str, orig: str, lang_tokens: frozenset[str], corroborated: bool) -> bool:
+ words = _words(seg)
+ head = words[-1] if words else ""
+ if seg in _TEST_DIR_TOKENS or head in _TEST_DIR_HEAD_WORDS:
+ return True
+ if head in _AMBIGUOUS_TEST_DIR_TOKENS and (head in lang_tokens or corroborated):
+ return True
+ return _CAMEL_TESTS_HEAD_RE.search(orig) is not None
+
+
+def _has_test_layout(segments: list[str], original: list[str]) -> bool:
+ """Whether the directories form a known test layout (``src/test/java``)."""
+ rules = _conventions()
+ return (
+ _in_test_project(segments)
+ or any(_contains_run(segments, needle) for needle in rules.dir_paths)
+ or any(
+ _has_wildcard_pair(segments, original, prefix_seg, camel_suffix)
+ for prefix_seg, camel_suffix in rules.dir_wildcards
+ )
+ or any(seg.endswith(rules.dir_suffixes) for seg in original)
+ )
+
+
+def _in_test_project(segments: list[str]) -> bool:
+ return any(
+ seg == _TEST_PROJECT_CONTAINER
+ and segments[i + 2] == "src"
+ and segments[i + 4] in _JVM_SOURCE_ROOTS
+ for i, seg in enumerate(segments[:-4])
+ )
+
+
+def _contains_run(segments: list[str], needle: tuple[str, ...]) -> bool:
+ span = len(needle)
+ return any(tuple(segments[i : i + span]) == needle for i in range(len(segments) - span + 1))
+
+
+def _has_wildcard_pair(
+ segments: list[str], original: list[str], prefix_seg: str, camel_suffix: str
+) -> bool:
+ """``src/*Test``: a *prefix_seg* directly above a name ending in *camel_suffix*."""
+ return any(
+ segments[i] == prefix_seg
+ and original[i + 1].endswith(camel_suffix)
+ and len(original[i + 1]) > len(camel_suffix)
+ for i in range(len(segments) - 1)
+ )
def _classify(path: str, language: str | None) -> str:
diff --git a/tests/unit/ingestion/test_language_capabilities.py b/tests/unit/ingestion/test_language_capabilities.py
index e5fc9ef22..2b708d5e3 100644
--- a/tests/unit/ingestion/test_language_capabilities.py
+++ b/tests/unit/ingestion/test_language_capabilities.py
@@ -125,6 +125,8 @@ class TestParityGoldens:
"src/test/java",
"src/test/kotlin",
"src/test/scala",
+ "src/testfixtures/java",
+ "src/testfixtures/kotlin",
)
def test_test_dir_suffixes_union(self) -> None:
diff --git a/tests/unit/test_test_paths.py b/tests/unit/test_test_paths.py
index c24291d30..8174efce4 100644
--- a/tests/unit/test_test_paths.py
+++ b/tests/unit/test_test_paths.py
@@ -53,6 +53,28 @@ _CORPUS: tuple[tuple[str, str | None, str], ...] = (
("src/main/java/Latest.java", None, ""),
# .net sibling test projects
("Foo.Tests/Bar.cs", None, "test"),
+ # PascalCase suite folders, one word with no separator (PowerToys)
+ ("src/common/updating/UnitTests/UpdatingTests.cpp", None, "test"),
+ ("src/modules/AdvancedPaste/AdvancedPaste.UnitTests/Mocks/Clipboard.cs", None, "support"),
+ ("src/modules/peek/Peek.UITests/PeekFilePreviewTests.cs", None, "test"),
+ ("src/modules/x/FuzzTests/fuzz.cpp", None, "test"),
+ ("src/unitTests/parser.ts", None, "test"),
+ # ...plural only, and only with the capital: singular names one thing
+ ("src/ui/HitTest/hit.cpp", None, ""),
+ ("src/contests/rules.py", None, ""),
+ ("src/Latests/x.cs", None, ""),
+ # gradle test fixtures and QA projects (elasticsearch)
+ ("build-tools/src/testFixtures/java/org/x/Fixture.java", None, "test"),
+ ("x-pack/plugin/sql/qa/server/src/main/java/org/x/JdbcBase.java", None, "test"),
+ ("qa/logging-spi/src/main/java/org/x/Spi.java", None, "test"),
+ ("src/qa/answer.py", None, ""), # a question-answering module
+ ("app/qa/src/model.py", None, ""), # qa is the project itself
+ ("gradle/internal/testfixtures/DeployPlugin.java", None, ""),
+ ("src/testfixtures/pkg/mod.py", None, ""), # the Python testfixtures library
+ ("packages/qa/cli/src/main.ts", None, ""), # shipped QA tooling
+ ("src/qa/tools/src/x.py", None, ""),
+ ("qa/tools/src/report.py", None, ""),
+ ("docs/qa/guide/src/x.md", None, ""),
# rspec: `spec/` is RSpec for ruby and a specification folder otherwise
("spec/models/user_spec.rb", None, "test"), # #1103: one of nine said test
("spec/models/user.rb", "ruby", "test"),