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
perf(risk): serve the PR blast radius only on request (#3118)
Raghav Chamadiya9d6fb543d995
diff --git a/docs/agent/MCP_TOOLS.md b/docs/agent/MCP_TOOLS.mdindex 358115893..625b2aa6e 100644--- a/docs/agent/MCP_TOOLS.md+++ b/docs/agent/MCP_TOOLS.md@@ -227,10 +227,10 @@ What history says about touching a file: hotspot score, bug-fix record, owners,|-----------|------|---------|---------|| `targets` | list[string] | `changed_files` | File paths to assess || `changed_files` | list[string] | none | Files in a change; switches on PR mode |-| `include` | list[string] | none | `graph` (typed dependents, consumers, cross-repo links), `churn`, `tests` (typed `test_recommendations` in PR mode), `scales` (units and calibration, identical per call) |+| `include` | list[string] | none | `graph` (typed dependents, consumers, cross-repo links), `churn`, `tests` (typed `test_recommendations` in PR mode), `blast` (`pr_blast_radius` in PR mode), `scales` (units and calibration, identical per call) || `repo` | string | default repo | Workspace repo alias. `"all"` is not supported |-**Key return fields:** per file: `hotspot_score` (0 to 1), `health_score` (0 to 10), `dependents_count`, `co_change_partners`, owners, test gaps, `security_signals`. In PR mode, `directive` with `may_break`, `missing_cochanges`, `tests_to_run`, `tests_to_run_basis` (`measured`, `inferred` or `none`), `tests_to_update` (test files to edit, each with a `name_pair`, `imports` or `co_change` reason), `coverage`, `next_calls`, and the 0 to 10 `structural_impact_score`. `missing_tests` appears only when coverage can back it. A target naming no indexed file returns `resolved: false` with a reason, never zeroed counts.+**Key return fields:** per file: `hotspot_score` (0 to 1), `health_score` (0 to 10), `dependents_count`, `co_change_partners`, owners, test gaps, `security_signals`. In PR mode, `directive` with `may_break`, `missing_cochanges`, `tests_to_run`, `tests_to_run_basis` (`measured`, `inferred` or `none`), `tests_to_update` (test files to edit, each with a `name_pair`, `imports` or `co_change` reason), `coverage`, `recommended_reviewers` and `next_calls`. `include=["blast"]` adds `pr_blast_radius` with the 0 to 10 `structural_impact_score`. `missing_tests` appears only when coverage can back it. A target naming no indexed file returns `resolved: false` with a reason, never zeroed counts.Dependent counts are a floor over the indexed graph, and structural reach is not proof of runtime breakage. `structural_impact_score` is an uncalibrated heuristic, not a probability.diff --git a/docs/layers/CHANGE_RISK.md b/docs/layers/CHANGE_RISK.mdindex fb4a5aae8..802ae3c32 100644--- a/docs/layers/CHANGE_RISK.md+++ b/docs/layers/CHANGE_RISK.md@@ -156,7 +156,8 @@ index), `conformance_violations` and `dependency_cycles`. See[Cross-Repo Blast Radius](../scale/WORKSPACES.md#cross-repo-blast-radius) and[Breaking-Change Guard](../scale/WORKSPACES.md#breaking-change-guard).-PR mode also reports `structural_impact_score`: a deterministic, uncalibrated+The directive also names `recommended_reviewers`. With `include=["blast"]`,+PR mode adds `pr_blast_radius`, whose `structural_impact_score` is a deterministic, uncalibrated0-10 heuristic over PageRank, churn and transitive dependents, banded`localized` (below 4), `moderate` (4 to below 7) and `broad` (7 and up). It isnot a probability and does not decide review. `overall_risk_score` is an exactdiff --git a/docs/layers/OWNERSHIP.md b/docs/layers/OWNERSHIP.mdindex cf8df5487..72e017270 100644--- a/docs/layers/OWNERSHIP.md+++ b/docs/layers/OWNERSHIP.md@@ -125,7 +125,7 @@ differently:file's 90-day activity. Authors of each touched file's five strongestco-change partners score at half weight. Each suggestion lists the files itowns and the co-change files behind it.-- **`get_risk(changed_files=...)`**: `pr_blast_radius.recommended_reviewers` lists+- **`get_risk(changed_files=...)`**: `directive.recommended_reviewers` listsup to five primary owners of the affected files, ranked by how many of thosefiles they own, then by average ownership share.diff --git a/docs/reference/MCP_RESPONSE_FIELDS.md b/docs/reference/MCP_RESPONSE_FIELDS.mdindex f797ba259..a483cb5e4 100644--- a/docs/reference/MCP_RESPONSE_FIELDS.md+++ b/docs/reference/MCP_RESPONSE_FIELDS.md@@ -214,7 +214,7 @@ Per file:| test gaps, `security_signals` | Test coverage gaps and security findings for the file || `resolved`, `unresolved_reason` | A target naming no indexed file: `unsupported_target_kind` (a `module:` id), `directory`, `not_indexed`, `no_such_path`. Counts are omitted, never zeroed |-Opt-in blocks: `tests` adds the PR directive's typed `test_recommendations`. `graph` adds typed `dependents` (direct versus transitive), `consumers` (typed contract consumers only), `cross_repo_links`, `impact_surface` and `direct_risks`, with `relationship_analysis` distinguishing an empty analysis from an unavailable or partial one. `churn` adds `change_magnitude`, `risk_type` and `change_pattern`. `scales` adds the unit, range and calibration of every scalar; it is identical on every call, so ask once. A multi-target call also carries `global_hotspots`.+Opt-in blocks: `tests` adds the PR directive's typed `test_recommendations`, and `blast` adds `pr_blast_radius`, the PR dossier behind the directive (transitive files, co-change warnings, test gaps, the structural score; reviewers stay in the directive). `graph` adds typed `dependents` (direct versus transitive), `consumers` (typed contract consumers only), `cross_repo_links`, `impact_surface` and `direct_risks`, with `relationship_analysis` distinguishing an empty analysis from an unavailable or partial one. `churn` adds `change_magnitude`, `risk_type` and `change_pattern`. `scales` adds the unit, range and calibration of every scalar; it is identical on every call, so ask once. A multi-target call also carries `global_hotspots`.**PR mode** (`changed_files` passed). The response starts with `directive`:@@ -227,7 +227,8 @@ Opt-in blocks: `tests` adds the PR directive's typed `test_recommendations`. `gr| `missing_tests`, `files_without_measured_tests` | Changed files with no measured test. `missing_tests` is absent when coverage is unavailable or stale, since an empty list would read as no gaps || `coverage` | `{status, reason}` when there is no per-test coverage map. With a map, `coverage_analysis`, `test_analysis` and `test_inference_analysis` say whether each evidence source was available, stale, partial or degraded || `test_recommendations` | With `include=["tests"]`: typed rows, each with a `basis`: `measured` (the per-test coverage map found the test) or `inferred` (structural reach, not coverage proof) |-| `structural_impact_score` | Uncalibrated 0 to 10 structural heuristic: `localized` below 4, `moderate` 4 to below 7, `broad` 7 and up. Not a breakage probability. `overall_risk_score` is a deprecated alias |+| `recommended_reviewers` | Up to five primary owners of the affected files |+| `pr_blast_radius.structural_impact_score` | With `include=["blast"]`: uncalibrated 0 to 10 structural heuristic: `localized` below 4, `moderate` 4 to below 7, `broad` 7 and up. Not a breakage probability. `overall_risk_score` is a deprecated alias || `next_calls` | `get_change_risk()` for the diff itself, then `get_context` on the first `may_break` files |In workspace mode the directive also carries `will_break_consumers` (services in other repos that structurally depend on this one; structural reach only despite the name), `missing_cross_repo_cochanges`, `breaking_changes` (provider incompatibilities since the last index, with impacted consumers; a consumer link does not prove field use), `conformance_violations` and `dependency_cycles`. They are dropped when no workspace is loaded.diff --git a/packages/cli/src/repowise/cli/commands/risk_cmd.py b/packages/cli/src/repowise/cli/commands/risk_cmd.pyindex 2fcae98d8..ea95ed82b 100644--- a/packages/cli/src/repowise/cli/commands/risk_cmd.py+++ b/packages/cli/src/repowise/cli/commands/risk_cmd.py@@ -99,10 +99,8 @@ def project_risk(payload: dict) -> dict:timing half of ``_meta``, and the per-target keys named above.``pr_blast_radius`` survives although ``directive`` summarises much of it,- because ``recommended_reviewers`` has no substitute anywhere else in the- response, and because the tool has *already* capped its four noisy lists- (15/10/10/5) before it gets here — so the block a caller would most want is- the one an allowlist would silently discard, at almost no size.+ because the tool has *already* capped its four noisy lists (15/10/10/5)+ before it gets here, so keeping it costs almost nothing."""out: dict = {}if payload.get("directive"):@@ -142,8 +140,9 @@ def _target_risk(return get_risk(targets=list(targets),changed_files=list(changed_files) or None,- # _render_target_risk prints risk_type and change_magnitude.- include=["churn"],+ # _render_target_risk prints risk_type and change_magnitude; --format+ # json keeps the PR blast radius the tool serves only on request.+ include=["churn", "blast"],)payload = _ta.run(repo, _factory, "get_risk")diff --git a/packages/server/src/repowise/server/mcp_server/_budget/contracts.py b/packages/server/src/repowise/server/mcp_server/_budget/contracts.pyindex 2b2c3017f..c905b5306 100644--- a/packages/server/src/repowise/server/mcp_server/_budget/contracts.py+++ b/packages/server/src/repowise/server/mcp_server/_budget/contracts.py@@ -114,6 +114,8 @@ _CONTRACTS: dict[str, ResponseBudgetContract] = {),requested_projections=((+ # The cards are the changed files, so they outlive the blast+ # block, which stays first to go even when asked for."changed_files",("directive.test_recommendations[]",@@ -121,8 +123,7 @@ _CONTRACTS: dict[str, ResponseBudgetContract] = {"directive.tests_to_update[]","directive.may_break[]","directive.next_calls[]",- "pr_blast_radius",- "pr_blast_radius.guarding_tests",+ "targets[]",),),# targets is required, so it is always asked for. Without this thediff --git a/packages/server/src/repowise/server/mcp_server/tool_risk/directives.py b/packages/server/src/repowise/server/mcp_server/tool_risk/directives.pyindex 57aea0e88..9318875ea 100644--- a/packages/server/src/repowise/server/mcp_server/tool_risk/directives.py+++ b/packages/server/src/repowise/server/mcp_server/tool_risk/directives.py@@ -546,6 +546,7 @@ def _build_pr_directive(*,full_scale: bool = False,include_tests: bool = False,+ include_blast: bool = False,) -> None:"""Assemble PR-mode output: trim co-change lists + blast radius, then buildthe directive block. Mutates *response* in place. Behavior preserved.@@ -572,10 +573,16 @@ def _build_pr_directive(r["co_change_partners_emitted"] = emittedr["co_change_partners_truncated"] = emitted < total+ # The blast block mostly repeats the directive, so it ships on request;+ # unrequested, its trimmed rows are not omissions to recover.trimmed_blast = _trim_blast_lists(- pr_blast_radius, exclude_spec, collector, full_scale=full_scale+ pr_blast_radius,+ exclude_spec,+ collector if include_blast else None,+ full_scale=full_scale,)- response["pr_blast_radius"] = trimmed_blast+ if include_blast:+ response["pr_blast_radius"] = trimmed_blast# Directive: 3 short lists the agent can read in one glance. Each# entry is a file path (string), never a dossier. Designed to answer@@ -820,6 +827,7 @@ def _build_pr_directive("conformance_violations": conformance_violations,"dependency_cycles": dependency_cycles,"governance_risk": governance_risk,+ "recommended_reviewers": trimmed_blast.get("recommended_reviewers") or [],"next_calls": [c.as_dict() for c in next_calls],"summary": (f"PR touches {len(changed_files)} file(s). "@@ -921,6 +929,9 @@ def _build_pr_directive():directive.pop("cross_repo_relationship_analysis", None)+ # The directive carries the reviewers, so the MCP blast copy would repeat+ # them. The REST blast radius is built separately and keeps its field.+ _drop_family(trimmed_blast, "recommended_reviewers")response["directive"] = directivediff --git a/packages/server/src/repowise/server/mcp_server/tool_risk/get_risk.py b/packages/server/src/repowise/server/mcp_server/tool_risk/get_risk.pyindex 5f3075ca9..5da1a963a 100644--- a/packages/server/src/repowise/server/mcp_server/tool_risk/get_risk.py+++ b/packages/server/src/repowise/server/mcp_server/tool_risk/get_risk.py@@ -20,6 +20,7 @@ from repowise.core.persistence.models import ()from repowise.core.registry import ToolRecipefrom repowise.core.registry import mcp_tool_registry as mcp+from repowise.core.support_paths import is_doc_or_config_pathfrom repowise.server.mcp_server._budget import OmissionCollector, cap_collectionfrom repowise.server.mcp_server._episodes import enrich_episode_counts as _enrich_episodesfrom repowise.server.mcp_server._helpers import (@@ -81,10 +82,9 @@ _TARGET_CARD_INCLUDES: dict[str, tuple[str, ...]] = {}_BLAST_INCLUDES: dict[str, tuple[str, ...]] = {"graph": ("direct_risks",)}#: Per-field units and calibration. Identical on every call, so it is opt-in.-#: ``tests`` adds the PR directive's typed ``test_recommendations`` rows.-_INCLUDE_BLOCKS = (- frozenset(_TARGET_CARD_INCLUDES) | frozenset(_BLAST_INCLUDES) | {"scales", "tests"}-)+#: ``tests`` adds the PR directive's typed ``test_recommendations`` rows and+#: ``blast`` the ``pr_blast_radius`` dossier.+_INCLUDE_BLOCKS = frozenset(_TARGET_CARD_INCLUDES) | {"blast", "scales", "tests"}def _drop_opt_in_blocks(response: dict, include: set[str]) -> None:@@ -312,6 +312,7 @@ async def _lead_with_pr_directive(collector: OmissionCollector,full_scale: bool,include_tests: bool,+ include_blast: bool,) -> dict:governance_risk = await _governance_directive(ctx, changed_files)_build_pr_directive(@@ -325,6 +326,7 @@ async def _lead_with_pr_directive(ctx.alias,full_scale=full_scale,include_tests=include_tests,+ include_blast=include_blast,)# Insertion order is the serialized order, and PR mode leads with the directive.return {"directive": response.pop("directive"), **response}@@ -368,9 +370,9 @@ async def get_risk(measured or inferred. To score a commit or ``base..head`` range instead,use ``get_change_risk``.- In PR mode ``structural_impact_score`` is an uncalibrated 0-10 structural- heuristic, never a runtime-breakage probability; ``overall_risk_score`` is- its deprecated exact alias.+ ``include=["blast"]`` adds ``pr_blast_radius``, whose+ ``structural_impact_score`` is an uncalibrated 0-10 heuristic, never a+ runtime-breakage probability.Default responses fit 24,000 serialized chars; nonempty ``include`` uses32,000. Reductions carry counts and ``_meta.omitted`` recovery refs;@@ -382,7 +384,7 @@ async def get_risk(repo: usually omitted.changed_files: PR-changed files for blast-radius mode.include: opt-in blocks - "graph", "churn", "tests" (typed test- rows), "scales" (units and calibration; identical per call).+ rows), "blast", "scales" (units and calibration; identical per call)."""if repo == "all":return _unsupported_repo_all("get_risk")@@ -405,8 +407,12 @@ async def get_risk()await _enrich_cards(evidence.results, ctx, evidence.repository.id, collector, include_graph)+ # The budget sheds cards from the tail, so docs and config cards go last.+ cards = evidence.results+ if changed_files:+ cards = sorted(cards, key=lambda r: is_doc_or_config_path(r["target"]))response: dict = {- "targets": {r["target"]: r for r in evidence.results},+ "targets": {r["target"]: r for r in cards},**({"risk_scales": file_risk_scales()} if "scales" in include_set else {}),}if evidence.pr_blast_radius is not None:@@ -419,6 +425,7 @@ async def get_risk(collector,full_scale="scales" in include_set,include_tests="tests" in include_set,+ include_blast="blast" in include_set,)elif len(targets) > 1:# Ambient hotspots orient a multi-file request; beside one named file they are noise.diff --git a/plugins/claude-code/skills/change-review/SKILL.md b/plugins/claude-code/skills/change-review/SKILL.mdindex 748ce629c..3fcd30aa2 100644--- a/plugins/claude-code/skills/change-review/SKILL.md+++ b/plugins/claude-code/skills/change-review/SKILL.md@@ -74,7 +74,7 @@ The response carries its own `directive` block, per file rather than per changegraph filling in where it is silent, which needs no coverage ingest but is acandidate list, so say so rather than presenting it as proof; `none` with an empty list is "unknown", never "no tests exist".-`pr_blast_radius` holds the fuller dossier behind those lists (including the+`include=["blast"]` adds `pr_blast_radius`, the fuller dossier behind those lists (including theper-changed-file `guarding_tests` breakdown behind `tests_to_run`).For the line-precise version from a terminal, `repowise impacted-tests <revspec>`diff --git a/plugins/codex/skills/change-review/SKILL.md b/plugins/codex/skills/change-review/SKILL.mdindex a1cd33a51..3f6a82998 100644--- a/plugins/codex/skills/change-review/SKILL.md+++ b/plugins/codex/skills/change-review/SKILL.md@@ -69,7 +69,7 @@ The response carries its own `directive` block, per file rather than per changegraph filling in where it is silent, which needs no coverage ingest but is acandidate list, so say so rather than presenting it as proof; `none` with an empty list is "unknown", never "no tests exist".-`pr_blast_radius` holds the fuller dossier behind those lists (including the+`include=["blast"]` adds `pr_blast_radius`, the fuller dossier behind those lists (including theper-changed-file `guarding_tests` breakdown behind `tests_to_run`).For the line-precise version from a terminal, `repowise impacted-tests <revspec>`diff --git a/plugins/shared/skills/change-review.md b/plugins/shared/skills/change-review.mdindex b9bdd4593..cfcaee09c 100644--- a/plugins/shared/skills/change-review.md+++ b/plugins/shared/skills/change-review.md@@ -82,7 +82,7 @@ The response carries its own `directive` block, per file rather than per changegraph filling in where it is silent, which needs no coverage ingest but is acandidate list, so say so rather than presenting it as proof; `none` with an empty list is "unknown", never "no tests exist".-`pr_blast_radius` holds the fuller dossier behind those lists (including the+`include=["blast"]` adds `pr_blast_radius`, the fuller dossier behind those lists (including theper-changed-file `guarding_tests` breakdown behind `tests_to_run`).For the line-precise version from a terminal, `repowise impacted-tests <revspec>`diff --git a/scripts/measure_mcp_response_sizes.py b/scripts/measure_mcp_response_sizes.pyindex ced418be3..00b192bdb 100644--- a/scripts/measure_mcp_response_sizes.py+++ b/scripts/measure_mcp_response_sizes.py@@ -50,7 +50,7 @@ CASES: list[tuple[str, str, dict[str, Any]]] = [("get_health", "all-includes", {"include": ["files", "refactoring", "performance"], "limit": 100}),("get_risk", "one-target", {"targets": ["{file}"]}),("get_risk", "pr-mode", {"targets": ["{file}"], "changed_files": ["{file}", "{file2}"]}),- ("get_risk", "pr-mode-tests", {"targets": ["{file}"], "changed_files": ["{file}", "{file2}"], "include": ["tests"]}),+ ("get_risk", "pr-mode-includes", {"targets": ["{file}"], "changed_files": ["{file}", "{file2}"], "include": ["tests", "blast"]}),("get_change_risk", "head", {"revspec": "HEAD"}),("get_why", "targets", {"targets": ["{file}"]}),("get_dead_code", "default", {}),diff --git a/tests/fixtures/mcp/tool_response_shapes.json b/tests/fixtures/mcp/tool_response_shapes.jsonindex 8eaad1edd..be991fdd8 100644--- a/tests/fixtures/mcp/tool_response_shapes.json+++ b/tests/fixtures/mcp/tool_response_shapes.json@@ -1400,6 +1400,13 @@"tool": null}],+ "recommended_reviewers": [+ {+ "email": null,+ "files": null,+ "ownership_pct": null+ }+ ],"summary": null,"test_recommendations": [{@@ -1535,16 +1542,6 @@"historical_meaning": null,"replacement": null},- "recommended_reviewers": [- {- "email": null,- "files": null,- "ownership_pct": null- }- ],- "recommended_reviewers_emitted": null,- "recommended_reviewers_total": null,- "recommended_reviewers_truncated": null,"structural_impact_band": null,"structural_impact_scale": {"authoritative_for_change_review": null,diff --git a/tests/unit/cli/test_risk_cmd_contract.py b/tests/unit/cli/test_risk_cmd_contract.pyindex 8a89d5279..ef8b5b872 100644--- a/tests/unit/cli/test_risk_cmd_contract.py+++ b/tests/unit/cli/test_risk_cmd_contract.py@@ -169,12 +169,11 @@ def test_the_target_projection_drops_exactly_what_it_documents() -> None:def test_the_projection_keeps_the_blocks_a_caller_cannot_get_elsewhere() -> None:- """``pr_blast_radius`` survives because ``recommended_reviewers`` has no- substitute anywhere else in the response."""+ """``pr_blast_radius`` survives the projection whole."""payload = {"directive": {"status": "review"},"targets": {},- "pr_blast_radius": {"recommended_reviewers": ["dev"]},+ "pr_blast_radius": {"test_gaps": ["a.py"]},"global_hotspots": [{"path": "a.py"}],"risk_scales": [{"unit": "items"}],"omission_marker": "repowise#abc",diff --git a/tests/unit/cli/test_search_collapse.py b/tests/unit/cli/test_search_collapse.pyindex e72adc329..6a4293b01 100644--- a/tests/unit/cli/test_search_collapse.py+++ b/tests/unit/cli/test_search_collapse.py@@ -197,12 +197,12 @@ PR_RISK_PAYLOAD = {{"file": "persist.py", "decision_id": "dr-7", "title": "persist tombstones","status": "accepted", "reason": "stale_governance"}],+ "recommended_reviewers": [{"name": "Raghav Chamadiya", "commits": 40}],"overall_risk_score": 7.4,"summary": "PR touches 1 file(s). ~1 downstream file(s) may be affected.",},"pr_blast_radius": {"transitive_affected": ["packages/core/src/repowise/core/pipeline/orchestrator.py"],- "recommended_reviewers": [{"name": "Raghav Chamadiya", "commits": 40}],"test_gaps": ["packages/core/src/repowise/core/pipeline/persist.py"],"overall_risk_score": 7.4,},@@ -775,13 +775,13 @@ def test_risk_target_error_exits_one(monkeypatch, repo):assert json.loads(result.output)["error"] == "no index yet"-def test_risk_projection_keeps_the_reviewers_nothing_else_names():- """``pr_blast_radius`` is the only carrier of ``recommended_reviewers``,- and the tool has already capped its noisy lists before the CLI sees it."""+def test_risk_projection_keeps_the_reviewers_and_the_blast_block():+ """The directive carries the reviewers; the capped blast block rides whole."""out = project_risk(PR_RISK_PAYLOAD)- assert out["pr_blast_radius"]["recommended_reviewers"] == [+ assert out["directive"]["recommended_reviewers"] == [{"name": "Raghav Chamadiya", "commits": 40}]+ assert out["pr_blast_radius"] == PR_RISK_PAYLOAD["pr_blast_radius"]def test_risk_table_renders_the_health_and_coverage_it_keeps(monkeypatch, repo):diff --git a/tests/unit/server/mcp/test_mcp_exclude_filter.py b/tests/unit/server/mcp/test_mcp_exclude_filter.pyindex 554a452e2..059d05771 100644--- a/tests/unit/server/mcp/test_mcp_exclude_filter.py+++ b/tests/unit/server/mcp/test_mcp_exclude_filter.py@@ -209,7 +209,7 @@ async def test_risk_raw_pr_blast_radius_excludes_filtered(setup_mcp, tmp_path, mfrom repowise.server.mcp_server import get_riskargs = (["src/auth/service.py"],)- kwargs = {"changed_files": ["src/auth/service.py"]}+ kwargs = {"changed_files": ["src/auth/service.py"], "include": ["blast"]}# Baseline (no exclude config) — confirm the path is present, so the test# below is not vacuous.diff --git a/tests/unit/server/mcp/test_pr_test_impact_semantics.py b/tests/unit/server/mcp/test_pr_test_impact_semantics.pyindex 21b0eedc7..7df56a286 100644--- a/tests/unit/server/mcp/test_pr_test_impact_semantics.py+++ b/tests/unit/server/mcp/test_pr_test_impact_semantics.py@@ -89,7 +89,7 @@ async def test_sealed_pr_payload_is_directive_first_typed_and_count_exact(setup_await session.flush()payload = await get_risk(- ["src/measured.py"], changed_files=changed, include=["graph", "tests"]+ ["src/measured.py"], changed_files=changed, include=["graph", "tests", "blast"])external = json.loads(json.dumps(payload))directive = external["directive"]diff --git a/tests/unit/server/mcp/test_recoverable_caps_wire_contracts.py b/tests/unit/server/mcp/test_recoverable_caps_wire_contracts.pyindex d4b3c5dc4..d3010e3c2 100644--- a/tests/unit/server/mcp/test_recoverable_caps_wire_contracts.py+++ b/tests/unit/server/mcp/test_recoverable_caps_wire_contracts.py@@ -402,7 +402,7 @@ async def test_risk_real_adversarial_wire_recovers_each_directive_lane(monkeypatch.setattr(PRBlastRadiusAnalyzer, "analyze_files", sealed_analyze)changed = [f"src/gap_{i}.py" for i in range(6)]result = await tool_middleware(get_risk)(- ["src/auth/service.py"], changed_files=changed, include=["tests"]+ ["src/auth/service.py"], changed_files=changed, include=["tests", "blast"])_assert_wire(result, "directive", EXPANDED_RESPONSE_CHARS)@@ -422,10 +422,9 @@ async def test_risk_real_adversarial_wire_recovers_each_directive_lane(assert directive[f"{key}_emitted"] < totalassert directive[f"{key}_reduced_reason"].startswith("construction_cap")assert result["truncated"] is True+ # The blast block sheds first, so the directive lists keep their cap.assert "pr_blast_radius" not in result- assert directive["test_recommendations_reduced_reason"] == (- "construction_cap_and_response_budget"- )+ assert directive["test_recommendations_reduced_reason"] == "construction_cap"assert directive["test_recommendations_omitted"] == (directive["test_recommendations_total"]- directive["test_recommendations_emitted"]diff --git a/tests/unit/server/mcp/test_requested_projection_priority.py b/tests/unit/server/mcp/test_requested_projection_priority.pyindex 28be4607b..d502d556b 100644--- a/tests/unit/server/mcp/test_requested_projection_priority.py+++ b/tests/unit/server/mcp/test_requested_projection_priority.py@@ -173,6 +173,46 @@ def test_risk_targets_are_not_trimmed_ahead_of_pr_blocks() -> None:assert "targets" in requested+def _risk_signature() -> inspect.Signature:+ def get_risk(+ targets: list[str] | None = None,+ repo: str | None = None,+ changed_files: list[str] | None = None,+ include: list[str] | None = None,+ ): ...++ return inspect.signature(get_risk)+++def test_pr_mode_sheds_the_blast_block_before_changed_file_cards() -> None:+ """The blast dossier repeats the directive; the cards are the change itself."""+ requested = _requested_shed_keys(+ _CONTRACTS["get_risk"], _risk_signature(), (), {"changed_files": ["a.py"]}+ )+ order = _prioritised_shed_order(_CONTRACTS["get_risk"].shed_order, requested)+ assert order.index("pr_blast_radius") < order.index("targets[]")++ cards = {f"src/m{i}.py": {"risk_summary": "c" * 1500} for i in range(25)}+ cards["CHANGES.rst"] = {"risk_summary": "d" * 1500}+ result = enforce_response_budget(+ "get_risk",+ {+ "directive": {"may_break": ["src/x.py"]},+ "targets": cards,+ "pr_blast_radius": {"transitive_affected": ["e" * 400] * 20},+ "_meta": {},+ },+ signature=_risk_signature(),+ args=(),+ kwargs={"changed_files": list(cards), "include": ["blast"]},+ repo_root=None,+ )+ assert "pr_blast_radius" not in result+ kept = list(result["targets"])+ assert "src/m0.py" in kept+ assert "CHANGES.rst" not in kept++def test_a_trimmed_then_dropped_block_reports_the_whole_population() -> None:"""outline.sections[] trims, then outline is dropped: totals must survive."""payload = _overview_payload()diff --git a/tests/unit/server/mcp/test_risk.py b/tests/unit/server/mcp/test_risk.pyindex 3be034120..806a24572 100644--- a/tests/unit/server/mcp/test_risk.py+++ b/tests/unit/server/mcp/test_risk.py@@ -765,7 +765,9 @@ async def test_get_risk_gates_the_fields_an_agent_cannot_act_on(setup_mcp):"""graph and churn blocks ship only when include asks for them."""from repowise.server.mcp_server import get_risk- default = await get_risk(["src/auth/service.py"], changed_files=["src/auth/service.py"])+ default = await get_risk(+ ["src/auth/service.py"], changed_files=["src/auth/service.py"], include=["blast"]+ )card = default["targets"]["src/auth/service.py"]for key in ("impact_surface", "change_magnitude", "risk_type", "change_pattern"):assert key not in card@@ -775,7 +777,9 @@ async def test_get_risk_gates_the_fields_an_agent_cannot_act_on(setup_mcp):assert key in cardgraph = await get_risk(- ["src/auth/service.py"], changed_files=["src/auth/service.py"], include=["graph"]+ ["src/auth/service.py"],+ changed_files=["src/auth/service.py"],+ include=["graph", "blast"],)assert "impact_surface" in graph["targets"]["src/auth/service.py"]assert "direct_risks" in graph["pr_blast_radius"]@@ -794,7 +798,11 @@ async def test_get_risk_names_an_unknown_include_rather_than_applying_it(setup_mresult = await get_risk(["src/auth/service.py"], include=["graph", "nonsense"])assert "impact_surface" in result["targets"]["src/auth/service.py"]assert result["ignored_arguments"] == [- {"argument": "include", "values": ["nonsense"], "valid": ["churn", "graph", "scales", "tests"]}+ {+ "argument": "include",+ "values": ["nonsense"],+ "valid": ["blast", "churn", "graph", "scales", "tests"],+ }]@@ -803,7 +811,9 @@ async def test_get_risk_directive_does_not_copy_the_analyzer_score(setup_mcp):"""The structural heuristic lives in blast detail, not the directive."""from repowise.server.mcp_server import get_risk- result = await get_risk(["src/auth/service.py"], changed_files=["src/auth/service.py"])+ result = await get_risk(+ ["src/auth/service.py"], changed_files=["src/auth/service.py"], include=["blast"]+ )assert "overall_risk_score" not in result["directive"]blast = result["pr_blast_radius"]@@ -822,7 +832,7 @@ async def test_get_risk_directive_does_not_copy_the_analyzer_score(setup_mcp):assert "risk_scales" not in resultexpanded = await get_risk(- ["src/auth/service.py"], changed_files=["src/auth/service.py"], include=["scales"]+ ["src/auth/service.py"], changed_files=["src/auth/service.py"], include=["scales", "blast"])assert expanded["risk_scales"][0]["field"] == "targets.*.hotspot_score"assert expanded["pr_blast_radius"]["structural_impact_scale"]["component_fields"]@@ -855,7 +865,7 @@ async def test_get_risk_directive_points_at_the_full_run_list_when_capped(setup_await session.flush()result = await get_risk(- ["src/auth/service.py"], changed_files=["src/auth/service.py"], include=["tests"]+ ["src/auth/service.py"], changed_files=["src/auth/service.py"], include=["tests", "blast"])directive = result["directive"]@@ -1045,3 +1055,30 @@ async def test_security_signals_are_ranked_high_first(setup_mcp, session):signals = await _get_security_signals(session, "repo1", "src/auth/service.py")assert [s["severity"] for s in signals] == ["high", "med", "low"]+++async def test_get_risk_serves_the_blast_radius_on_request(setup_mcp):+ from repowise.server.mcp_server import get_risk++ files = ["src/auth/service.py"]+ plain = await get_risk(files, changed_files=files)+ assert "pr_blast_radius" not in plain+ assert isinstance(plain["directive"]["recommended_reviewers"], list)++ blast = await get_risk(files, changed_files=files, include=["blast"])+ assert "structural_impact_score" in blast["pr_blast_radius"]+ # Named once, in the directive.+ reviewers = plain["directive"]["recommended_reviewers"]+ assert blast["directive"]["recommended_reviewers"] == reviewers+ assert not [k for k in blast["pr_blast_radius"] if k.startswith("recommended_reviewers")]+++async def test_get_risk_pr_mode_puts_docs_and_config_cards_last(setup_mcp):+ """The budget sheds cards from the tail, so a code card must not sit there."""+ from repowise.server.mcp_server import get_risk++ files = ["CHANGES.rst", "setup.cfg", "src/auth/service.py"]+ result = await get_risk(files, changed_files=files)+ assert next(iter(result["targets"])) == "src/auth/service.py"diff --git a/tests/unit/server/mcp/test_risk_dependency_edges.py b/tests/unit/server/mcp/test_risk_dependency_edges.pyindex dce9ab268..1d5c7b272 100644--- a/tests/unit/server/mcp/test_risk_dependency_edges.py+++ b/tests/unit/server/mcp/test_risk_dependency_edges.py@@ -94,7 +94,7 @@ async def test_pr_relationship_rows_are_typed_and_totals_match(setup_mcp, factorfrom repowise.server.mcp_server import get_riskawait _add_doc_co_change(factory, setup_mcp)- result = await get_risk([_TARGET], changed_files=[_TARGET])+ result = await get_risk([_TARGET], changed_files=[_TARGET], include=["blast"])blast = result["pr_blast_radius"]assert blast["transitive_affected_total"] >= len(blast["transitive_affected"])diff --git a/tests/unit/server/mcp/test_risk_relationship_semantics.py b/tests/unit/server/mcp/test_risk_relationship_semantics.pyindex 062214ffa..8e1424932 100644--- a/tests/unit/server/mcp/test_risk_relationship_semantics.py+++ b/tests/unit/server/mcp/test_risk_relationship_semantics.py@@ -99,7 +99,9 @@ async def relationship_payload(setup_mcp, factory, tmp_path):try:yield {"normal": await get_risk([target], repo="alpha", include=["graph"]),- "pr": await get_risk([target], repo="alpha", changed_files=[target], include=["graph"]),+ "pr": await get_risk(+ [target], repo="alpha", changed_files=[target], include=["graph", "blast"]+ ),}finally:_state._registry, _state._cross_repo_enricher = previous