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(generation): give test support files their own pages and drop the test penalty for them (#2018)
KS Nithin014d08f30717
diff --git a/packages/core/src/repowise/core/generation/selection/scoring.py b/packages/core/src/repowise/core/generation/selection/scoring.pyindex 91ca58910..6eecc9991 100644--- a/packages/core/src/repowise/core/generation/selection/scoring.py+++ b/packages/core/src/repowise/core/generation/selection/scoring.py@@ -15,6 +15,8 @@ from __future__ import annotationsfrom pathlib import Pathfrom typing import Any+from repowise.core.test_paths import is_test_support_path+# -- File score --------------------------------------------------------# Bonuses applied additively on top of normalized PageRank+betweenness.@@ -36,6 +38,16 @@ _PENALTY_TRIVIAL_SYMBOL_CAP = 4_PENALTY_TRIVIAL = 0.40+def is_test_spec(fi: Any) -> bool:+ """A test proper: ``FileInfo.is_test`` less the support files around tests.++ ``is_test`` covers both, but ``conftest.py``, ``tests/helpers/`` and+ ``e2e/fixtures.ts`` carry the harness conventions a reader asks about, so+ page selection treats them as code (#1497).+ """+ return fi.is_test and not is_test_support_path(fi.path, fi.language)++def _normalize(value: float, max_value: float) -> float:"""Return ``value / max_value`` clamped to ``[0, 1]``; safe on 0."""if max_value <= 0:@@ -85,7 +97,7 @@ def score_file(base += kg_bonus# Penalties.- if fi.is_test:+ if is_test_spec(fi):base *= _PENALTY_TESTif (n_symbols <= _PENALTY_TRIVIAL_SYMBOL_CAPdiff --git a/packages/core/src/repowise/core/generation/selection/selector.py b/packages/core/src/repowise/core/generation/selection/selector.pyindex b79d4eecd..163db7669 100644--- a/packages/core/src/repowise/core/generation/selection/selector.py+++ b/packages/core/src/repowise/core/generation/selection/selector.py@@ -30,6 +30,7 @@ from ..concept_tree.naming import ()from ..models import member_structural_key, scc_page_slugfrom .scoring import (+ is_test_spec,score_api_contract,score_file,score_infra,@@ -346,9 +347,11 @@ def _passes_importance_floor(parsed: Any) -> bool:Tests are read off ``FileInfo.is_test``, the flag ingestion stamps once, so``e2e-tests/`` and ``foo.spec.ts`` are caught exactly as everywhere else.+ Test support (``conftest.py``, ``tests/helpers/``) passes: it holds the+ harness conventions, not test cases."""fi = parsed.file_info- if fi.is_test:+ if is_test_spec(fi):return Falsereturn fi.path.replace("\\", "/").rsplit("/", 1)[-1] != "__init__.py"diff --git a/packages/core/src/repowise/core/test_paths.py b/packages/core/src/repowise/core/test_paths.pyindex 86016937f..9d84c1fcb 100644--- a/packages/core/src/repowise/core/test_paths.py+++ b/packages/core/src/repowise/core/test_paths.py@@ -164,6 +164,14 @@ _SUPPORT_DIR_TOKENS: frozenset[str] = frozenset({"fixtures", "factories", "support", "helpers", "mocks"})+# Filename stems that mark scaffolding/fixtures when sitting inside a test+# tree (e.g. ``e2e/fixtures.ts``, ``tests/setup_tests.py``). They do not mark+# files outside a test tree because bare "fixtures" or "fixture" is an ordinary+# word in production domains (e.g. ``src/fixtures.py``).+_SUPPORT_STEMS_IN_TEST_TREE: frozenset[str] = frozenset(+ {"fixture", "fixtures", "setup-tests", "setup_tests", "setuptests"}+)+# Scaffolding directories whose names mean test material *wherever* they sit,# because nothing else is ever called this. Bare ``fixtures`` deliberately stays# out of this set and above: it is an ordinary English word that names real@@ -570,12 +578,20 @@ def _classify(return ""# Inside test material. A test-shaped filename wins; otherwise a- # scaffolding directory demotes it to support.- if not named_test and any(seg in _SUPPORT_DIR_TOKENS for seg in segments):+ # scaffolding directory or support stem demotes it to support.+ if not named_test and _is_support_in_test_tree(segments, filename):return "support"return "test"+def _is_support_in_test_tree(segments: list[str], filename: str) -> bool:+ """Whether a file already inside a test tree is scaffolding (``e2e/fixtures.ts``)."""+ return (+ any(seg in _SUPPORT_DIR_TOKENS for seg in segments)+ or PurePosixPath(filename.lower()).stem in _SUPPORT_STEMS_IN_TEST_TREE+ )++def _phpunit_skips(path: str, filename: str, roots: PhpunitRoots | None) -> bool:"""Whether PHPUnit's config keeps a test-named PHP file out of collection."""return (diff --git a/tests/unit/generation/test_selection_contract.py b/tests/unit/generation/test_selection_contract.pyindex 74921ca07..f208c107b 100644--- a/tests/unit/generation/test_selection_contract.py+++ b/tests/unit/generation/test_selection_contract.py@@ -21,6 +21,7 @@ from repowise.core.generation.selection import (recommended_file_page_cap,select_pages,)+from repowise.core.generation.selection.scoring import score_filefrom repowise.core.test_paths import is_test_related_path# ---------------------------------------------------------------------------@@ -141,6 +142,7 @@ def test_importance_floor_excludes_tests_and_reexports():Test files and pure ``__init__.py`` re-exports were proven to diluteretrieval, so they get no page even though nothing is rationed any more.+ Test support such as ``conftest.py`` is not a test and passes (#1497)."""parsed, pagerank, betweenness, community = _build_synthetic_repo(6)extras = (@@ -149,7 +151,6 @@ def test_importance_floor_excludes_tests_and_reexports():"pkg0/__init__.py","e2e-tests/cli/run.ts","web/src/button.spec.ts",- "pkg0/conftest.py",)for extra in extras:# Stamped the way ingestion stamps it; symbols so the score floor passes.@@ -169,6 +170,65 @@ def test_importance_floor_excludes_tests_and_reexports():assert len(sel.file_page_paths) == 6+def test_test_support_files_pass_importance_floor():+ """Test infrastructure and fixture files pass the floor to receive file pages."""+ parsed, pagerank, betweenness, community = _build_synthetic_repo(6)+ extras = [+ ("tests/conftest.py", "python"),+ ("tests/fixtures/setup.py", "python"),+ ("apps/console/e2e/helpers/hydration.ts", "typescript"),+ ("apps/console/e2e/fixtures.ts", "typescript"),+ ]+ for path, lang in extras:+ parsed.append(+ FakeParsedFile(+ file_info=FakeFileInfo(path=path, language=lang, is_test=True),+ symbols=[FakeSymbol(name="fixture_helper")],+ )+ )+ pagerank[path] = 0.1+ betweenness[path] = 0.0+ community[path] = 0++ # Also add pure specs which must be excluded+ test_specs = [+ ("tests/unit/test_foo.py", "python"),+ ("apps/console/e2e/specs/login.spec.ts", "typescript"),+ ]+ for path, lang in test_specs:+ parsed.append(+ FakeParsedFile(+ file_info=FakeFileInfo(path=path, language=lang, is_test=True),+ symbols=[FakeSymbol(name="test_login")],+ )+ )+ pagerank[path] = 0.1+ betweenness[path] = 0.0+ community[path] = 0++ sel = select_pages(_inputs(parsed, pagerank, betweenness, community, GenerationConfig()))++ for path, _ in extras:+ assert path in sel.file_page_paths, f"Expected {path} to receive a file_page"++ for path, _ in test_specs:+ assert path not in sel.file_page_paths, f"Expected {path} to be excluded"+++def test_test_penalty_skips_test_support():+ """A support file scores as code; a test spec keeps the test penalty."""+ kw = dict(pagerank=0.5, betweenness=0.0, max_pagerank=1.0, max_betweenness=0.0)+ symbols = [FakeSymbol(name=f"s{i}") for i in range(5)]++ def score(path: str, is_test: bool) -> float:+ fi = FakeFileInfo(path=path, is_test=is_test)+ return score_file(FakeParsedFile(file_info=fi, symbols=symbols), is_hotspot=False, **kw)++ production = score("pkg/helpers.py", False)+ assert score("tests/conftest.py", True) == production+ assert score("tests/test_helpers.py", True) < production++def test_selection_does_not_depend_on_having_a_key():"""Keyed and keyless runs select exactly the same pages.diff --git a/tests/unit/test_test_paths.py b/tests/unit/test_test_paths.pyindex 05f3baf93..1cfbf0041 100644--- a/tests/unit/test_test_paths.py+++ b/tests/unit/test_test_paths.py@@ -85,7 +85,8 @@ _CORPUS: tuple[tuple[str, str | None, str], ...] = (("src/contests/rules.py", None, ""),("src/Latests/x.cs", None, ""),# gradle test fixtures and QA projects (elasticsearch)- ("build-tools/src/testFixtures/java/org/x/Fixture.java", None, "test"),+ ("build-tools/src/testFixtures/java/org/x/Fixture.java", None, "support"),+ ("build-tools/src/testFixtures/java/org/x/Builder.java", None, "test"),("x-pack/plugin/sql/qa/server/src/main/java/org/x/JdbcBase.java", None, "test"),("qa/logging-spi/src/main/java/org/x/Spi.java", None, "test"),("src/qa/answer.py", None, ""), # a question-answering module@@ -124,6 +125,9 @@ _CORPUS: tuple[tuple[str, str | None, str], ...] = (("contest/x.py", None, ""),# e2e suites("e2e/login.ts", None, "test"),+ ("apps/console/e2e/helpers/hydration.ts", "typescript", "support"),+ ("apps/console/e2e/fixtures.ts", "typescript", "support"),+ ("apps/console/e2e/specs/login.spec.ts", "typescript", "test"),# ...and the `.e2e.` infix beside `.test.`/`.spec.`, suites and their helpers("src/gateway/gateway.e2e.ts", None, "test"),("src/gateway/test-helpers.e2e.ts", None, "test"),@@ -162,6 +166,11 @@ _CORPUS: tuple[tuple[str, str | None, str], ...] = (# still needs a test tree around it("fixtures/data.yml", None, ""),("app/fixtures/premier_league.py", None, ""),+ ("src/fixtures.ts", None, ""),+ ("src/fixtures.ts", "typescript", ""),+ ("src/fixtures.py", None, ""),+ ("src/fixtures.py", "python", ""),+ ("lib/fixtures.go", None, ""),("src/testdata_loader.py", None, ""),("tests/testdata/golden.json", None, "support"),# compound directory names: a segment's words split on - _ . and its last