Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(health): classify build files once by type and read that everywhere (#2954)
Raghav Chamadiya109823d06fae
diff --git a/docs/layers/CODE_HEALTH.md b/docs/layers/CODE_HEALTH.mdindex 5f093bbb3..2356925eb 100644--- a/docs/layers/CODE_HEALTH.md+++ b/docs/layers/CODE_HEALTH.md@@ -648,7 +648,7 @@ that is worth doing. Everything else is left out and counted in| Reason | What it leaves out ||---|---|| `test` | Test files. `scope=all` keeps them, labelled. |-| `tooling` | Scripts, tools, benchmarks, build and CI files, migrations, and code under a directory whose role is unknown (docs, demos). |+| `tooling` | Scripts, tools, benchmarks, CI files, migrations, code under a directory whose role is unknown (docs, demos), and build files by type wherever they sit (Gradle scripts, `CMakeLists.txt`, `*.cmake`, Makefiles, Bazel files, MSBuild `.props` / `.targets`, root `setup.py`, `noxfile.py`, crate-root `build.rs`, bundler configs). || `generated` | Generated files. || `vendored` | Third-party code: `vendor/`, `third_party/`, `node_modules/` and similar directories, minified files, and a library with its own license header among served assets. || `docs_example` | Documentation code and examples: `docs/`, `docs_src/`, `examples/`, tutorials, samples. |diff --git a/docs/layers/DEAD_CODE.md b/docs/layers/DEAD_CODE.mdindex 646c378af..b805aeb89 100644--- a/docs/layers/DEAD_CODE.md+++ b/docs/layers/DEAD_CODE.md@@ -189,10 +189,11 @@ these, so they are never flagged rather than flagged and down-weighted.| Group | Examples ||-------|---------|-| Entry points | Anything the graph marked `is_entry_point`, plus `__init__.py`, `__main__.py`, `conftest.py`, `manage.py`, `wsgi.py`, `asgi.py`, `setup.py`, `main.go`, `build.rs` |+| Entry points | Anything the graph marked `is_entry_point`, plus `__init__.py`, `__main__.py`, `conftest.py`, `manage.py`, `wsgi.py`, `asgi.py`, `setup.py`, `main.go` |+| Build files | Any file a build tool runs by name, classified by type in `code_origin`: Gradle `*.gradle(.kts)`, `pom.xml`, `CMakeLists.txt`, `*.cmake`, Makefiles, `meson.build`, Bazel `BUILD` / `*.bzl`, MSBuild `.props` / `.targets`, crate-root `build.rs`, `magefile.go`, `noxfile.py`, bundler configs. A directory holding only build files is not a package || Shell scripts | `*.sh`, `*.bash`, `*.zsh`. Invoked by name from CI configs and Makefiles; static reachability is meaningless || Programs | Any file whose first line is a shebang, and any Python file with a top-level `if __name__ == "__main__":` block. Nothing imports an entry point |-| Files a runner names | A file a CI workflow (`.github/workflows/`, `.gitlab-ci.yml`, `.circleci/`, `.buildkite/`), build or task file (`Makefile`, `Justfile`, `Dockerfile`, `noxfile.py`, `tox.ini`), manifest (`pyproject.toml`, `package.json`, `setup.cfg`) or shell script names by path. A doc that names a file only caps it at `0.40` |+| Files a runner names | A file a CI workflow (`.github/workflows/`, `.gitlab-ci.yml`, `.circleci/`, `.buildkite/`), build file (above), task file (`Dockerfile`, `tox.ini`), manifest (`pyproject.toml`, `package.json`, `setup.cfg`) or shell script names by path. A doc that names a file only caps it at `0.40` || Framework routes | Next.js `page.tsx` / `layout.tsx` / `route.ts` / `middleware.ts`, SvelteKit `+page.svelte`, Nuxt `pages/*.vue`, Remix entry files, ASP.NET minimal-API `Apis/` / `Endpoints/`, Blazor and Razor code-behind || Test files | `*_test.go`, `*.test.ts`, `*.spec.ts`, `*_test.cc`, `*Test.java`, `**/tests/*.rs`, `src/test/java/`, MSTest and xUnit project layouts, `__tests__/`, `__mocks__/` || Generated code | protoc `*.pb.go` / `*.pb.cs` / `*.pb.cc`, Qt MOC/UIC/RCC, Bison/Flex, SWIG, Cython, stringer, MapStruct `*MapperImpl.java`, Dagger, AutoValue, Roslyn `*.g.cs`, Dart `*.g.dart` / `*.freezed.dart`, `**/generated/**` |diff --git a/packages/core/src/repowise/core/analysis/dead_code/analyzer.py b/packages/core/src/repowise/core/analysis/dead_code/analyzer.pyindex bf3a1ff08..e31b2d618 100644--- a/packages/core/src/repowise/core/analysis/dead_code/analyzer.py+++ b/packages/core/src/repowise/core/analysis/dead_code/analyzer.py@@ -22,6 +22,7 @@ from typing import Anyimport structlog+from ...code_origin import is_build_filefrom ...entry_candidacy import is_reachability_rootfrom ...ingestion.models import REACHABILITY_USE_EDGE_TYPESfrom ...ingestion.symbol_identity import base_symbol_id, overload_sets@@ -2019,10 +2020,12 @@ class DeadCodeAnalyzer:return False# A real package contains at least one source file something could# import. Config and data (YAML, JSON, MD, TOML) is metadata, and a- # folder of Dockerfiles and shell scripts is run, never imported.+ # folder of Dockerfiles, shell scripts and build files is run, never+ # imported.return any(self.graph.nodes.get(f, {}).get("language", "unknown")not in _DEAD_CODE_EXEMPT_LANGUAGES | _RUN_NOT_IMPORTED_LANGUAGES+ and not is_build_file(f)for f in files)diff --git a/packages/core/src/repowise/core/analysis/dead_code/constants.py b/packages/core/src/repowise/core/analysis/dead_code/constants.pyindex 2acb86eb8..463654114 100644--- a/packages/core/src/repowise/core/analysis/dead_code/constants.py+++ b/packages/core/src/repowise/core/analysis/dead_code/constants.py@@ -16,7 +16,7 @@ import osimport refrom functools import lru_cache-from repowise.core.code_origin import is_vendored_or_generated_path+from repowise.core.code_origin import is_build_file, is_vendored_or_generated_pathfrom repowise.core.ingestion.languages.registry import REGISTRY as _LANG_REGISTRY# Non-code languages (registry passthrough languages plus "unknown").@@ -467,9 +467,7 @@ _NEVER_FLAG_PATTERNS: tuple[str, ...] = ("submodules/**","*/.deps/**",# ---- Rust / Cargo conventions ----------------------------------------- # Build scripts (executed by Cargo at compile time, never imported)- "**/build.rs",- "build.rs",+ # Build scripts are build files (``code_origin.is_build_file``).# Examples (run via `cargo run --example <name>`)"**/examples/*.rs","**/examples/**/*.rs",@@ -516,10 +514,6 @@ _NEVER_FLAG_PATTERNS: tuple[str, ...] = ("doc.go","*/docs.go","docs.go",- # Mage build files (``//go:build mage``, ``package main``) — run by the- # ``mage`` tool, excluded from normal builds, never imported.- "*/magefile.go",- "magefile.go",# Generated code (stringer, protobuf, go-bindata, ``zz_generated*``)."*.gen.go","*_gen.go",@@ -974,19 +968,14 @@ _CONTAINER_USE_LANGUAGES: frozenset[str] = frozenset({"csharp"})_RUN_NOT_IMPORTED_LANGUAGES: frozenset[str] = frozenset({"dockerfile", "makefile", "shell"})# Files that run, build or ship what they name by path: CI workflows, build-# and task files, package manifests and shell scripts. A file named there is-# executed or packaged, which is a use, not a mention.+# files (``code_origin.is_build_file``), task files, package manifests and+# shell scripts. A file named there is executed or packaged, which is a use,+# not a mention._RUNNER_FILE_NAMES: frozenset[str] = frozenset({- "Makefile",- "makefile",- "GNUmakefile",- "Justfile",- "justfile","Dockerfile","Jenkinsfile","Procfile",- "noxfile.py","tox.ini","pyproject.toml","setup.cfg",@@ -1004,6 +993,7 @@ def is_runner_file(path: str) -> bool:name = path.rpartition("/")[2]return (name in _RUNNER_FILE_NAMES+ or is_build_file(path)or name.startswith("Dockerfile")or name.endswith(_RUNNER_SUFFIXES)or any(f"/{d}" in f"/{path}" for d in _RUNNER_DIRS)@@ -1186,12 +1176,13 @@ def never_flag_match(path: str) -> bool:def never_flag_path(path: str) -> bool:- """The never-flag globs, plus vendored and generated code by path.+ """The never-flag globs, plus vendored, generated and build files by path.A copied library or a generator's output is not this repository's to- delete, whatever its importers look like.+ delete, whatever its importers look like, and a build tool runs a build+ file by its name, so it has no importer by design."""- return never_flag_match(path) or is_vendored_or_generated_path(path)+ return never_flag_match(path) or is_vendored_or_generated_path(path) or is_build_file(path)def _is_fixture_path(path: str) -> bool:diff --git a/packages/core/src/repowise/core/analysis/health/fix_first/build.py b/packages/core/src/repowise/core/analysis/health/fix_first/build.pyindex cd786d2d2..6122b6aa6 100644--- a/packages/core/src/repowise/core/analysis/health/fix_first/build.py+++ b/packages/core/src/repowise/core/analysis/health/fix_first/build.py@@ -57,11 +57,11 @@ from repowise.core.analysis.health.perf.opportunity_rank import (DEFAULT_QUEUE_CONTEXTS,default_queue_exclusion,)-from repowise.core.analysis.health.refactoring.extract_helper import _is_generated_pathfrom repowise.core.analysis.health.rows import detail_map, field, json_fieldfrom repowise.core.analysis.health.scoring import biomarker_dimensionfrom repowise.core.analysis.health.suggestions import suggestion_forfrom repowise.core.analysis.next_call import ActionCommand+from repowise.core.code_origin import path_originfrom . import textfrom .model import (@@ -181,14 +181,15 @@ class _Unit:may_lead: bool = True-_VENDORED = frozenset({"vendor", "third_party", "thirdparty", "node_modules"})-#: Stored code origins that do not ship, by the exclusion each counts as.+#: Code origins that do not ship, by the exclusion each counts as. A build+#: script is tooling to a reader choosing what to fix._ORIGIN_EXCLUSION = {"test": "test","vendored": "vendored","docs_example": "docs_example","generated": "generated","tooling": "tooling",+ "build": "tooling",}@@ -212,24 +213,23 @@ def _path_exclusion(The stored ``code_origin`` decides first: it read the file's head, so itknows a vendored library or a docs tutorial the path alone does not.- Then the path rules. Code-shape work reads :func:`code_context`, where a- CLI ships. A performance fix passes ``production``: its stored execution- context is judged by the performance default queue, so only the path- rules apply. The stored ``is_test`` flag also marks a test.+ Then the same classifier on the path (an index stored before the origin+ column, or a build file classed before build files were), then the path+ context. Code-shape work reads :func:`code_context`, where a CLI ships. A+ performance fix passes ``production``: its stored execution context is+ judged by the performance default queue. The stored ``is_test`` flag also+ marks a test."""if origin in _ORIGIN_EXCLUSION:return _ORIGIN_EXCLUSION[origin]ctx = context or _code_context(path)if is_test or ctx == "test":return "test"- parts = set(path.lower().split("/")[:-1])- if parts & _VENDORED:- return "vendored"- if _is_generated_path(path):- return "generated"- # ``unknown`` under a directory is docs, examples or demos: code that does- # not ship. A root-level file stays eligible.- if ctx == "tooling" or (ctx == "unknown" and parts):+ if reason := _ORIGIN_EXCLUSION.get(path_origin(path)):+ return reason+ # ``unknown`` under a directory is docs, examples or demos at any depth:+ # code that may not ship. A root-level file stays eligible.+ if ctx == "tooling" or (ctx == "unknown" and "/" in path):return "tooling"return Nonediff --git a/packages/core/src/repowise/core/analysis/health/models.py b/packages/core/src/repowise/core/analysis/health/models.pyindex 363f3b9c6..e7f1198da 100644--- a/packages/core/src/repowise/core/analysis/health/models.py+++ b/packages/core/src/repowise/core/analysis/health/models.py@@ -189,7 +189,7 @@ class HealthFileMetricData:# production reads a column instead of re-deriving the answer.is_test: bool = False# Where the file's code comes from: ``production``, ``test``, ``vendored``,- # ``docs_example``, ``generated`` or ``tooling``+ # ``docs_example``, ``generated``, ``tooling`` or ``build``# (:func:`repowise.core.code_origin.code_origin`). ``None`` when unknown.code_origin: str | None = Nonediff --git a/packages/core/src/repowise/core/analysis/health/perf/causal.py b/packages/core/src/repowise/core/analysis/health/perf/causal.pyindex d0dadd61b..ae9060b6d 100644--- a/packages/core/src/repowise/core/analysis/health/perf/causal.py+++ b/packages/core/src/repowise/core/analysis/health/perf/causal.py@@ -17,10 +17,10 @@ import hashlibimport jsonimport refrom collections import defaultdict-from itertools import pairwisefrom typing import Any, Literal-from repowise.core.test_paths import is_test_related_path+from repowise.core.code_origin import path_origin+from repowise.core.support_paths import DOC_DIR_TOKENS, EXAMPLE_DIR_TOKENSfrom .facts import ObservationFacts, detail_map, is_performance, observation_facts@@ -53,71 +53,37 @@ CausalKey = tuple[Any, ...]_ID_PREFIX = "perf"_ID_PATTERN = re.compile(rf"^{_ID_PREFIX}(\d*)_[0-9a-f]{{20}}$")-_TOOLING_PARTS = frozenset(- {- ".github",- "benchmarks",- "build",- "devtools",- # Schema migrations run once per deploy, not per request: Django and- # Flask-Migrate ``migrations/``, EF Core ``Migrations/``.- "migrations",- "scripts",- "tooling",- "tools",- }-)--_TOOLING_DIR_PAIRS = frozenset({("db", "migrate"), ("alembic", "versions")})-"""Adjacent directories that mark migrations where neither name does alone.--Rails keeps them in ``db/migrate``. Alembic keeps them in ``versions/`` under-its script directory; a bare ``versions/`` is too common (API versions) to-class on its own. Ceiling: an Alembic script directory with another name is-recognised only by its sibling ``env.py``, which a path-only classifier cannot-see.-"""--_UNCLASSIFIABLE_PARTS = frozenset(- {- "demo",- "demos",- "doc",- "docs",- "example",- "examples",- "sample",- "samples",- "third_party",- "thirdparty",- "vendor",- }-)-"""Directories that do not say whether their code ships.--Reporting these as production would assert exposure the tree does not support,-which is the one thing the fallback must not do.-"""+# Origins whose code may or may not ship: a copied library, a generator's+# output, a docs tree. Calling such code production would assert an exposure+# the tree does not support, which is the one thing the fallback must not do.+_UNKNOWN_ORIGINS = frozenset({"vendored", "generated", "docs_example"})+_TOOLING_ORIGINS = frozenset({"tooling", "build"})+# Example, demo and docs trees at any depth. Not ``website/``: a site can serve+# a shipped installer script.+_UNKNOWN_DIRS = EXAMPLE_DIR_TOKENS | (DOC_DIR_TOKENS - {"website"})def code_context(file_path: str) -> ExecutionContext:"""Whether this code ships, without :func:`execution_context`'s CLI rule.- A CLI is product code an edit can improve, so code-shape surfaces read- this; only performance treats a CLI loop as off the request path.+ Read from the shared :func:`~repowise.core.code_origin.path_origin`, so a+ build script, a tool, a test or a copied library means the same here as in+ every other layer. Two rules are this layer's own: a file with no+ directory, and an example, demo or docs tree at any depth, carry no+ evidence either way and are ``unknown``. A CLI is product code an edit can+ improve, so code-shape surfaces read this; only performance treats a CLI+ loop as off the request path."""normalized = file_path.replace("\\", "/")if not normalized:return "unknown"- if is_test_related_path(file_path):+ origin = path_origin(normalized)+ if origin == "test":return "test"- segments = normalized.lower().split("/")- parts = set(segments)- if parts & _TOOLING_PARTS:- return "tooling"- if any(pair in _TOOLING_DIR_PAIRS for pair in pairwise(segments[:-1])):+ if origin in _TOOLING_ORIGINS:return "tooling"- if parts & _UNCLASSIFIABLE_PARTS or "/" not in normalized:+ dirs = normalized.lower().split("/")[:-1]+ if origin in _UNKNOWN_ORIGINS or not dirs or any(d in _UNKNOWN_DIRS for d in dirs):return "unknown"return "production"diff --git a/packages/core/src/repowise/core/analysis/health/perf/gated.py b/packages/core/src/repowise/core/analysis/health/perf/gated.pyindex c7b5aec81..c6e1fe801 100644--- a/packages/core/src/repowise/core/analysis/health/perf/gated.py+++ b/packages/core/src/repowise/core/analysis/health/perf/gated.py@@ -27,6 +27,8 @@ from __future__ import annotationsfrom collections.abc import Iterablefrom typing import TYPE_CHECKING, Any+from repowise.core.code_origin import is_build_file+from .callgraph import CallGraphIndexfrom .sink_reach import collect_sink_reaching_hits@@ -66,6 +68,8 @@ def collect_centrality_gated(sits inside Rust inline test code (``_in_rust_test_range``) is skippedbefore the hotness check even runs — test code doing blocking I/O isnormal, not a finding, regardless of how central or churny its file is.+ A build file is never a hot path either: the build tool runs it, no+ request does."""from ..complexity import PerfHit@@ -74,6 +78,8 @@ def collect_centrality_gated(if not fcx.perf_fn_facts:continuepath = pf.file_info.path+ if is_build_file(path):+ continuefile_hits: list[PerfHit] = []test_ranges = fcx.rust_test_line_rangesfor fact in fcx.perf_fn_facts:diff --git a/packages/core/src/repowise/core/analysis/health/refactoring/extract_helper.py b/packages/core/src/repowise/core/analysis/health/refactoring/extract_helper.pyindex 2405a18af..9dc885f18 100644--- a/packages/core/src/repowise/core/analysis/health/refactoring/extract_helper.py+++ b/packages/core/src/repowise/core/analysis/health/refactoring/extract_helper.py@@ -45,6 +45,7 @@ from __future__ import annotationsimport refrom typing import Any+from ....code_origin import is_migration_path, is_vendored_or_generated_pathfrom ....test_paths import is_test_related_pathfrom ..duplication.detector import clone_ranges, union_line_countfrom .models import RefactoringContext, RefactoringSuggestion@@ -262,16 +263,7 @@ def _is_generated_path(path: str) -> bool:helper is the wrong advice — a migration must stay self-contained — sothese occurrences are dropped like test ones (plan's "no generated-filenoise" gate)."""- p = path.lower().replace("\\", "/")- return (- "/migrations/versions/" in p- or "/alembic/versions/" in p- or "/migrations/" in p- or "/node_modules/" in p- or "/vendor/" in p- or "/__generated__/" in p- or p.endswith(".min.js")- )+ return is_vendored_or_generated_path(path) or is_migration_path(path)def _is_skippable_occurrence(path: str, language: str | None = None) -> bool:diff --git a/packages/core/src/repowise/core/analysis/health/refactoring/opportunity_rank.py b/packages/core/src/repowise/core/analysis/health/refactoring/opportunity_rank.pyindex bd762e008..627c77c95 100644--- a/packages/core/src/repowise/core/analysis/health/refactoring/opportunity_rank.py+++ b/packages/core/src/repowise/core/analysis/health/refactoring/opportunity_rank.py@@ -33,7 +33,7 @@ from __future__ import annotationsfrom collections.abc import Sequencefrom typing import Any-from repowise.core.test_paths import is_test_related_path+from repowise.core.code_origin import ship_rankfrom .models import CONFIDENCE_LEVELS, RefactoringSuggestionfrom .recommendations import EFFORT_COST, detector_native_benefit, priority_score@@ -135,12 +135,14 @@ def why_ranked(factors: dict[str, float], *, limit: int = 3) -> list[dict[str, Areturn [{"factor": name, "value": value} for name, value in ordered[:limit]]-def rank_sort_key(opportunity: Any) -> tuple[bool, bool, float, str, str]:+def rank_sort_key(opportunity: Any) -> tuple[int, bool, float, str, str]:"""A total order, production files first. The id tail is what stops tiesfloating between runs.A test file never leads: it has no users, and its helpers score badly bydesign. Tests still rank among themselves, after every production file.+ Build scripts, tools and copied code rank between the two+ (:func:`~repowise.core.code_origin.ship_rank`).Within each, work that recovers health comes first. A detector-nativebenefit (a cycle's size, a split's group count) is not health, and on this@@ -149,7 +151,7 @@ def rank_sort_key(opportunity: Any) -> tuple[bool, bool, float, str, str]:in their own order."""return (- is_test_related_path(opportunity.file_path),+ ship_rank(opportunity.file_path),not has_credit(opportunity),-opportunity.rank_score,opportunity.file_path,diff --git a/packages/core/src/repowise/core/analysis/health/refactoring/recommendations.py b/packages/core/src/repowise/core/analysis/health/refactoring/recommendations.pyindex e65fcf5c5..ab93be8b3 100644--- a/packages/core/src/repowise/core/analysis/health/refactoring/recommendations.py+++ b/packages/core/src/repowise/core/analysis/health/refactoring/recommendations.py@@ -33,7 +33,8 @@ from repowise.core.analysis.test_reachability import (tests_reaching_by_tier,)from repowise.core.analysis.test_selection import expand_test_scopes-from repowise.core.test_paths import is_test_related_path, is_test_support_path, paired_test_names+from repowise.core.code_origin import ship_rank+from repowise.core.test_paths import is_test_support_path, paired_test_namesfrom .models import RefactoringSuggestion@@ -862,11 +863,12 @@ def build_recommendations(def canonical_order(recommendations: Sequence[Recommendation]) -> list[Recommendation]:- """Rank order, production files first so a test plan never leads the list."""+ """Rank order, production files first: a plan on a build script, a tool or+ copied code comes after them, and a test plan last."""return sorted(recommendations,key=lambda recommendation: (- is_test_related_path(recommendation.suggestion.file_path),+ ship_rank(recommendation.suggestion.file_path),-recommendation.rank_score,recommendation.suggestion.refactoring_type,recommendation.suggestion.file_path,diff --git a/packages/core/src/repowise/core/analysis/health/refactoring/split_file.py b/packages/core/src/repowise/core/analysis/health/refactoring/split_file.pyindex 3d7aab1c7..b551bae2a 100644--- a/packages/core/src/repowise/core/analysis/health/refactoring/split_file.py+++ b/packages/core/src/repowise/core/analysis/health/refactoring/split_file.py@@ -56,6 +56,7 @@ from typing import Anyfrom repowise.core.analysis.execution_graph import is_reliable_call_edge+from ....code_origin import is_migration_path, is_vendored_or_generated_pathfrom ....test_paths import is_test_related_pathfrom ...dead_code.file_reachability import BARREL_FILENAMESfrom .models import RefactoringContext, RefactoringSuggestion@@ -115,18 +116,11 @@ _HIGH_CONFIDENCE_MODULARITY = 0.45def _is_generated_path(path: str) -> bool:"""Generated / vendored / append-only code: a migration or a barrelre-export file must stay self-contained, so it is never a split target."""- p = path.lower().replace("\\", "/")- base = p.rsplit("/", 1)[-1]return (- "/migrations/" in p- or "/alembic/versions/" in p- or "/node_modules/" in p- or "/vendor/" in p- or "/__generated__/" in p- or ".generated." in base- or base.endswith(".min.js")+ is_vendored_or_generated_path(path)+ or is_migration_path(path)# Barrel / package-init re-export files: nothing of substance to split.- or base in BARREL_FILENAMES+ or path.replace("\\", "/").rsplit("/", 1)[-1].lower() in BARREL_FILENAMES)diff --git a/packages/core/src/repowise/core/code_origin.py b/packages/core/src/repowise/core/code_origin.pyindex 8946f357d..0756705dd 100644--- a/packages/core/src/repowise/core/code_origin.py+++ b/packages/core/src/repowise/core/code_origin.py@@ -7,8 +7,11 @@ under ``docs_src/`` or a vendored ``typeahead.jquery.js`` can carry a perfectlyreal finding that nobody should be asked to fix first.The answer is one of :data:`CODE_ORIGINS`, decided in precedence order, so a-file has exactly one: ``generated`` beats ``vendored`` beats ``test`` beats-``docs_example`` beats ``tooling``, and everything else is ``production``.+file has exactly one: ``generated`` beats ``vendored`` beats ``build`` beats+``test`` beats ``docs_example`` beats ``tooling``, and everything else is+``production``. ``build`` is decided by the file's type (a Gradle script, a+``CMakeLists.txt``, a bundler config), wherever it sits; :func:`is_build_file`+answers it for a caller that needs only that.The generated-file banner rule is the one ingestion already applies before itindexes a file (:func:`is_generated_header`, moved here from the traverser so@@ -23,6 +26,7 @@ from __future__ import annotationsimport refrom functools import cache, lru_cache+from itertools import pairwisefrom pathlib import PurePosixPathfrom typing import Literal@@ -33,11 +37,17 @@ __all__ = ["CODE_ORIGINS","CodeOrigin","code_origin",+ "is_build_file","is_generated_header",+ "is_migration_path","is_vendored_or_generated_path",+ "path_origin",+ "ship_rank",]-CodeOrigin = Literal["production", "test", "vendored", "docs_example", "generated", "tooling"]+CodeOrigin = Literal[+ "production", "test", "vendored", "docs_example", "generated", "tooling", "build"+]CODE_ORIGINS: tuple[CodeOrigin, ...] = ("production",@@ -46,6 +56,7 @@ CODE_ORIGINS: tuple[CodeOrigin, ...] = ("docs_example","generated","tooling",+ "build",)# --------------------------------------------------------------------------@@ -301,6 +312,135 @@ def _third_party_header(header: str, project: str | None) -> bool:return not (project and _squash(project) in _squash(comments))+# --------------------------------------------------------------------------+# Build+# --------------------------------------------------------------------------++# Build files, by type: what a build tool reads to configure, compile, package+# or run the project. A build tool loads each by its name, nothing imports one,+# and none ships, in whatever directory it sits. Exact names, spelled as the+# tool spells them (Bazel's ``BUILD`` is not a ``build`` script), by ecosystem.+_BUILD_FILE_NAMES = frozenset(+ {+ # Gradle, Maven, sbt, Mill and their wrappers+ "build.gradle",+ "build.gradle.kts",+ "settings.gradle",+ "settings.gradle.kts",+ "gradlew",+ "gradlew.bat",+ "pom.xml",+ "mvnw",+ "mvnw.cmd",+ "build.sbt",+ "build.sc",+ "build.mill",+ # CMake, Make, Autotools, Meson, SCons, Premake, xmake, Zig, Just+ "CMakeLists.txt",+ "Makefile",+ "makefile",+ "GNUmakefile",+ "Makefile.am",+ "Makefile.in",+ "configure.ac",+ "configure.in",+ "meson.build",+ "meson_options.txt",+ "meson.options",+ "SConstruct",+ "SConscript",+ "premake4.lua",+ "premake5.lua",+ "xmake.lua",+ "build.zig",+ "Justfile",+ "justfile",+ # Bazel, Buck+ "BUILD",+ "BUILD.bazel",+ "WORKSPACE",+ "WORKSPACE.bazel",+ "MODULE.bazel",+ "BUCK",+ # Cargo, SwiftPM, Mage, Mix, Leiningen, tools.build, Perl, Conan, nox+ "Cargo.toml",+ "Package.swift",+ "magefile.go",+ "mix.exs",+ "project.clj",+ "build.clj",+ "Makefile.PL",+ "Build.PL",+ "conanfile.py",+ "noxfile.py",+ # Ruby and JS task runners+ "Rakefile",+ "Gruntfile.js",+ "Gruntfile.coffee",+ }+)+# Suffixes that only a build file carries: Gradle scripts and precompiled+# script plugins, CMake modules, Make includes, Starlark, MSBuild imports+# (``Directory.Build.props``), package specs.+_BUILD_SUFFIXES = (+ ".gradle",+ ".gradle.kts",+ ".cmake",+ ".mk",+ ".bzl",+ ".props",+ ".targets",+ ".gemspec",+ ".podspec",+ # Cake (C# make): ``build.cake`` and its loaded ``*.cake`` scripts+ ".cake",+ ".rockspec",+)+# Bundler configs and gulp files, any extension a JS tool's config takes.+_BUILD_NAME_RE = re.compile(+ r"^(?:gulpfile|(?:webpack|vite|rollup|rolldown|rspack|esbuild|tsup)\.config(?:\.[\w-]+)*)"+ r"\.[cm]?[jt]s$"+)+# Names a build tool reads only at the root: a nested ``setup.py`` is as often+# a module (``homeassistant/setup.py`` sets up integrations).+_BUILD_ROOT_NAMES = frozenset({"setup.py"})+# Cargo runs ``build.rs`` from a crate root; directly in ``src/`` it is a+# module (``mod build;``). A crate root can sit under ``src/`` too+# (``src/bootstrap/build.rs`` in rust-lang/rust), so as a dead-code root every+# ``build.rs`` not directly in ``src/`` counts: a module there is reached by+# its ``mod`` edge anyway. As an origin, which hides code from fix lists, only+# one with no ``src/`` above it counts (``cli/src/commands/build.rs`` is a+# module).+_CRATE_ROOT_NAMES = frozenset({"build.rs"})+_SOURCE_DIR = "src"+++def _is_build_name(name: str, dirs: list[str], *, as_origin: bool = False) -> bool:+ lowered = name.lower()+ return (+ name in _BUILD_FILE_NAMES+ or lowered.endswith(_BUILD_SUFFIXES)+ or bool(_BUILD_NAME_RE.match(lowered))+ or (not dirs and name in _BUILD_ROOT_NAMES)+ or (name in _CRATE_ROOT_NAMES and _at_crate_root(dirs, as_origin=as_origin))+ )+++def _at_crate_root(dirs: list[str], *, as_origin: bool) -> bool:+ return _SOURCE_DIR not in dirs if as_origin else dirs[-1:] != [_SOURCE_DIR]+++@lru_cache(maxsize=65536)+def is_build_file(path: str) -> bool:+ """Whether *path* is a build file: a build tool runs it, nothing imports it.++ Decided by the file's type alone, so it holds under ``vendor/`` or a test+ tree too. Dead code reads this as a root: such a file is never unreachable.+ """+ split = _split(path)+ return split is not None and _is_build_name(split[1], split[2])++# --------------------------------------------------------------------------# Docs, examples, tooling# --------------------------------------------------------------------------@@ -326,10 +466,10 @@ def _is_docs_example(dirs: list[str]) -> bool:return any(d in _DOCS_ROOT_TOKENS for d in dirs) or bool(dirs and _is_example_dir(dirs[0]))-# Close to ``perf/causal.py``'s tooling parts, with two differences: the-# benchmark spellings ``bench`` / ``benches`` join ``benchmarks``, and there is-# no ``/cli/`` rule, since a CLI's source ships and its findings are real work.-# Migrations join too: they run once at deploy time and are append-only.+# No ``/cli/`` rule: a CLI's source ships and its findings are real work (only+# performance treats a CLI loop as off the request path, in+# ``perf/causal.execution_context``). Migrations join: they run once at deploy+# time and are append-only._TOOLING_DIR_TOKENS = frozenset({".github",@@ -350,12 +490,18 @@ _TOOLING_DIR_TOKENS = frozenset(_TOOLING_ROOT_DIRS = frozenset({"buildsrc", "build-logic", "build-conventions", "build-tools", "build-tools-internal"})-_TOOLING_ROOT_NAMES = frozenset(- {"setup.py", "noxfile.py", "fabfile.py", "Rakefile", "Gruntfile.js"}-)+# Schema migrations: a ``migrations/`` directory (above), or adjacent+# directories where neither name does alone. Rails keeps them in+# ``db/migrate``, Alembic in ``alembic/versions``; a bare ``versions/`` is too+# common (API versions) to class on its own. Ceiling: an Alembic script+# directory with another name is recognised only by its sibling ``env.py``,+# which a path-only classifier cannot see.+_MIGRATION_DIR = "migrations"+_MIGRATION_DIR_PAIRS = frozenset({("db", "migrate"), ("alembic", "versions")})+_TOOLING_ROOT_NAMES = frozenset({"fabfile.py"})+# Lint, test and transpiler configs. Bundler configs are build files (above)._TOOLING_NAME_RE = re.compile(- r"^(?:gulpfile|webpack\.config|vite\.config|rollup\.config|eslint\.config|"- r"jest\.config|vitest\.config|babel\.config|karma\.conf)\.[cm]?[jt]s$"+ r"^(?:eslint\.config|jest\.config|vitest\.config|babel\.config|karma\.conf)\.[cm]?[jt]s$")@@ -402,11 +548,22 @@ def is_vendored_or_generated_path(path: str) -> bool:return _is_generated_path(name, dirs) or _is_vendored_path(name.lower(), dirs)-def _is_tooling(normalized: str, name: str, dirs: list[str]) -> bool:+def _is_migration_dir(dirs: list[str]) -> bool:+ return _MIGRATION_DIR in dirs or any(pair in _MIGRATION_DIR_PAIRS for pair in pairwise(dirs))+++def is_migration_path(path: str) -> bool:+ """Whether *path* is a schema migration: generated once, append-only, and+ meant to stay self-contained, so no shared helper or split belongs in it."""+ split = _split(path)+ return split is not None and _is_migration_dir(split[2])+++def _is_tooling(name: str, dirs: list[str]) -> bool:return (any(d in _TOOLING_DIR_TOKENS for d in dirs)or bool(dirs and dirs[0] in _TOOLING_ROOT_DIRS)- or "/alembic/versions/" in f"/{normalized.lower()}"+ or _is_migration_dir(dirs)or (not dirs and name in _TOOLING_ROOT_NAMES)or bool(_TOOLING_NAME_RE.match(name.lower())))@@ -448,14 +605,40 @@ def code_origin(and _third_party_header(header, project)):return "vendored"+ return _maintained_origin(normalized, name, dirs, is_test)++def _maintained_origin(+ normalized: str, name: str, dirs: list[str], is_test: bool | None+) -> CodeOrigin:+ """The origin of code this repository maintains: build, test, docs or+ examples, tooling, or production, in that precedence."""+ if _is_build_name(name, dirs, as_origin=True):+ return "build"if is_test if is_test is not None else is_test_related_path(normalized):return "test"-if _is_docs_example(dirs):return "docs_example"-- if _is_tooling(normalized, name, dirs):+ if _is_tooling(name, dirs):return "tooling"-return "production"+++@lru_cache(maxsize=65536)+def path_origin(path: str) -> CodeOrigin:+ """:func:`code_origin` from the path alone, memoised.++ For callers holding no file content and no stored origin. A caller holding+ the stored ``code_origin`` reads that instead: it also saw the file's head.+ """+ return code_origin(path)+++def ship_rank(path: str) -> int:+ """Sort key for ranked lists: product code 0, other non-test code 1, tests 2.++ A build script, a tool or a copied library can carry a real finding, but it+ never leads a list of things to fix ahead of the code that ships.+ """+ origin = path_origin(path)+ return 0 if origin == "production" else 2 if origin == "test" else 1diff --git a/packages/core/src/repowise/core/persistence/models.py b/packages/core/src/repowise/core/persistence/models.pyindex 986e1911e..a5b5638d8 100644--- a/packages/core/src/repowise/core/persistence/models.py+++ b/packages/core/src/repowise/core/persistence/models.py@@ -2156,7 +2156,8 @@ class HealthFileMetric(Base):# fills those in without re-scoring anything.is_test: Mapped[bool | None] = mapped_column(Boolean, nullable=True)# Where the file's code comes from (``production`` / ``test`` /- # ``vendored`` / ``docs_example`` / ``generated`` / ``tooling``), decided+ # ``vendored`` / ``docs_example`` / ``generated`` / ``tooling`` /+ # ``build``), decided# by ``repowise.core.code_origin`` with the file's head in hand, so a# reader ranking what to fix never re-reads or re-parses the file. NULL on# rows written before the column existed.diff --git a/tests/unit/analysis/test_go_reachability.py b/tests/unit/analysis/test_go_reachability.pyindex 1a355ba3b..1664f7b74 100644--- a/tests/unit/analysis/test_go_reachability.py+++ b/tests/unit/analysis/test_go_reachability.py@@ -184,7 +184,11 @@ class TestGoNeverFlagPatterns:assert self._matches("common/doc.go")def test_magefile(self):- assert self._matches("magefile.go")+ # A build file by type (``code_origin``), not a glob.+ from repowise.core.analysis.dead_code.constants import never_flag_path++ assert never_flag_path("magefile.go")+ assert never_flag_path("build/magefile.go")def test_generated_code(self):assert self._matches("api/v1/types.pb.go")diff --git a/tests/unit/analysis/test_rust_dead_code_regression.py b/tests/unit/analysis/test_rust_dead_code_regression.pyindex 2ff588216..4cb80bd28 100644--- a/tests/unit/analysis/test_rust_dead_code_regression.py+++ b/tests/unit/analysis/test_rust_dead_code_regression.py@@ -14,11 +14,10 @@ class TestRustNeverFlagPatterns:"""Validate never-flag patterns cover Rust conventions."""def test_build_rs_never_flagged(self):- import fnmatch+ # A build file by type (``code_origin``), not a glob.+ from repowise.core.analysis.dead_code.constants import never_flag_path- from repowise.core.analysis.dead_code.constants import _NEVER_FLAG_PATTERNS- path = "crates/typst-pdf/build.rs"- assert any(fnmatch.fnmatch(path, p) for p in _NEVER_FLAG_PATTERNS)+ assert never_flag_path("crates/typst-pdf/build.rs")def test_examples_never_flagged(self):import fnmatchdiff --git a/tests/unit/dead_code/test_convention_never_flag.py b/tests/unit/dead_code/test_convention_never_flag.pyindex a97be8488..603dea241 100644--- a/tests/unit/dead_code/test_convention_never_flag.py+++ b/tests/unit/dead_code/test_convention_never_flag.py@@ -9,7 +9,11 @@ from __future__ import annotationsimport networkx as nximport pytest-from repowise.core.analysis.dead_code.constants import never_flag_match, never_flag_path+from repowise.core.analysis.dead_code.constants import (+ is_runner_file,+ never_flag_match,+ never_flag_path,+)from repowise.core.analysis.dead_code.file_reachability import is_file_reachable@@ -103,3 +107,42 @@ def test_vendored_and_generated_files_are_never_flagged(path):)def test_origin_near_misses_stay_flaggable(path):assert not never_flag_path(path)+++ "path",+ [+ # A build tool runs a build file by its name; nothing imports one.+ "ktor-server/ktor-server-core/build.gradle.kts",+ "gradle/plugins/ktorbuild.kmp.gradle.kts",+ "settings.gradle.kts",+ "crates/core/build.rs",+ "src/bootstrap/build.rs",+ "src/tools/x/build.rs",+ "magefile.go",+ "noxfile.py",+ "cmake/Toolchain.cmake",+ ],+)+def test_build_files_are_never_flagged(path):+ assert never_flag_path(path)+ assert not _unreachable(path)+++ "path",+ [+ "src/build.rs", # a ``mod build;`` module+ "src/main/kotlin/io/ktor/Settings.kt",+ "lib/webpack.js",+ ],+)+def test_build_near_misses_stay_flaggable(path):+ assert not never_flag_path(path)+++def test_a_build_file_runs_what_it_names():+ assert is_runner_file("CMakeLists.txt")+ assert is_runner_file("server/build.gradle")+ assert is_runner_file("eng/Versions.props")+ assert not is_runner_file("src/main.c")diff --git a/tests/unit/health/test_fix_first_precision.py b/tests/unit/health/test_fix_first_precision.pyindex 0a7adecf1..2a12d772e 100644--- a/tests/unit/health/test_fix_first_precision.py+++ b/tests/unit/health/test_fix_first_precision.py@@ -65,6 +65,17 @@ def test_a_vendored_directory_counts_as_vendored() -> None:assert queue.totals.excluded["vendored"] == 1+def test_a_build_file_counts_as_tooling_by_stored_origin_or_by_path() -> None:+ stored = _queue([_finding("src/a.py")], [_metric("src/a.py", code_origin="build")])+ assert stored.items == () and stored.totals.excluded["tooling"] == 1+ # An index stored before build files were classed says production; the+ # path still decides.+ path = "ktor-server/build.gradle.kts"+ old = _queue([_finding(path)], [_metric(path, code_origin="production")])+ assert old.items == () and old.totals.excluded["tooling"] == 1+ assert len(_queue([_finding("src/build_info.py")]).items) == 1++def test_a_deprecated_function_is_no_item() -> None:queue = _queue([_finding(deprecated=True)])assert queue.items == () and queue.totals.excluded["deprecated"] == 1diff --git a/tests/unit/health/test_perf_execution_context.py b/tests/unit/health/test_perf_execution_context.pyindex ac4f4861d..cc2498f93 100644--- a/tests/unit/health/test_perf_execution_context.py+++ b/tests/unit/health/test_perf_execution_context.py@@ -42,3 +42,33 @@ def test_migrations_are_tooling(path: str) -> None:)def test_lookalikes_stay_production(path: str) -> None:assert execution_context(path) == "production"+++ "path",+ [+ "build.gradle.kts", # a root build file is tooling, no longer unknown+ "ktor-client/ktor-client-core/build.gradle.kts",+ "crates/core/build.rs",+ "packages/app/vite.config.ts",+ "src/lib/CMakeLists.txt",+ ],+)+def test_build_files_are_tooling(path: str) -> None:+ assert execution_context(path) == "tooling"+++ ("path", "expected"),+ [+ ("src/build.rs", "production"),+ ("src/x/examples/a.py", "unknown"), # a nested example may or may not ship+ ("pkg/doc/gen.go", "unknown"),+ ("vendor/github.com/x/y.go", "unknown"),+ ("src/__generated__/schema.ts", "unknown"),+ ("benches/parse.rs", "tooling"),+ ("main.py", "unknown"), # no directory, no evidence+ ],+)+def test_contexts_follow_the_shared_origin(path: str, expected: str) -> None:+ assert execution_context(path) == expecteddiff --git a/tests/unit/health/test_perf_rust_test_filter.py b/tests/unit/health/test_perf_rust_test_filter.pyindex 10e8554db..dd0d53055 100644--- a/tests/unit/health/test_perf_rust_test_filter.py+++ b/tests/unit/health/test_perf_rust_test_filter.py@@ -197,3 +197,9 @@ def test_non_rust_languages_get_empty_ranges_and_are_unaffected(language):}fc = walk_file(f"t.{language}", language, src_by_lang[language].encode())assert fc.rust_test_line_ranges == ()+++def test_a_build_script_is_never_a_hot_path():+ """``build.rs`` runs once per compile, never under a request."""+ walked = _walked("crates/core/build.rs", "rust", _PRODUCTION_FN)+ assert collect_centrality_gated(walked, _always_hot()) == {}diff --git a/tests/unit/test_code_origin.py b/tests/unit/test_code_origin.pyindex 34ed07cd5..a968cb02c 100644--- a/tests/unit/test_code_origin.py+++ b/tests/unit/test_code_origin.py@@ -1,4 +1,4 @@-"""One origin per file: production, test, vendored, docs_example, generated, tooling."""+"""One origin per file: production, test, vendored, docs_example, generated, tooling, build."""from __future__ import annotations@@ -7,8 +7,11 @@ import pytestfrom repowise.core.code_origin import (CODE_ORIGINS,code_origin,+ is_build_file,is_generated_header,+ is_migration_path,is_vendored_or_generated_path,+ ship_rank,)_JQUERY = (@@ -71,8 +74,11 @@ _OWN_HEADER = (("benchmarks/bench_app.py", "tooling"),("app/migrations/0001_initial.py", "tooling"),("db/alembic/versions/abc_add.py", "tooling"),- ("setup.py", "tooling"),- ("vite.config.ts", "tooling"),+ ("setup.py", "build"),+ ("vite.config.ts", "build"),+ ("fabfile.py", "tooling"),+ ("eslint.config.mjs", "tooling"),+ ("db/migrate/20240101_add_users.rb", "tooling"),("src/__generated__/schema.ts", "generated"),("api/user_pb2.py", "generated"),("api/user_grpc.pb.go", "generated"),@@ -98,7 +104,7 @@ _OWN_HEADER = (("src/external/foo.cpp", "production"),("libs/external/x/a.h", "production"),("a/b/External/Foo.cpp", "production"),- ("src/native/external/zlib.cmake", "production"), # no library directory+ ("src/native/external/zlib.cmake", "build"), # no library directory: a CMake module# a bare generated/ only as a build output("app/generated/handlers.py", "production"),("tests/generated/test_x.py", "test"),@@ -106,7 +112,8 @@ _OWN_HEADER = (("build/generated/source/X.java", "generated"),("build-tools-internal/src/main/java/org/x/Plugin.java", "tooling"),("build-tools/src/main/java/org/x/Task.java", "tooling"),- ("buildSrc/src/main/kotlin/conventions.gradle.kts", "tooling"),+ ("buildSrc/src/main/kotlin/conventions.gradle.kts", "build"),+ ("buildSrc/src/main/kotlin/Versions.kt", "tooling"),("build-logic/src/main/kotlin/Plugin.kt", "tooling"),("packages/build-tools/src/index.ts", "production"), # a shipped package],@@ -115,7 +122,7 @@ def test_path_rules(path: str, expected: str) -> None:assert code_origin(path) == expected-def test_every_answer_is_one_of_the_six() -> None:+def test_every_answer_is_one_of_the_seven() -> None:assert set(CODE_ORIGINS) == {"production","test",@@ -123,11 +130,16 @@ def test_every_answer_is_one_of_the_six() -> None:"docs_example","generated","tooling",+ "build",}-def test_precedence_is_generated_vendored_test_docs_tooling() -> None:+def test_precedence_is_generated_vendored_build_test_docs_tooling() -> None:assert code_origin("vendor/foo_test.go") == "vendored"+ assert code_origin("third_party/zlib/CMakeLists.txt") == "vendored"+ assert code_origin("tests/fixtures/app/build.gradle") == "build"+ assert code_origin("examples/hello/CMakeLists.txt", is_test=True) == "build"+ assert code_origin("scripts/build.gradle.kts") == "build"assert code_origin("docs/tests/test_x.py") == "test"assert code_origin("examples/scripts/run.py") == "docs_example"assert code_origin("vendor/x.go", "// Code generated by protoc. DO NOT EDIT.\n") == "generated"@@ -338,3 +350,103 @@ def test_reference_stub_markers_are_anchored() -> None:"namespace L { // callers may throw null; see docs\n public class C { int M() => 1; } }\n")assert code_origin("src/Lib/ref/C.cs", mention) == "production"+++ "path",+ [+ "build.gradle.kts",+ "ktor-server/ktor-server-core/build.gradle.kts",+ "settings.gradle",+ "gradle/plugins/ktorbuild.kmp.gradle.kts",+ "caffeine/build.gradle",+ "pom.xml",+ "server/pom.xml",+ "CMakeLists.txt",+ "src/lib/CMakeLists.txt",+ "cmake/FindOpenSSL.cmake",+ "Makefile",+ "src/Makefile.am",+ "rules.mk",+ "meson.build",+ "BUILD",+ "pkg/BUILD.bazel",+ "tools/defs.bzl",+ "Directory.Build.props",+ "src/Directory.Build.targets",+ "eng/Versions.props",+ "build.rs",+ "crates/core/build.rs",+ "Cargo.toml",+ "setup.py",+ "noxfile.py",+ "magefile.go",+ "Package.swift",+ "webpack.config.js",+ "packages/app/vite.config.mts",+ "rollup.config.prod.mjs",+ "gulpfile.js",+ "Rakefile",+ "foo.gemspec",+ "build.cake",+ "build/tasks.cake",+ ],+)+def test_build_files_by_type(path: str) -> None:+ assert is_build_file(path)+ assert code_origin(path) == "build"+++ ("path", "expected"),+ [+ # Near misses: code named like a build step, which ships.+ ("src/build.rs", "production"), # a ``mod build;``, not a Cargo build script+ ("homeassistant/setup.py", "production"), # a nested setup.py is a module+ ("src/build/compiler.ts", "tooling"), # the build/ directory rule, not the type+ ("src/builder.py", "production"),+ ("src/gradle/GradlePlugin.java", "production"),+ ("lib/webpack.js", "production"),+ ("src/makefile_parser.py", "production"),+ ("src/cmake.py", "production"),+ ("app/props.ts", "production"),+ ("src/Button.props.ts", "production"),+ ("cake.cs", "production"), # an app named cake, not a Cake script+ ("src/Cake/CakeHost.cs", "production"),+ ("src/BuildInfo.java", "production"),+ ("src/main/kotlin/Settings.kt", "production"),+ ("lib/rake_task.rb", "production"),+ ("src/vite.ts", "production"),+ ("cmd/build/main.go", "tooling"),+ ("src/BUILD.md", "production"),+ ],+)+def test_build_near_misses_are_not_build_files(path: str, expected: str) -> None:+ assert not is_build_file(path)+ assert code_origin(path) == expected+++def test_migration_paths() -> None:+ assert is_migration_path("app/migrations/0001_initial.py")+ assert is_migration_path("db/migrate/20240101_add.rb")+ assert is_migration_path("alembic/versions/abc.py")+ assert not is_migration_path("api/versions/v1.py")+ assert not is_migration_path("src/migrate.py")+++def test_ship_rank_puts_product_code_first_and_tests_last() -> None:+ assert ship_rank("src/app.py") == 0+ assert ship_rank("build.gradle.kts") == 1+ assert ship_rank("scripts/release.py") == 1+ assert ship_rank("vendor/x/y.go") == 1+ assert ship_rank("tests/test_app.py") == 2+++def test_build_rs_under_src_is_a_dead_code_root_but_keeps_its_origin() -> None:+ # A crate root under src/ (rust-lang/rust) is never flagged as dead...+ assert is_build_file("src/bootstrap/build.rs")+ assert is_build_file("src/tools/x/build.rs")+ # ...but only a build.rs with no src/ above it leaves the fix lists.+ 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")