Repository navigation
fix(pipeline): preserve coverage across an incremental health re-score - #1806
Conversation
The incremental pipeline built its HealthAnalyzer without a coverage_map, so every changed file was re-scored as if no coverage had ever been ingested. The partial-health writer then upserted those metrics, overwriting the stored line_coverage_pct with NULL for exactly the files that just changed — eroding coverage one file per update, starting with files under active development (issue repowise-dev#1739). Add load_stored_coverage_map (mirroring the existing _coverage_for_rescore in the CLI update path and load_stored_function_mod_p80 in the workspace updater) and pass it to HealthAnalyzer in run_partial_analysis. Both callers — the workspace updater and the CLI incremental path — now load and supply the persisted coverage map, so an incremental update re-scores changed files against the coverage they already had. Fixes repowise-dev#1739
|
✅ Health of changed files: 1.7 → 1.9 (+0.2) 📋 At a glance ✅ Health gate: passed 📌 Before you merge
🎯 Blast radius (symbols whose signature this PR changed, and who calls them)
🔎 More signals (4)🗺️ Change map flowchart LR
subgraph PR ["Changed in this PR (3 with dependents)"]
f_packages_cli_src_repowise_cli_commands_update_cmd_incremental_py[".../update_cmd/incremental.py 🔥"]:::changed
f_packages_core_src_repowise_core_pipeline_incremental_py[".../pipeline/incremental.py 🔥"]:::changed
f_packages_core_src_repowise_core_workspace_update_py[".../workspace/update.py 🔥"]:::changed
end
f_packages_cli_src_repowise_cli_commands_update_cmd___init___py[".../update_cmd/__init__.py"]
f_packages_cli_src_repowise_cli_commands_update_cmd_incremental_py --> f_packages_cli_src_repowise_cli_commands_update_cmd___init___py
f_packages_cli_src_repowise_cli_commands_update_cmd_command_py[".../update_cmd/command.py"]
f_packages_cli_src_repowise_cli_commands_update_cmd_incremental_py --> f_packages_cli_src_repowise_cli_commands_update_cmd_command_py
f_packages_cli_src_repowise_cli_commands_update_cmd_persistence_py[".../update_cmd/persistence.py"]
f_packages_cli_src_repowise_cli_commands_update_cmd_incremental_py --> f_packages_cli_src_repowise_cli_commands_update_cmd_persistence_py
f_packages_cli_src_repowise_cli_commands_dead_code_cmd_py[".../commands/dead_code_cmd.py"]
f_packages_core_src_repowise_core_pipeline_incremental_py --> f_packages_cli_src_repowise_cli_commands_dead_code_cmd_py
f_packages_core_src_repowise_core_pipeline_incremental_py --> f_packages_cli_src_repowise_cli_commands_update_cmd_command_py
f_packages_core_src_repowise_core_pipeline_incremental_py --> f_packages_cli_src_repowise_cli_commands_update_cmd_persistence_py
f_packages_core_src_repowise_core_analysis_dead_code_analyzer_py[".../dead_code/analyzer.py"]
f_packages_core_src_repowise_core_pipeline_incremental_py --> f_packages_core_src_repowise_core_analysis_dead_code_analyzer_py
f_packages_cli_src_repowise_cli_commands_doctor_cmd_workspace_checks_py[".../doctor_cmd/workspace_checks.py"]
f_packages_core_src_repowise_core_workspace_update_py --> f_packages_cli_src_repowise_cli_commands_doctor_cmd_workspace_checks_py
f_packages_cli_src_repowise_cli_commands_init_cmd_workspace_py[".../init_cmd/workspace.py"]
f_packages_core_src_repowise_core_workspace_update_py --> f_packages_cli_src_repowise_cli_commands_init_cmd_workspace_py
f_packages_core_src_repowise_core_workspace_update_py --> f_packages_cli_src_repowise_cli_commands_update_cmd_command_py
f_packages_core_src_repowise_core_workspace_update_py --> f_packages_cli_src_repowise_cli_commands_update_cmd_persistence_py
more(["+10 more dependents"])
PR --> more
w_packages_core_src_repowise_core_pipeline_persist_py(["⚠️ .../pipeline/persist.py changed together 14×, not in PR"]):::warn
f_packages_core_src_repowise_core_pipeline_incremental_py -.- w_packages_core_src_repowise_core_pipeline_persist_py
w_packages_cli_src_repowise_cli_commands_update_cmd_command_py(["⚠️ .../update_cmd/command.py changed together 13×, not in PR"]):::warn
f_packages_core_src_repowise_core_workspace_update_py -.- w_packages_cli_src_repowise_cli_commands_update_cmd_command_py
t_tests_unit_dead_code_test_partial_py(["✅ .../dead_code/test_partial.py"]):::guard
t_tests_unit_dead_code_test_partial_py -.-> f_packages_core_src_repowise_core_pipeline_incremental_py
t_tests_unit_cli_test_update_lock_py(["✅ .../cli/test_update_lock.py"]):::guard
t_tests_unit_cli_test_update_lock_py -.-> f_packages_core_src_repowise_core_workspace_update_py
classDef changed fill:#dbeafe,stroke:#1d4ed8,color:#1e3a5f
classDef warn fill:#fef3c7,stroke:#b45309,color:#78350f
classDef guard fill:#dcfce7,stroke:#15803d,color:#14532d
Solid arrows: code that imports the changed files (17 direct dependents, from the last indexed snapshot). Dashed: history/tests. 🔥 Hotspots touched (3)
🔗 Hidden coupling (2 files)
💀 Dead code (1 finding)
👀 Suggested reviewers @RaghavChamadiya 📊 See the full report for this PR |
RaghavChamadiya
left a comment
There was a problem hiding this comment.
Thanks @sloemo01 for tracing this to the writer instead of stopping at the analyzer. I confirmed the whole chain against main before merging:
run_partial_analysisbuilds itsHealthAnalyzeratincremental.py:569with nocoverage_map- the analyzer defaults it to
{}(engine.py:327) - the per-file lookup at
engine.py:977then yieldsNonefor bothline_coverage_pctandbranch_coverage_pct upsert_health_metricswrites thatNonestraight back (crud/analysis/health.py:1018)
So coverage really is erased, and it is erased for exactly the files someone just touched, which is the worst possible subset to lose it on. A repo that ingested coverage once would watch it decay along its own active development front, and nothing in the output says why.
Mirroring load_stored_function_mod_p80 rather than inventing a new loading shape is the right call, and wiring both callers means the workspace updater does not quietly keep the bug.
What
Fixes #1739. The incremental pipeline built its
HealthAnalyzerwithout acoverage_map, so every changed file was re-scored as if no coverage had ever been ingested. The partial-health writer then upserted those metrics, overwriting the storedline_coverage_pctwithNULLfor exactly the files that just changed — eroding coverage one file per update, starting with the files under active development.Root cause
run_partial_analysisbuiltHealthAnalyzer(...)with nocoverage_map(which defaults to{}), so the coverage lookup atengine.py:889yieldedNonefor every re-analyzed file.persist_partial_healththen upserted those metrics, nulling coverage. The sibling re-score path already had the fix pattern (_coverage_for_rescorein the CLI update path) — this extends it to the incremental health pass.Fix
incremental.py: addload_stored_coverage_map(repo_path)— reloads the persistedCoverageFilerows into the{path: coverage-dict}shapeHealthAnalyzerexpects, mirroringload_stored_function_mod_p80and the CLI's_coverage_for_rescore.run_partial_analysis: accept and passcoverage_maptoHealthAnalyzer.workspace/update.py, async) and the CLI incremental path (update_cmd/incremental.py).Tests
tests/unit/pipeline/test_load_stored_coverage_map.py— persists coverage rows then reloads them as the health-coverage map (2 tests: reload round-trip + absent-store returns empty).tests/unit/pipeline/+tests/unit/cli/test_coverage_cmd.py— 127 passed, no regressions.