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(workspace): skip .NET test projects in contract extraction (#2828)

Yang Baie78a226a8cdf
diff --git a/packages/core/src/repowise/core/workspace/extractors/base.py b/packages/core/src/repowise/core/workspace/extractors/base.py
index a0795e844..9685bbcfc 100644
--- a/packages/core/src/repowise/core/workspace/extractors/base.py
+++ b/packages/core/src/repowise/core/workspace/extractors/base.py
@@ -18,6 +18,8 @@ from fnmatch import fnmatch
from pathlib import Path
from typing import TYPE_CHECKING
+from repowise.core.ingestion.languages.registry import REGISTRY
+
if TYPE_CHECKING:
from repowise.core.workspace.repo_index import RepoIndex
@@ -31,6 +33,14 @@ if TYPE_CHECKING:
# patterns below.
_TEST_DIR_SEGMENTS = frozenset({"tests", "__tests__", "__mocks__"})
+# .NET test projects are sibling directories named after the project under test
+# (``Foo.Tests/``, case-sensitive), not a ``tests/`` tree. Read from the language
+# registry so a suffix added there is excluded here too. ``.Specs`` is left out
+# for the reason ``spec/`` is above: it can hold real OpenAPI or proto contracts.
+_TEST_PROJECT_DIR_SUFFIXES = tuple(
+ suffix for suffix in REGISTRY.test_dir_suffixes() if suffix != ".Specs"
+)
+
# Filename patterns that mark a test file regardless of directory.
_TEST_FILE_PATTERNS = (
"test_*.py",
@@ -64,7 +74,9 @@ def line_at(content: str, offset: int) -> int:
def is_test_path(rel_path: str) -> bool:
"""True when *rel_path* (POSIX) lives in a test tree or is a test file."""
parts = rel_path.split("/")
- if any(seg in _TEST_DIR_SEGMENTS for seg in parts[:-1]):
+ if any(
+ seg in _TEST_DIR_SEGMENTS or seg.endswith(_TEST_PROJECT_DIR_SUFFIXES) for seg in parts[:-1]
+ ):
return True
name = parts[-1]
return any(fnmatch(name, pat) for pat in _TEST_FILE_PATTERNS)
diff --git a/tests/unit/workspace/test_dialect_regressions.py b/tests/unit/workspace/test_dialect_regressions.py
index f177c1315..947dd17dd 100644
--- a/tests/unit/workspace/test_dialect_regressions.py
+++ b/tests/unit/workspace/test_dialect_regressions.py
@@ -125,6 +125,29 @@ class TestExtractorSelfExclusion:
assert skip("vendor/thing.py")
assert not skip("app/thing.py")
+ def test_dotnet_test_projects_are_skipped(self) -> None:
+ # A .NET test project is a sibling directory named after the project
+ # it tests, not a `tests/` tree. Its HTTP calls and published messages
+ # became producers and consumers linked across repos (#2808).
+ skip = make_exclude_predicate()
+ assert skip("Foo.Worker.Tests/OrderPlacedTests.cs")
+ assert skip("src/Billing.Tests/Consumers/InvoiceConsumerTests.vb")
+
+ def test_a_dotnet_specs_project_is_still_scanned(self) -> None:
+ # Left in for the reason a `spec/` directory is: it can hold real
+ # OpenAPI or proto contracts.
+ skip = make_exclude_predicate()
+ assert not skip("Foo.Specs/openapi.yaml")
+
+ def test_a_name_that_only_ends_like_a_test_project_is_still_scanned(self) -> None:
+ skip = make_exclude_predicate()
+ assert not skip("LoadTests/Runner.cs")
+ assert not skip("src/Foo.Testing/Clients/OrdersClient.cs")
+
+ def test_dotnet_test_projects_are_scanned_when_tests_are_included(self) -> None:
+ skip = make_exclude_predicate(exclude_tests=False)
+ assert not skip("Foo.Worker.Tests/OrderPlacedTests.cs")
+
class TestSqlCteAlias:
"""Regression 3: ``WITH ranked AS (...)`` emitted a table named ``ranked``."""