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(health): skip plan generation for test-context performance opportunities (#2964)
Aman73d522326acc
diff --git a/packages/core/src/repowise/core/analysis/health/refactoring/performance_fix.py b/packages/core/src/repowise/core/analysis/health/refactoring/performance_fix.pyindex 5e40cf20d..cfe074933 100644--- a/packages/core/src/repowise/core/analysis/health/refactoring/performance_fix.py+++ b/packages/core/src/repowise/core/analysis/health/refactoring/performance_fix.py@@ -120,6 +120,8 @@ def performance_fix_suggestions(floor = confidence_order.get((min_confidence or "").lower(), 0)out: list[RefactoringSuggestion] = []for opportunity in opportunities:+ if opportunity.execution_context == "test":+ continuefix = opportunity.fixconfidence = "high" if fix and fix.safety == "proven" else "medium"if fix is None or not opportunity.evidence or confidence_order[confidence] < floor:diff --git a/tests/fixtures/perf_corpus/golden_plans.json b/tests/fixtures/perf_corpus/golden_plans.jsonindex e07d322f0..fa844560b 100644--- a/tests/fixtures/perf_corpus/golden_plans.json+++ b/tests/fixtures/perf_corpus/golden_plans.json@@ -1800,90 +1800,6 @@"source_biomarker": "io_in_loop","target_symbol": "src/app/edge.py::run"},- {- "blast_radius": {- "call_sites": 1,- "file_count": 1,- "files": [- "tests/test_job.py"- ]- },- "confidence": "medium",- "evidence": {- "affected_files_total": 1,- "biomarker_type": "io_in_loop",- "biomarker_types": [- "io_in_loop"- ],- "boundary_kind": "db",- "execution_context": "test",- "observations_total": 1,- "provenance": "call-site",- "rank_factors": {- "affected_call_sites": 2,- "boundary_kind": 4,- "entry_reachability": 0,- "execution_context": 1,- "loop_magnitude": 1,- "multiplier_shape": 4,- "provenance": 3- },- "rank_score": 15,- "rationale": "The shared I/O sink is proven; no concrete batch API or result-equivalence proof is available.",- "reliable_entry_reachability": null- },- "file_path": "tests/test_job.py",- "impact_delta": 0.0,- "line_end": 202,- "line_start": 200,- "plan": {- "affected_locations": [- {- "file_path": "tests/test_job.py",- "function_name": "run",- "line_end": 202,- "line_start": 200- }- ],- "affected_locations_total": 1,- "api": null,- "evidence_truncated": false,- "intervention_symbol": "tests/test_job.py::run",- "judgment_steps": 2,- "mechanical_steps": 0,- "opportunity_id": "perf3_91d25fc7b3e4e8ad00c1",- "paths": [- [- "tests/test_job.py::run",- "src/app/db.py::get_session"- ]- ],- "paths_total": 1,- "safety": "advisory",- "steps": [- {- "action": "Add a form of get_session that takes every key at once",- "applicability": "judgment",- "file_path": "src/app/db.py",- "line": null,- "order": 1,- "symbol": "src/app/db.py::get_session"- },- {- "action": "Collect the keys before the loop and call the batched form once",- "applicability": "judgment",- "file_path": "tests/test_job.py",- "line": 200,- "order": 2,- "symbol": "run"- }- ],- "strategy": "batch_or_prefetch_io"- },- "refactoring_type": "performance_fix",- "source_biomarker": "io_in_loop",- "target_symbol": "tests/test_job.py::run"- },{"blast_radius": {"call_sites": 1,diff --git a/tests/unit/health/test_perf_opportunities.py b/tests/unit/health/test_perf_opportunities.pyindex cf1a56185..951c4c51f 100644--- a/tests/unit/health/test_perf_opportunities.py+++ b/tests/unit/health/test_perf_opportunities.py@@ -203,6 +203,92 @@ def test_lock_fix_targets_the_single_lock_owner_not_the_shared_sink():assert plan.target_symbol == "lock.py::critical"+def test_lock_fix_skips_a_test_owned_critical_section():+ """A lock held in a test method names no production I/O to move."""+ T = "server/src/test/java/org/elasticsearch/index/translog/TranslogTests.java"+ P = "server/src/main/java/org/elasticsearch/index/translog/Translog.java"+ rows = [+ _finding(+ T,+ 120,+ marker="blocking_io_under_lock",+ boundary="fs",+ call_path=(+ f"{T}::TranslogTests::testConcurrentWriteViewsAndSnapshot",+ f"{P}::Translog::add",+ f"{P}::Translog::flushBuffer",+ ),+ )+ ]+ link_performance_findings(rows)+ opportunity = build_performance_opportunities(rows)[0]++ assert opportunity.execution_context == "test"+ assert opportunity.fix is not None+ assert performance_fix_suggestions([opportunity]) == []+++def test_lock_fix_still_targets_a_production_owned_critical_section():+ """Same shape, production lock owner: the plan is unaffected by the fix."""+ P = "server/src/main/java/org/elasticsearch/index/translog/Translog.java"+ rows = [+ _finding(+ P,+ 120,+ marker="blocking_io_under_lock",+ boundary="fs",+ call_path=(+ f"{P}::Translog::writeAndFlush",+ f"{P}::Translog::add",+ f"{P}::Translog::flushBuffer",+ ),+ )+ ]+ link_performance_findings(rows)+ opportunity = build_performance_opportunities(rows)[0]++ assert opportunity.execution_context == "production"+ plan = performance_fix_suggestions([opportunity])[0]+ assert plan.plan["strategy"] == "shrink_lock_scope"+ assert plan.target_symbol == f"{P}::Translog::writeAndFlush"+++def test_skip_reads_the_opportunity_context_not_an_individual_evidence_path():+ """Context is a grouping-key field, one value per opportunity, not per finding.++ A lock owner's own file decides the group's ``execution_context`` (see+ ``causal.causal_key``); the call path recorded as evidence is display data+ and is not re-inspected here. This pins that the skip in+ ``performance_fix_suggestions`` reads ``opportunity.execution_context`` as+ a whole and does not walk evidence looking for a test-looking path node.+ """+ T = "server/src/test/java/org/elasticsearch/index/translog/TranslogTests.java"+ P = "server/src/main/java/org/elasticsearch/index/translog/Translog.java"+ rows = [+ _finding(+ P,+ 120,+ marker="blocking_io_under_lock",+ boundary="fs",+ call_path=(+ f"{T}::TranslogTests::testConcurrentWriteViewsAndSnapshot",+ f"{P}::Translog::add",+ f"{P}::Translog::flushBuffer",+ ),+ )+ ]+ link_performance_findings(rows)+ opportunity = build_performance_opportunities(rows)[0]++ # The finding's own file (a production file) decides the group's context,+ # even though the recorded call path's first node names a test method.+ assert opportunity.execution_context == "production"+ assert opportunity.evidence[0]["path"][0].startswith(T)++ plan = performance_fix_suggestions([opportunity])[0]+ assert plan.plan["strategy"] == "shrink_lock_scope"++def test_distinct_lock_owners_behind_one_helper_do_not_claim_one_lock_fix():"""One shared helper, two critical sections: no single scope to shorten."""opportunity = build_performance_opportunities(