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): class deps/ C libraries, benchmarks, C/C++ test helpers and Cargo examples as non-production (#2958)

Raghav Chamadiya1b89c2915a7a
diff --git a/packages/core/src/repowise/core/code_origin.py b/packages/core/src/repowise/core/code_origin.py
index 0756705dd..c2c60741f 100644
--- a/packages/core/src/repowise/core/code_origin.py
+++ b/packages/core/src/repowise/core/code_origin.py
@@ -220,6 +220,13 @@ def _generated_suffixes() -> tuple[str, ...]:
return tuple(sorted(REGISTRY.generated_suffixes()))
+@cache
+def _deps_suffixes() -> tuple[str, ...]:
+ from .ingestion.languages.registry import REGISTRY
+
+ return tuple(sorted(REGISTRY.extensions_for(_DEPS_LANGUAGES)))
+
+
def _is_generated_name(name: str) -> bool:
return ".generated." in name or name.endswith(_generated_suffixes())
@@ -247,6 +254,13 @@ _VENDORED_DIR_TOKENS = frozenset(
# monorepo's own libraries as it is a copy of someone else's code.
_VENDORED_ROOT_TOKENS = frozenset({"external", "externals"})
_NATIVE_TREE = "native"
+# A ``deps/`` directory holding a library directory (aria2's ``deps/wslay/``,
+# hugo's ``internal/warpc/deps/parson/``). A file directly in ``deps/`` is the
+# repository's own (hugo's ``deps/deps.go``). C and C++ only: those trees copy
+# libraries in by hand, while a Go, Rust or JS ``deps/`` package with
+# sub-packages (``internal/deps/resolver/``) is usually first-party.
+_DEPS_DIR = "deps"
+_DEPS_LANGUAGES = ("c", "cpp")
_MINIFIED_SUFFIXES = (".min.js", ".min.css", ".min.mjs")
@@ -260,6 +274,8 @@ def _is_vendored_path(lowered_name: str, dirs: list[str]) -> bool:
d == _NATIVE_TREE and dirs[i + 1] in _VENDORED_ROOT_TOKENS for i, d in enumerate(dirs[:-2])
):
return True
+ if _DEPS_DIR in dirs[:-1] and lowered_name.endswith(_deps_suffixes()):
+ return True
return lowered_name.endswith(_MINIFIED_SUFFIXES)
@@ -461,9 +477,28 @@ def _is_example_dir(segment: str) -> bool:
return segment in _EXAMPLE_TOKENS or segment.startswith(_TUTORIAL_PREFIX)
-def _is_docs_example(dirs: list[str]) -> bool:
+# Example directories a build tool compiles as examples at any depth, by file
+# suffix: Cargo builds every crate's ``examples/`` as example targets
+# (ripgrep's ``crates/grep/examples/``). Outside a ``src/`` tree only: under
+# it, ``examples`` is a module of the crate.
+_TOOL_EXAMPLE_DIRS = {".rs": "examples"}
+_SOURCE_ROOT = "src"
+
+
+def _is_tool_example(name: str, dirs: list[str]) -> bool:
+ example_dir = _TOOL_EXAMPLE_DIRS.get(PurePosixPath(name).suffix.lower())
+ if example_dir is None or example_dir not in dirs:
+ return False
+ return _SOURCE_ROOT not in dirs[: dirs.index(example_dir)]
+
+
+def _is_docs_example(name: str, dirs: list[str]) -> bool:
# Anything under a docs root already counts, examples beneath it included.
- return any(d in _DOCS_ROOT_TOKENS for d in dirs) or bool(dirs and _is_example_dir(dirs[0]))
+ return (
+ any(d in _DOCS_ROOT_TOKENS for d in dirs)
+ or bool(dirs and _is_example_dir(dirs[0]))
+ or _is_tool_example(name, dirs)
+ )
# No ``/cli/`` rule: a CLI's source ships and its findings are real work (only
@@ -499,6 +534,9 @@ _TOOLING_ROOT_DIRS = frozenset(
_MIGRATION_DIR = "migrations"
_MIGRATION_DIR_PAIRS = frozenset({("db", "migrate"), ("alembic", "versions")})
_TOOLING_ROOT_NAMES = frozenset({"fabfile.py"})
+# Benchmarks kept beside the code they measure (abseil's
+# ``mutex_benchmark.cc``), not in a benchmarks directory.
+_TOOLING_STEM_SUFFIXES = ("_benchmark", "_benchmarks")
# Lint, test and transpiler configs. Bundler configs are build files (above).
_TOOLING_NAME_RE = re.compile(
r"^(?:eslint\.config|jest\.config|vitest\.config|babel\.config|karma\.conf)\.[cm]?[jt]s$"
@@ -566,6 +604,14 @@ def _is_tooling(name: str, dirs: list[str]) -> bool:
or _is_migration_dir(dirs)
or (not dirs and name in _TOOLING_ROOT_NAMES)
or bool(_TOOLING_NAME_RE.match(name.lower()))
+ or _is_benchmark_file(name)
+ )
+
+
+def _is_benchmark_file(name: str) -> bool:
+ lowered = name.lower()
+ return lowered.endswith(_code_suffixes()) and PurePosixPath(lowered).stem.endswith(
+ _TOOLING_STEM_SUFFIXES
)
@@ -617,7 +663,7 @@ def _maintained_origin(
return "build"
if is_test if is_test is not None else is_test_related_path(normalized):
return "test"
- if _is_docs_example(dirs):
+ if _is_docs_example(name, dirs):
return "docs_example"
if _is_tooling(name, dirs):
return "tooling"
diff --git a/packages/core/src/repowise/core/ingestion/languages/specs/c.py b/packages/core/src/repowise/core/ingestion/languages/specs/c.py
index bd1329c69..a72c80acc 100644
--- a/packages/core/src/repowise/core/ingestion/languages/specs/c.py
+++ b/packages/core/src/repowise/core/ingestion/languages/specs/c.py
@@ -23,13 +23,22 @@ BUILTIN_TYPES: frozenset[str] = frozenset(
}
)
+#: Stems of the helpers C and C++ tests share. Exported for cpp, which keeps
+#: the same test conventions.
+TEST_SUPPORT_STEM_SUFFIXES: tuple[str, ...] = (
+ "_test_helper",
+ "_test_helpers",
+ "_test_util",
+ "_test_impl",
+)
+
SPEC = LanguageSpec(
tag="c",
display_name="C",
import_support="full",
# Same test conventions as C++ (GoogleTest/Unity): foo_test.c / test_foo.c.
test_stem_prefixes=("test_",),
- test_stem_suffixes=("_test", "_unittest"),
+ test_stem_suffixes=("_test", "_unittest", *TEST_SUPPORT_STEM_SUFFIXES),
# A top-level include/ holds a C library's installed public headers —
# its API surface (libuv, curl, openssl layouts). Root-anchored: a
# vendored include/ deep in another tree must not mint the layer.
diff --git a/packages/core/src/repowise/core/ingestion/languages/specs/cpp.py b/packages/core/src/repowise/core/ingestion/languages/specs/cpp.py
index 4ca1e1cef..d8688e228 100644
--- a/packages/core/src/repowise/core/ingestion/languages/specs/cpp.py
+++ b/packages/core/src/repowise/core/ingestion/languages/specs/cpp.py
@@ -2,6 +2,7 @@
from ..spec import LanguageSpec
from .c import BUILTIN_TYPES as _C_BUILTIN_TYPES
+from .c import TEST_SUPPORT_STEM_SUFFIXES
#: Include fragments: C++ source that is ``#include``d into a translation unit
#: rather than compiled as one of its own. The convention carries inline and
@@ -26,9 +27,11 @@ SPEC = LanguageSpec(
tag="cpp",
display_name="C++",
import_support="full",
- # GoogleTest conventions: foo_test.cc / foo_unittest.cc / test_foo.cpp.
+ # GoogleTest conventions: foo_test.cc / foo_unittest.cc / test_foo.cpp,
+ # and the helpers tests share (abseil's cord_test_helpers.h,
+ # distribution_test_util.h, log_basic_test_impl.inc).
test_stem_prefixes=("test_",),
- test_stem_suffixes=("_test", "_unittest"),
+ test_stem_suffixes=("_test", "_unittest", *TEST_SUPPORT_STEM_SUFFIXES),
# A top-level include/ holds a C++ library's installed public headers —
# its API surface (fmt, leveldb, boost layouts). Root-anchored: a
# vendored include/ deep in another tree must not mint the layer.
diff --git a/tests/unit/ingestion/test_language_capabilities.py b/tests/unit/ingestion/test_language_capabilities.py
index 2b708d5e3..41b2a968d 100644
--- a/tests/unit/ingestion/test_language_capabilities.py
+++ b/tests/unit/ingestion/test_language_capabilities.py
@@ -52,8 +52,17 @@ class TestParityGoldens:
def test_test_stem_suffixes_match_historical_set(self) -> None:
# "_unittest" (C/C++ GoogleTest convention) was a conscious
- # addition to the historical {"_test", "_spec"} union.
- assert set(REGISTRY.test_stem_suffixes()) == {"_test", "_spec", "_unittest"}
+ # addition to the historical {"_test", "_spec"} union, and so are the
+ # C/C++ test-helper stems (cord_test_helpers.h, log_basic_test_impl.inc).
+ assert set(REGISTRY.test_stem_suffixes()) == {
+ "_test",
+ "_spec",
+ "_unittest",
+ "_test_helper",
+ "_test_helpers",
+ "_test_util",
+ "_test_impl",
+ }
def test_test_infixes_match_historical_set(self) -> None:
# `.test-d.` is the TypeScript type-test infix (`*.test-d.ts`).
diff --git a/tests/unit/test_code_origin.py b/tests/unit/test_code_origin.py
index a968cb02c..3b28e0b33 100644
--- a/tests/unit/test_code_origin.py
+++ b/tests/unit/test_code_origin.py
@@ -450,3 +450,33 @@ def test_build_rs_under_src_is_a_dead_code_root_but_keeps_its_origin() -> None:
assert code_origin("src/bootstrap/build.rs") == "production"
assert code_origin("crates/cli/src/commands/build.rs") == "production"
assert not is_build_file("src/build.rs")
+
+
+ ("path", "expected"),
+ [
+ # A deps/ directory holding a library is a vendored copy.
+ ("deps/wslay/lib/wslay_event.c", "vendored"),
+ ("internal/warpc/deps/parson/parson.c", "vendored"),
+ ("deps/deps.go", "production"), # hugo's own package named deps
+ # C and C++ only: a first-party deps package elsewhere stays production.
+ ("internal/deps/resolver/resolve.go", "production"),
+ ("src/deps/graph/mod.rs", "production"),
+ ("lib/deps/tree/walk.js", "production"),
+ ("deps/wslay.c", "production"), # directly in deps/, no library directory
+ ("src/deps.py", "production"),
+ # Benchmarks beside the code they measure are tooling.
+ ("absl/synchronization/mutex_benchmark.cc", "tooling"),
+ ("absl/random/internal/randen_benchmarks.cc", "tooling"),
+ ("absl/synchronization/mutex.cc", "production"),
+ ("src/benchmark_runner.py", "production"),
+ # Cargo builds every crate's examples/ as example targets.
+ ("crates/grep/examples/simplegrep.rs", "docs_example"),
+ ("apps/examples/desktop-app/src-tauri/src/main.rs", "docs_example"),
+ ("crates/core/src/examples/registry.rs", "production"), # a module of the crate
+ ("pkg/x/examples/a.py", "production"), # other languages: root only
+ ("src/main/kotlin/org/example/App.kt", "production"),
+ ],
+)
+def test_deps_benchmarks_and_cargo_examples(path: str, expected: str) -> None:
+ assert code_origin(path) == expected
diff --git a/tests/unit/test_test_paths.py b/tests/unit/test_test_paths.py
index fa0367b22..c5592137c 100644
--- a/tests/unit/test_test_paths.py
+++ b/tests/unit/test_test_paths.py
@@ -197,6 +197,13 @@ _CORPUS: tuple[tuple[str, str | None, str], ...] = (
# Support directories count anywhere, .github included.
(".github/test-data/expected.json", None, "support"),
(".github/actions/notify/__snapshots__/Button.snap", None, "support"),
+ # C/C++ helpers shared by tests (abseil, leveldb)
+ ("absl/strings/cord_test_helpers.h", None, "test"),
+ ("absl/random/internal/distribution_test_util.cc", None, "test"),
+ ("absl/log/log_basic_test_impl.inc", None, "test"),
+ ("util/env_posix_test_helper.h", None, "test"),
+ ("absl/strings/str_cat.h", None, ""),
+ ("crates/searcher/src/searcher/util.rs", None, ""),
)