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(tests): ignore type-only conftest imports when narrowing selection (#3633)
Swati Ahuja19130c575db6
diff --git a/packages/core/src/repowise/core/analysis/conftest_routes.py b/packages/core/src/repowise/core/analysis/conftest_routes.pyindex cc6082008..4f7eec93d 100644--- a/packages/core/src/repowise/core/analysis/conftest_routes.py+++ b/packages/core/src/repowise/core/analysis/conftest_routes.py@@ -487,11 +487,12 @@ async def _edges_into_scopes(One query. The second part is a range on the indexed target column: animport of ``conftest`` the resolver could not place lands on an- ``external:`` node, and the importer it hides must not be dropped.+ ``external:`` node, and the importer it hides must not be dropped. A+ type-only import (``if TYPE_CHECKING:``) never runs, so it hides nothing."""if not targets:return []- params: dict[str, Any] = {"repo_id": repo_id}+ params: dict[str, Any] = {"repo_id": repo_id, "type_only": False}tgt = _in_clause("p", targets, params)rows = await session.execute(text(@@ -500,7 +501,8 @@ async def _edges_into_scopes(f"(target_node_id IN ({tgt}) ""AND edge_type IN ('framework', 'framework_binds', 'calls')) ""OR (target_node_id >= 'external:' AND target_node_id < 'external;' "- "AND target_node_id LIKE '%conftest' AND edge_type = 'imports'))"+ "AND target_node_id LIKE '%conftest' AND edge_type = 'imports' "+ "AND type_only = :type_only))"),params,)diff --git a/tests/unit/persistence/test_impacted_tests_resolution.py b/tests/unit/persistence/test_impacted_tests_resolution.pyindex b5d182796..c12423f92 100644--- a/tests/unit/persistence/test_impacted_tests_resolution.py+++ b/tests/unit/persistence/test_impacted_tests_resolution.py@@ -432,7 +432,7 @@ async def test_a_conftest_only_patching_the_route_runs_one_import_check(async_seassert _pairs(out, "src/app/util.py") == {"tests/test_a.py": "conftest-import-check"}-async def _add_edge(session, repo_id, source, target, edge_type, hint=None) -> None:+async def _add_edge(session, repo_id, source, target, edge_type, hint=None, **flags) -> None:from repowise.core.persistence.models import GraphEdgesession.add(@@ -442,6 +442,7 @@ async def _add_edge(session, repo_id, source, target, edge_type, hint=None) -> Ntarget_node_id=target,edge_type=edge_type,hint_source=hint,+ **flags,))await session.commit()@@ -491,6 +492,36 @@ async def test_an_unresolved_conftest_import_keeps_every_test(async_session) ->assert any("could not resolve" in n for n in out["conftest_notes"])+async def test_an_unresolved_type_only_conftest_import_keeps_the_narrowing(+ async_session,+) -> None:+ """An import under ``if TYPE_CHECKING:`` never runs, so it hides no importer."""+ repo = await insert_repo(async_session)+ await _conftest_graph(async_session, repo.id, stamped=True)+ await _add_edge(+ async_session, repo.id, "tests/test_c.py", "external:conftest", "imports", type_only=True+ )++ out = await _narrowed(async_session, repo.id)++ assert "tests/conftest.py" not in _pairs(out, "src/app/util.py")+ assert not any("could not resolve" in n for n in out["conftest_notes"])+++async def test_an_unresolved_deferred_conftest_import_keeps_every_test(async_session) -> None:+ """A function-body import does run, so it still blocks the narrowing."""+ repo = await insert_repo(async_session)+ await _conftest_graph(async_session, repo.id, stamped=True)+ await _add_edge(+ async_session, repo.id, "tests/test_c.py", "external:conftest", "imports", deferred=True+ )++ out = await _narrowed(async_session, repo.id)++ assert "tests/conftest.py" in _pairs(out, "src/app/util.py")+ assert any("could not resolve" in n for n in out["conftest_notes"])++async def test_a_resolved_conftest_import_keeps_its_importer(async_session) -> None:"""``from conftest import helper`` is an import: that test runs whatever it reaches."""from sqlalchemy import update