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(fix-first): drop the helper name from a title when the plan has none (#3529)

Raghav Chamadiya71c2ccc94f61
diff --git a/packages/core/src/repowise/core/analysis/health/fix_first/build.py b/packages/core/src/repowise/core/analysis/health/fix_first/build.py
index e162fd716..61b7d4faa 100644
--- a/packages/core/src/repowise/core/analysis/health/fix_first/build.py
+++ b/packages/core/src/repowise/core/analysis/health/fix_first/build.py
@@ -93,7 +93,6 @@ from repowise.core.analysis.health.queue.value import (
worth,
)
from repowise.core.analysis.health.refactoring.recipe import ELSEWHERE_NOTE, plan_anchors
-from repowise.core.analysis.health.refactoring.render import NAME_PLACEHOLDER
from repowise.core.analysis.health.rows import detail_map, field, json_field
from repowise.core.analysis.health.scoring import biomarker_dimension
from repowise.core.analysis.health.suggestions import suggestion_for
@@ -1024,13 +1023,20 @@ def _refactor_title(plan: _RefactorPlan, lead_plan: Any) -> str:
def _span_title(plan: _RefactorPlan, lead_plan: Any) -> str:
start, end = _span(lead_plan)
- name = _plan_body(lead_plan).get("suggested_name") or NAME_PLACEHOLDER
+ # With no suggested name the title drops "into ...": the step already says
+ # to name the helper for what the lines do, and a title never reads "<name>".
+ name = _plan_body(lead_plan).get("suggested_name") or ""
spanned = plan.lead_type == "extract_method" and bool(start and end)
if spanned and magnitude(plan.rank.shape) >= SIZE_BREAK_UP:
return _break_up_title(plan, f"{start}-{end}", name)
- title = text.REFACTOR_TITLE.get(
+ template = text.REFACTOR_TITLE.get(
"extract_method_span" if spanned else plan.lead_type, "Refactor {file}"
- ).format(sym=plan.sym, file=text.basename(plan.path), start=start, end=end, name=name)
+ )
+ if not name:
+ template = template.replace(" into {name}", "")
+ title = template.format(
+ sym=plan.sym, file=text.basename(plan.path), start=start, end=end, name=name
+ )
return _with_more_steps(plan, title)
@@ -1047,7 +1053,7 @@ def _break_up_title(plan: _RefactorPlan, span: str, name: str) -> str:
f"Start breaking up {plan.sym} ({text.size_brief(plan.rank.shape)}): "
f"first lift lines {span}"
)
- into = f" into {name}"
+ into = f" into {name}" if name else ""
return title + into if len(title + into) <= text.TITLE_MAX else title
diff --git a/tests/unit/health/test_fix_first_build.py b/tests/unit/health/test_fix_first_build.py
index 7516401aa..efb3499d6 100644
--- a/tests/unit/health/test_fix_first_build.py
+++ b/tests/unit/health/test_fix_first_build.py
@@ -346,17 +346,18 @@ def test_an_extract_method_step_carries_the_helper_header_and_call() -> None:
assert lone.action.steps[0].signature == "def _sum_rows(rows, limit):"
-def test_an_unnamed_helper_reads_as_the_placeholder_in_titles() -> None:
+def test_an_unnamed_helper_is_left_out_of_titles() -> None:
+ """A title never reads "<name>": the step already says to name the helper."""
plans = copy.deepcopy(PLANS)
del plans[0]["plan"]["suggested_name"]
core = next(i for i in _build(plans=plans).items if i.kind == "refactor")
- assert core.title == "Start breaking up run (CCN 44, 50 lines): first lift lines 20-35 into <name>"
+ assert core.title == "Start breaking up run (CCN 44, 50 lines): first lift lines 20-35"
small = [{**FINDINGS[1], "details": {"ccn": 12, "nloc": 50}}]
row = copy.deepcopy(REFACTORING[0])
row["details"]["steps"] = row["details"]["steps"][:1]
core = next(i for i in _build(plans=plans, findings=small, refactoring=[row]).items
if i.kind == "refactor")
- assert core.title == "Extract lines 20-35 of run into <name>"
+ assert core.title == "Extract lines 20-35 of run"
def test_an_item_no_test_reaches_says_to_pin_its_behaviour_first() -> None: