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(mcp): run the tests under a reached conftest instead of recommending the conftest (#2845)

Raghav Chamadiya8ff73a537b24
diff --git a/packages/core/src/repowise/core/analysis/health/refactoring/recommendations.py b/packages/core/src/repowise/core/analysis/health/refactoring/recommendations.py
index 41bc2c38c..65e7818cf 100644
--- a/packages/core/src/repowise/core/analysis/health/refactoring/recommendations.py
+++ b/packages/core/src/repowise/core/analysis/health/refactoring/recommendations.py
@@ -22,14 +22,17 @@ from repowise.core.analysis.health.grading import TARGET_SCORE
from repowise.core.analysis.pr_blast import rank_tests_by_reach
from repowise.core.analysis.test_reachability import (
DEFAULT_CALL_DEPTH,
+ MAX_TESTS_PER_TARGET,
ReachDistance,
ReachedBy,
imported_names_by_test,
load_test_files,
+ rank_tests,
reach_into_symbols,
tests_matching_by_name,
tests_reaching_by_tier,
)
+from repowise.core.analysis.test_selection import expand_test_scopes
from repowise.core.test_paths import is_test_support_path, paired_test_names
from .models import RefactoringSuggestion
@@ -439,8 +442,9 @@ def _rank_target_tests(
Most direct evidence first: measured coverage of the changed lines, then a
test naming the changed symbol (a direct call or an import of it), then
fewer call hops to it, then more of the test's functions at that distance,
- then a test named for the file, then directory overlap. Test support
- (``conftest.py``) runs nothing on its own, so it goes last.
+ then a test named for the file, then directory overlap. Test support (a
+ helper module) runs nothing on its own, so it goes last; a ``conftest.py``
+ was already replaced by the tests under it (:func:`_expand_scopes`).
"""
name = file_path.rsplit("/", 1)[-1]
named_for = paired_test_names(file_path)
@@ -1037,9 +1041,38 @@ async def _validation_inputs(
unreached = sorted(unanswered - inferred.keys())
if unreached:
inferred.update(tests_matching_by_name(unreached, test_files))
+ inferred = {
+ path: _expand_scopes(path, reached, test_files) for path, reached in inferred.items()
+ }
return ValidationInputs(measured=measured, inferred=inferred, test_files=test_files)
+def _expand_scopes(path: str, reached: ReachedBy, test_files: set[str]) -> ReachedBy:
+ """*reached* with a conftest or test package it stopped at replaced by the tests under it.
+
+ A validation command must name tests a runner collects; ``pytest
+ tests/conftest.py`` runs nothing. A scope with no runnable test under it
+ drops out, so a target reached only through one can end up unknown.
+
+ A root conftest stands for every test in the repository, so the expansion
+ is ranked nearest-first and capped like the walk's own list. ``all_tests``
+ is cleared rather than left uncapped: plan ranking then scores at most the
+ cap per target, and ``total`` keeps the true count, so a capped target
+ reads as incomplete instead of as the whole answer.
+ """
+ found = reached.all_tests or tuple(reached.tests)
+ expanded = expand_test_scopes(found, test_files)
+ if tuple(expanded) == tuple(found):
+ return reached
+ ranked = rank_tests(path, expanded)
+ return dataclasses.replace(
+ reached,
+ tests=ranked[:MAX_TESTS_PER_TARGET],
+ total=len(ranked),
+ all_tests=None,
+ )
+
+
async def _validation_evidence(
session: AsyncSession,
repository_id: str,
diff --git a/packages/core/src/repowise/core/analysis/test_impact.py b/packages/core/src/repowise/core/analysis/test_impact.py
index 2a6d34981..9b2b403b6 100644
--- a/packages/core/src/repowise/core/analysis/test_impact.py
+++ b/packages/core/src/repowise/core/analysis/test_impact.py
@@ -9,13 +9,15 @@ from an empty recommendation population.
from __future__ import annotations
from collections import defaultdict
-from collections.abc import Iterable, Mapping, Sequence
+from collections.abc import Collection, Iterable, Mapping, Sequence
from typing import Any
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from repowise.core.analysis.health.coverage.freshness import coverage_freshness
+from repowise.core.analysis.test_reachability import MAX_TESTS_PER_TARGET, rank_tests
+from repowise.core.analysis.test_selection import expand_test_scopes
from repowise.core.exclusion import is_excluded
from repowise.core.persistence.models import Repository
@@ -113,7 +115,7 @@ async def analyze_test_impact(
Reads the coverage map and graph reachability for *changed_files*, then
hands both to :func:`assemble_test_impact`.
"""
- from repowise.core.analysis.test_reachability import tests_reaching_by_tier
+ from repowise.core.analysis.test_reachability import load_test_files, tests_reaching_by_tier
from repowise.core.persistence.crud import get_test_coverage_summary, tests_covering
changed = _changed_paths(changed_files, exclude_spec)
@@ -155,8 +157,12 @@ async def analyze_test_impact(
coverage_error = type(exc).__name__
inference_error: str | None = None
+ test_files: set[str] = set()
try:
- reached_by_file = await tests_reaching_by_tier(session, repository_id, changed)
+ test_files = await load_test_files(session, repository_id)
+ reached_by_file = await tests_reaching_by_tier(
+ session, repository_id, changed, test_files=test_files
+ )
except Exception as exc:
reached_by_file = {}
inference_error = type(exc).__name__
@@ -170,6 +176,7 @@ async def analyze_test_impact(
measured,
inferred,
summary,
+ repository_test_files=test_files,
indexed_commit=indexed_commit,
indexed_commit_error=indexed_commit_error,
coverage_error=coverage_error,
@@ -202,6 +209,7 @@ def assemble_test_impact(
coverage_error: str | None = None,
inference_error: str | None = None,
indexed_commit_error: str | None = None,
+ repository_test_files: Collection[str] = (),
) -> dict[str, Any]:
"""Fold coverage and reachability evidence into the test-impact result.
@@ -210,7 +218,8 @@ def assemble_test_impact(
when *coverage_summary* reports pairs. *inferred_by_file* maps a changed path
to ``{"tests": [...], "via": tier}``, both keys required, with ``tests`` the
uncapped list (``ReachedBy.all_tests``, not the display-capped ``tests``);
- paths outside *changed_files* are ignored. *coverage_summary* carries
+ paths outside *changed_files* are ignored. That list is used as the walk
+ found it, except where a scope file expanded (below). *coverage_summary* carries
``pair_count``, ``test_count``, ``source_file_count``, ``ingested_at``,
``source_format`` and ``ingested_commit_sha``. The ``*_error`` arguments
are the exception type names of a failed read; each marks the analysis degraded.
@@ -220,6 +229,14 @@ def assemble_test_impact(
A deleted path has no head side to cover, so "no measured tests" there is a
consequence of the deletion and not a coverage gap. Without it every path is
treated as present, which is the historical behaviour.
+
+ *repository_test_files* are the repository's test files, which an inferred
+ ``conftest.py`` or test-package ``__init__.py`` expands into (the runnable
+ ones under its directory). Without them such a file drops out. An expanded
+ list is ranked nearest-first and capped at ``MAX_TESTS_PER_TARGET`` per
+ changed file, so ``files[*].inferred_tests`` and the recommendations it
+ feeds are bounded; ``inferred_tests_total`` and
+ ``inference.candidates_before_dedup`` keep the count before the cap.
"""
changed = _changed_paths(changed_files, exclude_spec)
repository = repository or repository_id
@@ -310,12 +327,17 @@ def assemble_test_impact(
for path, reached in inferred_by_file.items():
if path not in inferred_tests_by_file:
continue
+ expanded = expand_test_scopes(reached["tests"], repository_test_files)
kept_tests = [
test_id
- for test_id in reached["tests"]
+ for test_id in expanded
if not (exclude_spec and is_excluded(test_id, exclude_spec))
]
inferred_totals_by_file[path] = len(kept_tests)
+ if expanded != list(reached["tests"]):
+ # A root conftest stands for every test in the repository: rank the
+ # expansion nearest-first and keep the walk's own per-target cap.
+ kept_tests = rank_tests(path, kept_tests)[:MAX_TESTS_PER_TARGET]
for test_id in kept_tests:
inferred_tests_by_file[path].append(test_id)
key = (repository_id, test_id)
@@ -418,7 +440,7 @@ def assemble_test_impact(
"measured_tests": measured_tests,
"measured_tests_total": len(measured_tests),
"inferred_tests": inferred_tests,
- "inferred_tests_total": len(inferred_tests),
+ "inferred_tests_total": inferred_totals_by_file.get(path, len(inferred_tests)),
}
)
diff --git a/packages/core/src/repowise/core/analysis/test_reachability.py b/packages/core/src/repowise/core/analysis/test_reachability.py
index 1be4a8d90..d644a5b26 100644
--- a/packages/core/src/repowise/core/analysis/test_reachability.py
+++ b/packages/core/src/repowise/core/analysis/test_reachability.py
@@ -450,6 +450,7 @@ async def tests_reaching(
*,
call_depth: int = DEFAULT_CALL_DEPTH,
import_depth: int = DEFAULT_MAX_DEPTH,
+ test_files: set[str] | None = None,
) -> dict[str, list[str]]:
"""Test files that reach each of *targets*, keyed by target path.
@@ -458,7 +459,12 @@ async def tests_reaching(
or as unknown.
"""
found = await tests_reaching_by_tier(
- session, repo_id, targets, call_depth=call_depth, import_depth=import_depth
+ session,
+ repo_id,
+ targets,
+ call_depth=call_depth,
+ import_depth=import_depth,
+ test_files=test_files,
)
return {target: reached.tests for target, reached in found.items()}
diff --git a/packages/core/src/repowise/core/analysis/test_selection.py b/packages/core/src/repowise/core/analysis/test_selection.py
index b48cf3ff0..5fe17563d 100644
--- a/packages/core/src/repowise/core/analysis/test_selection.py
+++ b/packages/core/src/repowise/core/analysis/test_selection.py
@@ -749,6 +749,26 @@ def _tests_under(inits: Collection[str], known_tests: Collection[str]) -> list[s
]
+def expand_test_scopes(tests: Iterable[str], test_files: Collection[str]) -> list[str]:
+ """*tests* as a run list: each scope file replaced by the tests under its directory.
+
+ A graph walk reports a ``conftest.py`` or test-package ``__init__.py`` it
+ stopped at, but pytest collects nothing from either; the tests they run for
+ are the runnable ones among *test_files* below their directory, the same
+ expansion the selection makes. Order is kept and duplicates dropped; a scope
+ with no runnable test under it drops out.
+ """
+ tests = list(tests)
+ if not any(scope_kind(t) for t in tests):
+ return list(dict.fromkeys(tests))
+ runnable = sorted(t for t in test_files if is_runnable_test(t))
+ out: dict[str, None] = {}
+ for test in tests:
+ for expanded in _tests_under([test], runnable) if scope_kind(test) else (test,):
+ out.setdefault(expanded)
+ return list(out)
+
+
def _basis(
path: str,
covered: Mapping[str, Any],
diff --git a/packages/core/src/repowise/core/workspace/test_impact.py b/packages/core/src/repowise/core/workspace/test_impact.py
index 94ca52806..b735f84b2 100644
--- a/packages/core/src/repowise/core/workspace/test_impact.py
+++ b/packages/core/src/repowise/core/workspace/test_impact.py
@@ -23,8 +23,10 @@ from repowise.core.analysis.test_reachability import (
DEFAULT_CALL_DEPTH,
DEFAULT_MAX_DEPTH,
MAX_TESTS_PER_TARGET,
+ load_test_files,
tests_reaching_by_tier,
)
+from repowise.core.analysis.test_selection import expand_test_scopes, scope_kind
from repowise.core.persistence.crud.analysis.coverage_map import tests_covering_files
from repowise.core.workspace.config import WorkspaceConfig
from repowise.core.workspace.contracts import ContractLink, load_contract_store, same_service
@@ -260,6 +262,7 @@ async def _analyze_consumer(
files = sorted(bound)
measured: dict[str, list[dict[str, Any]]] = {}
reached: dict[str, Any] = {}
+ test_files: set[str] = set()
# A pass that fails takes down only its own signal; whatever the other pass
# found, and the links already classified, still reach the caller.
failures: list[str] = []
@@ -306,6 +309,12 @@ async def _analyze_consumer(
import_depth=import_depth,
)
reached = {**by_file_reached, **by_symbol}
+ # Read only when the walk stopped at a conftest or test package,
+ # which stands for the tests under its directory.
+ if any(
+ scope_kind(t) for hit in reached.values() for t in hit.all_tests or hit.tests
+ ):
+ test_files = await load_test_files(session, repo_index.repo_id)
except Exception as exc:
failures.append(f"inferred: {type(exc).__name__}")
@@ -357,7 +366,9 @@ async def _analyze_consumer(
continue
# The walk trims its own list per target; the join caps per consumer
# and provider pair below and reports the cut, so start from all of them.
- reached_tests = list(hit.all_tests or hit.tests)
+ reached_tests = expand_test_scopes(hit.all_tests or hit.tests, test_files)
+ if not reached_tests:
+ continue
file_tests.update(reached_tests)
if file_via is None or _TIER_PRIORITY.get(hit.via, 99) < _TIER_PRIORITY.get(file_via, 99):
file_via = hit.via
diff --git a/packages/server/src/repowise/server/mcp_server/tool_change_risk.py b/packages/server/src/repowise/server/mcp_server/tool_change_risk.py
index 0a298c573..1719ec49c 100644
--- a/packages/server/src/repowise/server/mcp_server/tool_change_risk.py
+++ b/packages/server/src/repowise/server/mcp_server/tool_change_risk.py
@@ -1106,7 +1106,8 @@ async def _inferred_impacted(
a signal that cannot speak to lines - the distinction this whole block
exists to keep.
"""
- from repowise.core.analysis.test_reachability import tests_reaching
+ from repowise.core.analysis.test_reachability import load_test_files, tests_reaching
+ from repowise.core.analysis.test_selection import expand_test_scopes
hint = (
"Inferred from the dependency graph, not measured. For the line-precise "
@@ -1114,10 +1115,14 @@ async def _inferred_impacted(
"`repowise coverage add`."
)
try:
- reaching = await tests_reaching(session, repo_id, changed_files)
+ test_files = await load_test_files(session, repo_id)
+ reaching = await tests_reaching(session, repo_id, changed_files, test_files=test_files)
except Exception:
- reaching = {}
- tests = rank_tests_by_reach(reaching)
+ test_files, reaching = set(), {}
+ # A conftest the walk stopped at stands for the tests under its directory.
+ tests = rank_tests_by_reach(
+ {path: expand_test_scopes(found, test_files) for path, found in reaching.items()}
+ )
if not tests:
return _empty_impacted(
"no_map",
diff --git a/tests/unit/analysis/test_assemble_test_impact.py b/tests/unit/analysis/test_assemble_test_impact.py
index a7c1353f8..3305cef43 100644
--- a/tests/unit/analysis/test_assemble_test_impact.py
+++ b/tests/unit/analysis/test_assemble_test_impact.py
@@ -56,6 +56,74 @@ def test_read_failures_mark_each_side_degraded() -> None:
assert impact["analysis"]["status"] == "degraded"
+_INFERRED = {
+ "src/b.py": {"tests": ["tests/unit/conftest.py", "tests/test_b.py"], "via": "imports"},
+ "src/c.py": {"tests": ["tests/unit/conftest.py"], "via": "call-graph"},
+}
+_TEST_FILES = {
+ "tests/unit/conftest.py",
+ "tests/unit/test_x.py",
+ "tests/unit/helpers.py",
+ "tests/test_b.py",
+}
+
+
+def test_a_conftest_the_walk_reached_stands_for_the_tests_under_it() -> None:
+ """pytest collects nothing from a conftest; it runs for the tests below it."""
+ impact = assemble_test_impact(
+ ["src/b.py", "src/c.py"], {}, _INFERRED, {}, repository_id="r1", repository_test_files=_TEST_FILES
+ )
+ assert [r["test_id"] for r in impact["recommendations"]] == [
+ "tests/unit/test_x.py",
+ "tests/test_b.py",
+ ]
+ c = next(r for r in impact["files"] if r["source_file"] == "src/c.py")
+ assert (c["status"], c["inferred_tests"]) == ("inferred", ["tests/unit/test_x.py"])
+ assert impact["unknown_files"] == []
+
+
+def test_without_the_test_files_a_conftest_drops_out() -> None:
+ impact = assemble_test_impact(["src/b.py", "src/c.py"], {}, _INFERRED, {}, repository_id="r1")
+ assert [r["test_id"] for r in impact["recommendations"]] == ["tests/test_b.py"]
+ assert impact["unknown_files"] == ["src/c.py"]
+
+
+def test_a_root_conftest_expansion_is_ranked_and_capped_per_file() -> None:
+ """A root conftest stands for every test; it must not flood the result."""
+ from repowise.core.analysis.test_reachability import MAX_TESTS_PER_TARGET
+
+ many = {f"tests/aaa/test_{i:03}.py" for i in range(MAX_TESTS_PER_TARGET + 20)}
+ impact = assemble_test_impact(
+ ["src/core.py"],
+ {},
+ {"src/core.py": {"tests": ["conftest.py"], "via": "call-graph"}},
+ {},
+ repository_id="r1",
+ repository_test_files={"conftest.py", "tests/unit/test_core.py", *many},
+ )
+ row = impact["files"][0]
+ assert len(row["inferred_tests"]) == MAX_TESTS_PER_TARGET
+ assert row["inferred_tests_total"] == MAX_TESTS_PER_TARGET + 21
+ assert "tests/unit/test_core.py" in row["inferred_tests"] # nearest kept, not first
+ assert impact["recommendations_total"] == MAX_TESTS_PER_TARGET
+ assert impact["inference"]["candidates_before_dedup"] == MAX_TESTS_PER_TARGET + 21
+
+
+def test_expand_test_scopes_replaces_only_scope_files() -> None:
+ from repowise.core.analysis.test_selection import expand_test_scopes
+
+ files = {"tests/a/test_one.py", "tests/a/helpers.py", "tests/b/test_two.py", "tests/b/__init__.py"}
+ assert expand_test_scopes(
+ ["tests/test_conftest.py", "tests/a/conftest.py", "tests/a/helpers.py", "tests/a/test_one.py"],
+ files,
+ ) == ["tests/test_conftest.py", "tests/a/test_one.py", "tests/a/helpers.py"]
+ assert expand_test_scopes(["tests/b/__init__.py"], files) == ["tests/b/test_two.py"]
+ assert expand_test_scopes(["conftest.py"], files) == [
+ "tests/a/test_one.py",
+ "tests/b/test_two.py",
+ ]
+
+
def test_nothing_changed() -> None:
impact = assemble_test_impact([], {}, {}, {}, repository_id="r1")
assert impact["files"] == []
diff --git a/tests/unit/health/test_recommendations.py b/tests/unit/health/test_recommendations.py
index 9a90d86d9..e697a159d 100644
--- a/tests/unit/health/test_recommendations.py
+++ b/tests/unit/health/test_recommendations.py
@@ -196,6 +196,43 @@ def test_the_test_named_for_the_file_survives_the_cap() -> None:
assert validation.tests == ["tests/unit/test_core.py"]
+def test_a_reached_conftest_validates_with_the_tests_under_it() -> None:
+ """``pytest tests/unit/conftest.py`` collects nothing; the tests below it run."""
+ from repowise.core.analysis.health.refactoring.recommendations import _expand_scopes
+
+ test_files = {"tests/unit/conftest.py", "tests/unit/test_core.py", "tests/other/test_x.py"}
+ reached = ReachedBy(
+ ["tests/unit/conftest.py"], "call-graph", 1, ("tests/unit/conftest.py",)
+ )
+ validation = build_validation_plan(
+ _plan("fixture"), {}, {"src/core.py": _expand_scopes("src/core.py", reached, test_files)}
+ )
+ assert validation.basis == "inferred"
+ assert validation.tests == ["tests/unit/test_core.py"]
+ assert validation.commands == ["pytest tests/unit/test_core.py"]
+
+
+def test_a_root_conftest_expansion_is_ranked_before_it_is_capped() -> None:
+ """A root conftest stands for every test; the cut keeps the nearest, not the first."""
+ from repowise.core.analysis.health.refactoring.recommendations import _expand_scopes
+ from repowise.core.analysis.test_reachability import MAX_TESTS_PER_TARGET
+
+ many = {f"tests/aaa/test_{i:03}.py" for i in range(MAX_TESTS_PER_TARGET + 20)}
+ test_files = {"conftest.py", "tests/unit/test_core.py", *many}
+ reached = ReachedBy(["conftest.py"], "call-graph", 1, ("conftest.py",))
+
+ expanded = _expand_scopes("src/core.py", reached, test_files)
+
+ assert expanded.total == MAX_TESTS_PER_TARGET + 21
+ assert len(expanded.tests) == MAX_TESTS_PER_TARGET
+ assert expanded.tests[0] == "tests/unit/test_core.py" # named for the target
+ assert expanded.all_tests is None # plan ranking scores the capped list only
+ validation = build_validation_plan(_plan("fixture"), {}, {"src/core.py": expanded})
+ assert validation.total == MAX_TESTS_PER_TARGET + 21
+ assert validation.truncated is True
+ assert validation.tests[0] == "tests/unit/test_core.py"
+
+
def test_aggregate_validation_total_deduplicates_tests_across_targets() -> None:
plan = _plan("shared", file_path="src/a.py")
plan.blast_radius = {"files": ["src/b.py"]}
diff --git a/tests/unit/server/mcp/test_tool_change_risk.py b/tests/unit/server/mcp/test_tool_change_risk.py
index e6b1df2d7..013a0220a 100644
--- a/tests/unit/server/mcp/test_tool_change_risk.py
+++ b/tests/unit/server/mcp/test_tool_change_risk.py
@@ -291,6 +291,39 @@ async def test_inferred_tests_treat_a_failed_graph_walk_as_no_reach(
assert "run the full suite" in block["summary"]
+async def test_inferred_tests_run_the_tests_under_a_conftest_not_the_conftest(
+ monkeypatch, session, repo_id, tmp_path
+):
+ """The walk reports a conftest it stopped at; pytest collects nothing from one.
+
+ It stands for the tests under its directory, so ``b.py``, reached only
+ through it, still gets tests rather than "run the full suite".
+ """
+ import repowise.core.analysis.test_reachability as reach
+
+ async def _test_files(*_a, **_k):
+ return {
+ "tests/unit/conftest.py",
+ "tests/unit/test_a.py",
+ "tests/unit/sub/test_b.py",
+ "tests/unit/helpers.py",
+ "tests/other/test_c.py",
+ }
+
+ async def _reaching(*_a, **_k):
+ return {"a.py": ["tests/unit/test_a.py"], "b.py": ["tests/unit/conftest.py"]}
+
+ monkeypatch.setattr(reach, "load_test_files", _test_files)
+ monkeypatch.setattr(reach, "tests_reaching", _reaching)
+ block = await tool._inferred_impacted(
+ session, repo_id, ["a.py", "b.py"], OmissionCollector("get_change_risk", repo_root=tmp_path)
+ )
+ # test_a reaches both files, so it leads.
+ assert block["tests_to_run"] == ["tests/unit/test_a.py", "tests/unit/sub/test_b.py"]
+ assert block["total"] == 2
+
+
@pytest.mark.asyncio
async def test_independent_changes_are_silent_for_one_file_or_an_unreadable_index(
monkeypatch, factory, tmp_path
diff --git a/tests/unit/workspace/test_test_impact.py b/tests/unit/workspace/test_test_impact.py
index 9ad6768b1..3a6d30c80 100644
--- a/tests/unit/workspace/test_test_impact.py
+++ b/tests/unit/workspace/test_test_impact.py
@@ -714,3 +714,59 @@ async def test_a_caller_supplies_its_own_reads_over_an_index_built_from_rows() -
("tests/walk.test.ts", "inferred"),
}
assert result.unresolved == []
+
+
+# ---------------------------------------------------------------------------
+# A conftest the walk stopped at
+# ---------------------------------------------------------------------------
+
+
+async def test_a_conftest_stands_for_the_tests_under_it_and_drops_out_with_none(
+ tmp_path: Path,
+) -> None:
+ """pytest collects nothing from a conftest; it runs for the tests below it.
+
+ ``client`` in ``tests/unit/conftest.py`` is the only caller of ``get_user``,
+ so its link is guarded by the test under that directory. ``tests/lonely/``
+ has no test, so ``list_users``, reached only by its conftest, has none.
+ """
+ index = await make_repo_index(
+ tmp_path / "frontend",
+ {"src/api.py": [_symbol("src/api.py::get_user"), _symbol("src/api.py::list_users")]},
+ alias="frontend",
+ graph_nodes=(
+ ("src/api.py", False),
+ ("tests/unit/conftest.py", True),
+ ("tests/unit/test_users.py", True),
+ ("tests/lonely/conftest.py", True),
+ ),
+ graph_edges=(
+ ("src/api.py", "src/api.py::get_user", "defines"),
+ ("src/api.py", "src/api.py::list_users", "defines"),
+ ("tests/unit/conftest.py", "tests/unit/conftest.py::client", "defines"),
+ ("tests/lonely/conftest.py", "tests/lonely/conftest.py::db", "defines"),
+ ("tests/unit/conftest.py::client", "src/api.py::get_user", "calls"),
+ ("tests/lonely/conftest.py::db", "src/api.py::list_users", "calls"),
+ ),
+ )
+ guarded = _link(consumer_file="src/api.py", consumer_symbol_id="src/api.py::get_user")
+ lonely = _link(
+ consumer_file="src/api.py",
+ consumer_symbol_id="src/api.py::list_users",
+ contract_id="http::GET::/users",
+ )
+ try:
+ both = await analyze_workspace_test_impact(
+ WorkspaceIndex({"frontend": index}), [guarded, lonely], CHANGED, include_measured=False
+ )
+ alone = await analyze_workspace_test_impact(
+ WorkspaceIndex({"frontend": index}), [lonely], CHANGED, include_measured=False
+ )
+ finally:
+ await index.close()
+
+ assert [(r.test_file, r.consumer_symbol_ids) for r in both.recommendations] == [
+ ("tests/unit/test_users.py", ["src/api.py::get_user"])
+ ]
+ assert not alone.recommendations
+ assert [row["state"] for row in alone.files_analyzed] == ["none"]
\ No newline at end of file