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): trim get_risk card responses and move detailed owner metrics behind owners include (#3139)

Rishabh Mishrae7d068eaef3d
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index e43ec7692..921a9a1f6 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -39,6 +39,8 @@ Agents get leaner, more useful MCP responses, module wiki pages are written from
### Changed
+- **`get_risk` card responses are leaner** (#3112). `co_change_partners` rows keep only `file_path`, `support`, `conf_ab` and `has_import_link`. Detailed owner metrics (`owner_pct`, `owner_line_pct`, `recent_owner`, `recent_owner_pct`, `bus_factor`, `contributor_count`) move behind `include=["owners"]`, saving ~1.2 KB per target card. `primary_owner` and the owner clause in `risk_summary` stay unconditional.
+
- **Call resolution is more precise for Go, Rust, Python, TypeScript, Java, C#, C++ and Objective-C** (#2766, #2767, #2777, #2778, #2800, #2773, #2772, #2775, #2779, #2768, #2827, #2833, #2776, #2770, #2837). Go calls are typed through struct fields, `:=` locals and range variables, and a chain on an external return type is no longer bound to a same-named repository function. Rust receivers are typed from parameters, `let` annotations and constructors. Python `super()` walks the MRO. A parameter or local that shadows a name no longer resolves to the module-level symbol, and a member call is resolved by its receiver first. Against compiler or SCIP oracles, precision moved on gitleaks from 0.9755 to 0.9908, on cobra from 0.9724 to 0.9944, on httpx from 0.9696 to 0.9831 and on click from 0.9358 to 0.9572.
- **Java, C# and C++ overloads each get their own symbol** (#2811, #2829). Overloads of different arity, and a C# generic type beside its non-generic sibling, are separate graph nodes, so a call draws an edge to the overload it names.
- **TypeScript object-literal methods and C/C++ functions returning pointers or references are symbols** (#2772, #2774). Methods in mixin and builder objects get ids such as `ZodNumber::gt`, which on zod moved recall from 0.7762 to 0.7959.
diff --git a/docs/agent/MCP_TOOLS.md b/docs/agent/MCP_TOOLS.md
index 3b7aeb519..1a140428d 100644
--- a/docs/agent/MCP_TOOLS.md
+++ b/docs/agent/MCP_TOOLS.md
@@ -240,10 +240,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), `blast` (`pr_blast_radius` in PR mode), `scales` (units and calibration, identical per call) |
+| `include` | list[string] | none | `graph` (typed dependents, consumers, cross-repo links), `churn`, `owners` (owner percentages, bus factor, contributor count), `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`, `recommended_reviewers`, `next_calls`, and `reach` (`localized`, `moderate` or `broad`; `null` when no structural score was computed). `include=["blast"]` adds `pr_blast_radius`; the raw 0 to 10 `structural_impact_score` and its scale appear there only with `include=["blast", "scales"]`. `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` (`file_path`, `support`, `conf_ab`, `has_import_link`), `primary_owner` (detailed owner metrics are opt-in under `include=["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`, `next_calls`, and `reach` (`localized`, `moderate` or `broad`; `null` when no structural score was computed). `include=["blast"]` adds `pr_blast_radius`; the raw 0 to 10 `structural_impact_score` and its scale appear there only with `include=["blast", "scales"]`. `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. `reach` bands an uncalibrated heuristic that never sees the diff; it is not a probability.
diff --git a/docs/reference/MCP_RESPONSE_FIELDS.md b/docs/reference/MCP_RESPONSE_FIELDS.md
index 7094955ef..f4595592d 100644
--- a/docs/reference/MCP_RESPONSE_FIELDS.md
+++ b/docs/reference/MCP_RESPONSE_FIELDS.md
@@ -210,12 +210,12 @@ Per file:
| `hotspot_score` | 0 to 1 churn percentile |
| `health_score` | 0 to 10 |
| `dependents_count` | Direct directed structural dependents; a floor over the indexed graph |
-| `co_change_partners` | Historical correlation only. Each has a recency-decayed `weight`, a `direction` (`a_to_b`, `b_to_a` or `undirected`, where `a` is the assessed file), and `conf_ab` / `conf_ba`, the share of each file's commits that touched the other |
-| owners, reviewers | Primary and recent owners (`owner_pct`, `recent_owner_pct` are 0 to 1) and recommended reviewers |
+| `co_change_partners` | Historical correlation only. Each row carries `file_path`, `support` (count of shared commits, when known), `conf_ab` (share of target file's commits that touched partner, when known), and `has_import_link`. Sorted by recency-decayed weight |
+| owners, reviewers | Primary owner (`primary_owner`) and the owner clause in `risk_summary` are unconditional; detailed owner metrics (`owner_pct`, `owner_line_pct`, `recent_owner`, `recent_owner_pct`, `bus_factor`, `contributor_count`) are opt-in under `include=["owners"]`; recommended reviewers stay in PR mode |
| 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`, 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`.
+Opt-in blocks: `owners` adds `owner_pct`, `owner_line_pct`, `recent_owner`, `recent_owner_pct`, `bus_factor` and `contributor_count`. `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`:
diff --git a/packages/claude-mod/src/model/replies.ts b/packages/claude-mod/src/model/replies.ts
index 2af40f43c..9906200e6 100644
--- a/packages/claude-mod/src/model/replies.ts
+++ b/packages/claude-mod/src/model/replies.ts
@@ -107,7 +107,6 @@ function riskFacts(r: Rec): ReplyFact[] {
...fact("targets", targets.length),
...fact("dependents", sumOver(targets, (t) => num(t["dependents_count"]))),
...fact("coChange", sumOver(targets, (t) => num(t["co_change_partners_total"]) ?? count(t["co_change_partners"]))),
- ...fact("contributors", sumOver(targets, (t) => num(t["contributor_count"]))),
...fact("hotspots", flagged(targets, "is_hotspot") || null),
];
}
diff --git a/packages/claude-mod/test/flow.test.ts b/packages/claude-mod/test/flow.test.ts
index 60c714db8..3b2954679 100644
--- a/packages/claude-mod/test/flow.test.ts
+++ b/packages/claude-mod/test/flow.test.ts
@@ -58,13 +58,12 @@ describe("reply summaries over recorded replies", () => {
expect(s.error).toBeNull();
});
- it("get_risk: dependents, co-change partners, contributors; capped and tokens left out", () => {
+ it("get_risk: dependents, co-change partners; capped and tokens left out", () => {
const s = summarizeReply("get_risk", reply("get_risk"));
expect(s.inside).toEqual([
{ what: "targets", n: 1 },
{ what: "dependents", n: 12 },
{ what: "coChange", n: 25 },
- { what: "contributors", n: 172 },
{ what: "hotspots", n: 1 },
]);
expect(s.behind).toMatchObject({ complete: false, omittedTokens: 1849 });
diff --git a/packages/cli/src/repowise/cli/commands/risk_cmd.py b/packages/cli/src/repowise/cli/commands/risk_cmd.py
index ea95ed82b..2859629f2 100644
--- a/packages/cli/src/repowise/cli/commands/risk_cmd.py
+++ b/packages/cli/src/repowise/cli/commands/risk_cmd.py
@@ -140,9 +140,10 @@ 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; --format
- # json keeps the PR blast radius the tool serves only on request.
- include=["churn", "blast"],
+ # _render_target_risk prints risk_type, change_magnitude, owner share,
+ # bus factor, contributor count, and recent owner; --format json keeps
+ # the PR blast radius the tool serves only on request.
+ include=["churn", "owners", "blast"],
)
payload = _ta.run(repo, _factory, "get_risk")
@@ -333,12 +334,10 @@ def _render_card(name: str, card: dict) -> None:
console.print(" [bold]Co-changes with[/bold]")
for p in partners[:8]:
link = " [dim](also imports)[/dim]" if p.get("has_import_link") else ""
- # A recency-decayed weight rather than a raw tally, so it is not an
- # integer; ``:g`` keeps a whole number whole and trims the rest.
- weight = p.get("weight", 0)
- weight_text = f"{float(weight):.1f}".rstrip("0").rstrip(".") if weight else "0"
+ support = p.get("support")
+ support_text = f" [dim]x{support}[/dim]" if support is not None else ""
console.print(
- f" {escape(str(p.get('file_path', '')))} [dim]x{weight_text}[/dim]{link}"
+ f" {escape(str(p.get('file_path', '')))}{support_text}{link}"
)
if len(partners) > 8:
console.print(f" [dim]… and {len(partners) - 8} more (--format json).[/dim]")
diff --git a/packages/core/src/repowise/core/upgrade/_data/CHANGELOG.md b/packages/core/src/repowise/core/upgrade/_data/CHANGELOG.md
index e43ec7692..921a9a1f6 100644
--- a/packages/core/src/repowise/core/upgrade/_data/CHANGELOG.md
+++ b/packages/core/src/repowise/core/upgrade/_data/CHANGELOG.md
@@ -39,6 +39,8 @@ Agents get leaner, more useful MCP responses, module wiki pages are written from
### Changed
+- **`get_risk` card responses are leaner** (#3112). `co_change_partners` rows keep only `file_path`, `support`, `conf_ab` and `has_import_link`. Detailed owner metrics (`owner_pct`, `owner_line_pct`, `recent_owner`, `recent_owner_pct`, `bus_factor`, `contributor_count`) move behind `include=["owners"]`, saving ~1.2 KB per target card. `primary_owner` and the owner clause in `risk_summary` stay unconditional.
+
- **Call resolution is more precise for Go, Rust, Python, TypeScript, Java, C#, C++ and Objective-C** (#2766, #2767, #2777, #2778, #2800, #2773, #2772, #2775, #2779, #2768, #2827, #2833, #2776, #2770, #2837). Go calls are typed through struct fields, `:=` locals and range variables, and a chain on an external return type is no longer bound to a same-named repository function. Rust receivers are typed from parameters, `let` annotations and constructors. Python `super()` walks the MRO. A parameter or local that shadows a name no longer resolves to the module-level symbol, and a member call is resolved by its receiver first. Against compiler or SCIP oracles, precision moved on gitleaks from 0.9755 to 0.9908, on cobra from 0.9724 to 0.9944, on httpx from 0.9696 to 0.9831 and on click from 0.9358 to 0.9572.
- **Java, C# and C++ overloads each get their own symbol** (#2811, #2829). Overloads of different arity, and a C# generic type beside its non-generic sibling, are separate graph nodes, so a call draws an edge to the overload it names.
- **TypeScript object-literal methods and C/C++ functions returning pointers or references are symbols** (#2772, #2774). Methods in mixin and builder objects get ids such as `ZodNumber::gt`, which on zod moved recall from 0.7762 to 0.7959.
diff --git a/packages/server/src/repowise/server/mcp_server/tool_risk/assessment.py b/packages/server/src/repowise/server/mcp_server/tool_risk/assessment.py
index 3b4da5635..c15dd91fe 100644
--- a/packages/server/src/repowise/server/mcp_server/tool_risk/assessment.py
+++ b/packages/server/src/repowise/server/mcp_server/tool_risk/assessment.py
@@ -310,19 +310,6 @@ async def _get_security_signals(session: AsyncSession, repo_id: str, target: str
return []
-def _co_change_direction(conf_ab: float | None, conf_ba: float | None) -> str:
- """Which side of a pair leads, where ``a`` is the target and ``b`` the partner.
-
- A higher ``conf_ab`` means the target seldom changes without the partner, so
- the target is the antecedent. Equal confidences, or an index written before
- the two commit totals were recorded, stay ``undirected`` rather than having
- a lead broken arbitrarily.
- """
- if conf_ab is None or conf_ba is None or conf_ab == conf_ba:
- return "undirected"
- return "a_to_b" if conf_ab > conf_ba else "b_to_a"
-
-
def _build_co_changes(
meta: Any, structural_related: Any, exclude_spec: Any
) -> tuple[list[dict], int]:
@@ -331,12 +318,9 @@ def _build_co_changes(
Larger lists make MCP responses verbose without adding signal: top-5 captures
the bulk of the temporal-coupling mass and keeps tool output tight for agents.
- The strength field is emitted as ``weight``, not ``count``: the stored value
- is a recency-decayed sum (``exp(-age_days / tau)`` per shared commit), so it
- is fractional. Named ``count`` it read as "5.52 co-changes" to every agent.
-
- ``conf_ab`` and ``conf_ba`` are the two directional confidences behind
- ``direction``, omitted when the commit totals are unknown.
+ Row order stays by recency-decayed ``weight``. Each row carries ``file_path``,
+ ``support`` (shared commit count, when known), ``conf_ab`` (share of target's
+ commits that touched partner, when known), and ``has_import_link``.
"""
partners_sorted = parse_partners(meta.co_change_partners_json)
relation_types = structural_related if isinstance(structural_related, dict) else {}
@@ -346,28 +330,14 @@ def _build_co_changes(
path = partner.file_path
types = sorted(relation_types.get(path, ()))
conf_ab = confidence_ratio(partner.support, partner.self_commits)
- conf_ba = confidence_ratio(partner.support, partner.partner_commits)
- row = {
+ row: dict[str, Any] = {
"file_path": path,
- "weight": partner.weight,
- "last_co_change": partner.last_co_change,
- "relationship_type": "co_change",
- "direction": _co_change_direction(conf_ab, conf_ba),
- "evidence_kind": "historical",
- "provenance": "git_history",
- "has_structural_link": path in related_paths,
- # Compatibility field: unlike the broader structural flag, this is
- # true only for an actual imports edge.
"has_import_link": "imports" in types if types else path in related_paths,
}
- if types:
- row["structural_relationship_types"] = types
if partner.support:
row["support"] = partner.support
if conf_ab is not None:
row["conf_ab"] = conf_ab
- if conf_ba is not None:
- row["conf_ba"] = conf_ba
rows.append(row)
population = filter_dicts_by_key(rows, "file_path", exclude_spec)
return population, len(population)
diff --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.py
index 3a2bf03d6..e6aa384e9 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
@@ -79,6 +79,14 @@ _TARGET_CARD_INCLUDES: dict[str, tuple[str, ...]] = {
"relationship_analysis",
),
"churn": ("change_magnitude", "risk_type", "change_pattern"),
+ "owners": (
+ "owner_pct",
+ "owner_line_pct",
+ "recent_owner",
+ "recent_owner_pct",
+ "bus_factor",
+ "contributor_count",
+ ),
}
_BLAST_INCLUDES: dict[str, tuple[str, ...]] = {"graph": ("direct_risks",)}
#: Per-field units and calibration. Identical on every call, so it is opt-in.
@@ -402,7 +410,7 @@ async def get_risk(
targets: file paths to assess; defaults to changed_files.
repo: usually omitted.
changed_files: PR-changed files for blast-radius mode.
- include: opt-in blocks - "graph", "churn", "tests" (typed test
+ include: opt-in blocks - "graph", "churn", "owners", "tests" (typed test
rows), "blast", "scales" (units and calibration).
"""
if repo == "all":
diff --git a/plugins/claude-code/hooks/lens/lens.js b/plugins/claude-code/hooks/lens/lens.js
index 71c3bf894..7378b9021 100644
--- a/plugins/claude-code/hooks/lens/lens.js
+++ b/plugins/claude-code/hooks/lens/lens.js
@@ -1444,7 +1444,6 @@ function riskFacts(r) {
...fact("targets", targets.length),
...fact("dependents", sumOver(targets, (t) => num(t["dependents_count"]))),
...fact("coChange", sumOver(targets, (t) => num(t["co_change_partners_total"]) ?? count2(t["co_change_partners"]))),
- ...fact("contributors", sumOver(targets, (t) => num(t["contributor_count"]))),
...fact("hotspots", flagged(targets, "is_hotspot") || null)
];
}
diff --git a/plugins/claude-code/skills/pre-modification/SKILL.md b/plugins/claude-code/skills/pre-modification/SKILL.md
index a082ff7ac..86ff0e9aa 100644
--- a/plugins/claude-code/skills/pre-modification/SKILL.md
+++ b/plugins/claude-code/skills/pre-modification/SKILL.md
@@ -16,7 +16,7 @@ Before modifying files in a Repowise-indexed codebase, assess the impact.
Call `get_risk(targets=["path/to/file.py"])`. Per file it returns
`hotspot_score`, `trend`, `risk_type`, `impact_surface` (top 3),
-`dependents_count`, `co_change_partners`, `primary_owner`, `bus_factor`,
+`dependents_count`, `co_change_partners`, `primary_owner`,
`test_gap`, and `security_signals`. Read it for:
- **Bug-fix history** (`defect_profile`) — present only on files with counted
fixes: `fix_count` over the trailing 6 months, `last_fix_days_ago`, a
diff --git a/plugins/codex/skills/pre-modification-check/SKILL.md b/plugins/codex/skills/pre-modification-check/SKILL.md
index 5360ce67a..044076555 100644
--- a/plugins/codex/skills/pre-modification-check/SKILL.md
+++ b/plugins/codex/skills/pre-modification-check/SKILL.md
@@ -11,7 +11,7 @@ Before modifying files in a Repowise-indexed codebase, assess the impact.
Call `get_risk(targets=["path/to/file.py"])`. Per file it returns
`hotspot_score`, `trend`, `risk_type`, `impact_surface` (top 3),
-`dependents_count`, `co_change_partners`, `primary_owner`, `bus_factor`,
+`dependents_count`, `co_change_partners`, `primary_owner`,
`test_gap`, and `security_signals`. Read it for:
- **Bug-fix history** (`defect_profile`) — present only on files with counted
fixes: `fix_count` over the trailing 6 months, `last_fix_days_ago`, a
diff --git a/plugins/shared/skills/pre-modification.md b/plugins/shared/skills/pre-modification.md
index f61bed981..bb1035c3c 100644
--- a/plugins/shared/skills/pre-modification.md
+++ b/plugins/shared/skills/pre-modification.md
@@ -24,7 +24,7 @@ Before modifying files in a Repowise-indexed codebase, assess the impact.
Call `get_risk(targets=["path/to/file.py"])`. Per file it returns
`hotspot_score`, `trend`, `risk_type`, `impact_surface` (top 3),
-`dependents_count`, `co_change_partners`, `primary_owner`, `bus_factor`,
+`dependents_count`, `co_change_partners`, `primary_owner`,
`test_gap`, and `security_signals`. Read it for:
- **Bug-fix history** (`defect_profile`) — present only on files with counted
fixes: `fix_count` over the trailing 6 months, `last_fix_days_ago`, a
diff --git a/tests/fixtures/mcp/tool_response_shapes.json b/tests/fixtures/mcp/tool_response_shapes.json
index 254bde686..25a21e86e 100644
--- a/tests/fixtures/mcp/tool_response_shapes.json
+++ b/tests/fixtures/mcp/tool_response_shapes.json
@@ -1612,22 +1612,12 @@
},
"targets": {
"packages/core/src/repowise/core/ingestion/call_resolver.py": {
- "bus_factor": null,
"co_change_partners": [
{
- "direction": null,
- "evidence_kind": null,
+ "conf_ab": null,
"file_path": null,
"has_import_link": null,
- "has_structural_link": null,
- "last_co_change": null,
- "provenance": null,
- "relationship_type": null,
- "structural_relationship_types": [
- null
- ],
- "support": null,
- "weight": null
+ "support": null
}
],
"co_change_partners_emitted": null,
@@ -1636,7 +1626,6 @@
"co_change_partners_total": null,
"co_change_partners_truncated": null,
"commit_count_capped": null,
- "contributor_count": null,
"defect_profile": {
"bug_magnet": null,
"fix_count": null,
@@ -1654,10 +1643,7 @@
"hotspot_score": null,
"is_hotspot": null,
"line_coverage_pct": null,
- "owner_pct": null,
"primary_owner": null,
- "recent_owner": null,
- "recent_owner_pct": null,
"risk_summary": null,
"security_signals": [],
"target": null,
diff --git a/tests/unit/server/mcp/test_risk.py b/tests/unit/server/mcp/test_risk.py
index f3873f814..c44cd27b9 100644
--- a/tests/unit/server/mcp/test_risk.py
+++ b/tests/unit/server/mcp/test_risk.py
@@ -24,10 +24,14 @@ async def test_get_risk_single_target(setup_mcp):
assert t["dependents_count"] >= 1 # middleware imports it
assert len(t["co_change_partners"]) == 2
assert t["primary_owner"] == "Alice"
- assert t["owner_pct"] == 0.65
+ assert "owner_pct" not in t # detailed owner metrics require include=["owners"]
assert "risk_summary" in t
assert "hotspot score" in t["risk_summary"]
+ # include=["owners"] opt-in adds owner_pct
+ owners_result = await get_risk(["src/auth/service.py"], include=["owners"])
+ assert owners_result["targets"]["src/auth/service.py"]["owner_pct"] == 0.65
+
# Trend: 30d=3, 90d=8 → baseline_rate=0.083, recent=0.1 → stable
assert t["trend"] in ("increasing", "stable", "decreasing")
@@ -817,7 +821,7 @@ async def test_get_risk_names_an_unknown_include_rather_than_applying_it(setup_m
{
"argument": "include",
"values": ["nonsense"],
- "valid": ["blast", "churn", "graph", "scales", "tests"],
+ "valid": ["blast", "churn", "graph", "owners", "scales", "tests"],
}
]
@@ -986,55 +990,27 @@ def _co_change_row(**partner):
return rows[0]
-def test_co_change_direction_target_leads():
- """The target seldom moves without the partner, so it is the antecedent."""
+def test_co_change_confidence_calculated():
+ """``conf_ab`` is the share of the target's commits that also touched partner."""
row = _co_change_row(count=2.0, frequency=8, self_commits=10, partner_commits=20)
- assert row["direction"] == "a_to_b"
assert row["conf_ab"] == 0.8
- assert row["conf_ba"] == 0.4
-
-
-def test_co_change_direction_partner_leads():
- """The mirror case: the partner is the side that cannot move alone."""
- row = _co_change_row(count=2.0, frequency=8, self_commits=20, partner_commits=10)
-
- assert row["direction"] == "b_to_a"
- assert row["conf_ab"] == 0.4
- assert row["conf_ba"] == 0.8
-
-
-def test_co_change_direction_tie_is_undirected():
- """Equal confidences report a tie rather than breaking the lead arbitrarily."""
- row = _co_change_row(count=2.0, frequency=5, self_commits=10, partner_commits=10)
+ assert row["support"] == 8
+ assert row["has_import_link"] is False
- assert row["direction"] == "undirected"
- assert row["conf_ab"] == 0.5
- assert row["conf_ba"] == 0.5
-
-def test_co_change_direction_without_commit_totals():
- """An index written before the commit totals existed stays undirected.
-
- ``self_commits``/``partner_commits`` are absent from such a record, so there
- is no denominator to divide by; the confidences are omitted rather than
- emitted as a guessed zero.
- """
+def test_co_change_confidence_without_commit_totals():
+ """An index written before commit totals existed omits conf_ab."""
row = _co_change_row(count=2.0, frequency=8)
- assert row["direction"] == "undirected"
assert "conf_ab" not in row
- assert "conf_ba" not in row
+ assert row["support"] == 8
+ assert row["has_import_link"] is False
@pytest.mark.asyncio
-async def test_get_risk_co_change_rows_carry_direction(setup_mcp):
- """The field survives the whole pipeline, and says nothing it cannot back.
-
- The seeded records carry no commit totals, so every row must come back
- ``undirected`` with no confidence beside it -- a guessed ``0.0`` here would
- read as "these files never change together", the opposite of unknown.
- """
+async def test_get_risk_co_change_rows_are_lean(setup_mcp):
+ """The rows carry file_path, support, and has_import_link; conf_ab when known."""
from repowise.server.mcp_server import get_risk
result = await get_risk(["src/auth/service.py"])
@@ -1042,9 +1018,11 @@ async def test_get_risk_co_change_rows_carry_direction(setup_mcp):
assert partners
for p in partners:
- assert p["direction"] == "undirected"
- assert "conf_ab" not in p
- assert "conf_ba" not in p
+ assert "file_path" in p
+ assert "has_import_link" in p
+ assert "direction" not in p
+ assert "weight" not in p
+ assert "relationship_type" not in p
@pytest.mark.asyncio
diff --git a/tests/unit/server/mcp/test_risk_relationship_semantics.py b/tests/unit/server/mcp/test_risk_relationship_semantics.py
index 8e1424932..b6879122b 100644
--- a/tests/unit/server/mcp/test_risk_relationship_semantics.py
+++ b/tests/unit/server/mcp/test_risk_relationship_semantics.py
@@ -170,16 +170,12 @@ async def test_co_change_is_historical_only_and_mixed_evidence_stays_separate(
consumer_paths = {row["consumer_file"] for row in card["consumers"]}
only = partners["docs/cochange-only.md"]
- assert only["relationship_type"] == "co_change"
- assert only["evidence_kind"] == "historical"
- assert only["provenance"] == "git_history"
assert only["support"] == 7
- assert only["has_structural_link"] is False
+ assert only["has_import_link"] is False
assert only["file_path"] not in dependent_paths | consumer_paths
mixed = partners["src/direct_0.py"]
- assert mixed["has_structural_link"] is True
- assert mixed["structural_relationship_types"] == ["imports"]
+ assert mixed["has_import_link"] is True
assert card["co_change_partners_total"] == 6
assert card["co_change_partners_emitted"] == len(card["co_change_partners"]) == 5
assert card["co_change_partners_truncated"] is True