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(test-paths): count __mocks__ anywhere and the other .NET test-project suffixes (#2669)

Yang Baib6b3deb663c5
diff --git a/packages/core/src/repowise/core/ingestion/languages/specs/csharp.py b/packages/core/src/repowise/core/ingestion/languages/specs/csharp.py
index 0d5c4b657..8f1d7c518 100644
--- a/packages/core/src/repowise/core/ingestion/languages/specs/csharp.py
+++ b/packages/core/src/repowise/core/ingestion/languages/specs/csharp.py
@@ -7,9 +7,21 @@ SPEC = LanguageSpec(
display_name="C#",
import_support="full",
# xUnit/NUnit conventions: FooTest(s)/FooSpec(s); sibling Foo.Tests/
- # and BDD-style Foo.Specs/ projects (Polly's test/Polly.Specs).
+ # and BDD-style Foo.Specs/ projects (Polly's test/Polly.Specs), plus the
+ # Foo.UnitTests / Foo.IntegrationTests / Foo.FunctionalTests / Foo.FuzzTests
+ # spellings (PowerToys' Settings.UI.UnitTests, Hosts.FuzzTests) and the
+ # singular Foo.UnitTest (#2662). Case-sensitive whole-suffix matches, so a
+ # shipped Foo.Testing/ library stays production code.
test_camel_suffixes=("Test", "Tests", "Spec", "Specs"),
- test_dir_suffixes=(".Tests", ".Specs"),
+ test_dir_suffixes=(
+ ".Tests",
+ ".Specs",
+ ".UnitTests",
+ ".IntegrationTests",
+ ".FunctionalTests",
+ ".FuzzTests",
+ ".UnitTest",
+ ),
# Clean-architecture project-dir suffixes (Foo.Api/, Foo.Domain/,
# Foo.Infrastructure/) — not yet verified against a live .NET repo.
layer_dir_hints=((".Api", "API"), (".Domain", "Service"), (".Infrastructure", "Data")),
diff --git a/packages/core/src/repowise/core/ingestion/languages/specs/vbnet.py b/packages/core/src/repowise/core/ingestion/languages/specs/vbnet.py
index bd3a1c533..9b5c495bb 100644
--- a/packages/core/src/repowise/core/ingestion/languages/specs/vbnet.py
+++ b/packages/core/src/repowise/core/ingestion/languages/specs/vbnet.py
@@ -7,9 +7,18 @@ SPEC = LanguageSpec(
display_name="VB.NET",
import_support="full",
# VB.NET tests follow the MSTest/xUnit conventions (FooTests/FooTest),
- # mostly as sibling files in the same project.
+ # mostly as sibling files in the same project. Test-project directory
+ # suffixes are the .NET set shared with csharp (#2662).
test_camel_suffixes=("Test", "Tests", "Spec", "Specs"),
- test_dir_suffixes=(".Tests", ".Specs"),
+ test_dir_suffixes=(
+ ".Tests",
+ ".Specs",
+ ".UnitTests",
+ ".IntegrationTests",
+ ".FunctionalTests",
+ ".FuzzTests",
+ ".UnitTest",
+ ),
extensions=frozenset({".vb"}),
grammar_package="tree_sitter_vb_dotnet",
scm_file="vbnet.scm",
diff --git a/packages/core/src/repowise/core/test_paths.py b/packages/core/src/repowise/core/test_paths.py
index e6d04020c..92d62955f 100644
--- a/packages/core/src/repowise/core/test_paths.py
+++ b/packages/core/src/repowise/core/test_paths.py
@@ -122,7 +122,7 @@ _TEST_EXACT_STEMS: frozenset[str] = frozenset({"test", "tests"})
# not. A test-shaped filename still wins over them, so
# ``tests/helpers/test_builders.py`` stays a test.
_SUPPORT_DIR_TOKENS: frozenset[str] = frozenset(
- {"fixtures", "factories", "support", "helpers", "mocks", "__mocks__"}
+ {"fixtures", "factories", "support", "helpers", "mocks"}
)
# Scaffolding directories whose names mean test material *wherever* they sit,
@@ -131,15 +131,18 @@ _SUPPORT_DIR_TOKENS: frozenset[str] = frozenset(
# product directories (a sports app's fixtures list), and on this repo plus its
# two siblings 230 of 231 ``fixtures/`` files already sit inside a test tree, so
# the tree requirement costs nothing and the widening would buy nothing.
-# ``__fixtures__`` is the same convention with the JS dunder wrapper that
-# ``__tests__``/``__mocks__`` use, and carries no other meaning. ``testdata`` is
-# the Go convention the toolchain itself reserves - ``go build`` ignores any
-# directory of that name - which is why it needs no Go file to corroborate it:
-# the golden files inside are JSON and YAML, and asking the file's own language
-# would never fire on them. ``__snapshots__`` is where Jest and Vitest write the
-# ``.snap`` output a snapshot test compares against; the ``.test.`` infix used to
-# catch those files by accident, and stopped once filename rules became source
-# rules.
+# ``__fixtures__`` and ``__mocks__`` are the same convention with the JS dunder
+# wrapper that ``__tests__`` uses, and carry no other meaning. Jest reads manual
+# mocks from a root ``__mocks__/`` beside ``node_modules`` and from a
+# ``__mocks__/`` beside the module it replaces, so neither sits in a test tree
+# (#2662); bare ``mocks`` stays above, because it names product code too.
+# ``testdata`` is the Go convention the toolchain itself reserves - ``go build``
+# ignores any directory of that name - which is why it needs no Go file to
+# corroborate it: the golden files inside are JSON and YAML, and asking the
+# file's own language would never fire on them. ``__snapshots__`` is where Jest
+# and Vitest write the ``.snap`` output a snapshot test compares against; the
+# ``.test.`` infix used to catch those files by accident, and stopped once
+# filename rules became source rules.
#
# Support rather than test, deliberately: golden data is what a test reads, not
# a test. So the union counts it (#1103's reporter asked for exactly that) while
@@ -147,7 +150,7 @@ _SUPPORT_DIR_TOKENS: frozenset[str] = frozenset(
# Matched on the segment's words run together too, so ``test-data/`` and
# ``test_data/`` are the same golden data rather than a test tree.
_SUPPORT_DIR_TOKENS_ANYWHERE: frozenset[str] = frozenset(
- {"__fixtures__", "__snapshots__", "testdata"}
+ {"__fixtures__", "__mocks__", "__snapshots__", "testdata"}
)
diff --git a/tests/unit/ingestion/test_language_capabilities.py b/tests/unit/ingestion/test_language_capabilities.py
index 41b2a968d..eb2a599d8 100644
--- a/tests/unit/ingestion/test_language_capabilities.py
+++ b/tests/unit/ingestion/test_language_capabilities.py
@@ -140,7 +140,15 @@ class TestParityGoldens:
def test_test_dir_suffixes_union(self) -> None:
# .Specs = BDD-style sibling test projects (Polly, validated live).
- assert REGISTRY.test_dir_suffixes() == (".Specs", ".Tests")
+ assert REGISTRY.test_dir_suffixes() == (
+ ".FunctionalTests",
+ ".FuzzTests",
+ ".IntegrationTests",
+ ".Specs",
+ ".Tests",
+ ".UnitTest",
+ ".UnitTests",
+ )
# ---------------------------------------------------------------------------
diff --git a/tests/unit/test_test_paths.py b/tests/unit/test_test_paths.py
index c5592137c..9c4ffde21 100644
--- a/tests/unit/test_test_paths.py
+++ b/tests/unit/test_test_paths.py
@@ -204,6 +204,24 @@ _CORPUS: tuple[tuple[str, str | None, str], ...] = (
("util/env_posix_test_helper.h", None, "test"),
("absl/strings/str_cat.h", None, ""),
("crates/searcher/src/searcher/util.rs", None, ""),
+ # #2662: Jest manual mocks live in a root `__mocks__/` beside node_modules or
+ # beside the mocked module, never in a test tree, so the dunder dir counts
+ # wherever it sits, like `__fixtures__`. Bare `mocks` stays tree-gated: this
+ # repo's analysis/health/mocks/ and ktor-client-mock are product code.
+ ("__mocks__/axios.js", None, "support"),
+ ("src/__mocks__/api.ts", None, "support"),
+ ("src/__mocks__/api.test.ts", None, "test"), # a test-shaped name still wins
+ ("src/mocks/handlers.ts", None, ""),
+ ("packages/core/src/repowise/core/analysis/health/mocks/lexicon.py", None, ""),
+ ("ktor-client-mock/common/src/io/ktor/client/engine/mock/MockEngine.kt", None, ""),
+ # #2662: .NET test projects are also named Foo.UnitTests, Foo.IntegrationTests
+ # and Foo.FuzzTests (PowerToys). A shipped Foo.Testing library is not one, and a
+ # scaffolding dir inside a test project is support, as under tests/.
+ ("Settings.UI.UnitTests/ViewModelTests/General.cs", None, "test"),
+ ("Hosts.FuzzTests/Fuzz.cs", None, "test"),
+ ("Foo.IntegrationTests/Sql/Db.cs", None, "test"),
+ ("Foo.IntegrationTests/Helpers/Db.cs", None, "support"),
+ ("src/Polly.Testing/ResiliencePipelineExtensions.cs", None, ""),
)