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(dead-code): keep rust sibling test modules live (#332)

biggiesmallcap-blip03a268940a33
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 2ef670826..2dfbd6070 100644
--- a/packages/core/src/repowise/core/analysis/dead_code/constants.py
+++ b/packages/core/src/repowise/core/analysis/dead_code/constants.py
@@ -9,7 +9,6 @@ from __future__ import annotations
from repowise.core.ingestion.languages.registry import REGISTRY as _LANG_REGISTRY
-
# Non-code languages that should never be flagged as dead code.
# Derived from the centralised LanguageRegistry — passthrough config/infra
# languages plus "unknown".
@@ -483,6 +482,9 @@ _NEVER_FLAG_PATTERNS: tuple[str, ...] = (
"**/tests/**/*.rs",
"tests/*.rs",
"tests/**/*.rs",
+ # Unit-test sibling modules (e.g. `src/foo/tests.rs`) are loaded by
+ # `#[cfg(test)] mod tests;` and the Cargo test harness, not production imports.
+ "**/src/**/tests.rs",
# Binary targets (separate executables in a crate)
"**/src/bin/*.rs",
"**/src/bin/**/*.rs",
@@ -967,7 +969,6 @@ _NEVER_PACKAGE_DIRS: frozenset[str] = frozenset({
".circleci",
".buildkite",
".cargo",
- ".husky",
".yarn",
"docs",
"doc",
diff --git a/tests/unit/dead_code/test_rust_tests_module.py b/tests/unit/dead_code/test_rust_tests_module.py
new file mode 100644
index 000000000..48d202a2f
--- /dev/null
+++ b/tests/unit/dead_code/test_rust_tests_module.py
@@ -0,0 +1,47 @@
+"""Rust sibling test modules should not be reported as dead code."""
+
+from __future__ import annotations
+
+from repowise.core.analysis.dead_code import DeadCodeAnalyzer, DeadCodeKind
+from tests.unit.dead_code._helpers import _build_graph
+
+
+def test_rust_sibling_tests_module_never_flagged() -> None:
+ analyzer = DeadCodeAnalyzer(_build_graph(nodes={}), git_meta_map={})
+
+ assert analyzer._should_never_flag("noor-server/src/server/routes/tests.rs", set())
+
+
+def test_rust_sibling_tests_module_not_reported_unreachable() -> None:
+ analyzer = DeadCodeAnalyzer(
+ _build_graph(
+ nodes={
+ "noor-server/src/server/routes/tests.rs": {
+ "is_entry_point": False,
+ "language": "rust",
+ "symbol_count": 1,
+ "symbols": [],
+ },
+ "noor-server/src/lib.rs": {
+ "is_entry_point": True,
+ "language": "rust",
+ "symbol_count": 1,
+ "symbols": [],
+ },
+ }
+ ),
+ git_meta_map={},
+ )
+
+ report = analyzer.analyze(
+ {
+ "detect_unused_exports": False,
+ "detect_unused_internal": False,
+ "detect_zombie_packages": False,
+ }
+ )
+
+ unreachable = [
+ finding for finding in report.findings if finding.kind == DeadCodeKind.UNREACHABLE_FILE
+ ]
+ assert unreachable == []