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.

feat(cli): status says when the next update re-scores health or rescans security (#4301)

Raghav Chamadiyab38fd57b0839
diff --git a/packages/cli/src/repowise/cli/commands/status_cmd.py b/packages/cli/src/repowise/cli/commands/status_cmd.py
index 242182d1a..4840b308a 100644
--- a/packages/cli/src/repowise/cli/commands/status_cmd.py
+++ b/packages/cli/src/repowise/cli/commands/status_cmd.py
@@ -334,6 +334,29 @@ def _query_health_line(repo_path: Path) -> str | None:
)
+def _rescore_pending(state: dict) -> list[str]:
+ """Which stored results the next ``repowise update`` redoes for a newer analyzer."""
+ from repowise.cli.commands.update_cmd.persistence import (
+ health_analyzer_changed,
+ security_scanner_changed,
+ )
+
+ pending = ["health"] if health_analyzer_changed(state) else []
+ return pending + (["security"] if security_scanner_changed(state) else [])
+
+
+_RESCORE_LINES = {
+ ("health",): "Health was scored by an older analyzer; the next repowise update re-scores it.",
+ ("security",): (
+ "Security findings came from an older scanner; the next repowise update rescans them."
+ ),
+ ("health", "security"): (
+ "Health and security results came from an older analyzer and scanner; "
+ "the next repowise update redoes both."
+ ),
+}
+
+
#: The resume command an interrupted ``init`` leaves for the user.
_RESUME_COMMAND = "repowise init --resume"
@@ -692,6 +715,8 @@ def status_command(path: str | None, workspace: bool, no_workspace: bool, fmt: s
has_db = db_path.exists() or db_configured()
incomplete = _incomplete_index(repo_path, state)
pending_lanes = pending_decision_lanes(state, repo_path)
+ # An unfinished init has no stamps yet; the resume line covers it.
+ rescore = _rescore_pending(state) if incomplete is None else []
if fmt == "json":
counts, total_db_tokens = (
@@ -720,6 +745,7 @@ def status_command(path: str | None, workspace: bool, no_workspace: bool, fmt: s
"index_scope": scope,
"upgrade_command": upgrade_command(scope),
"decision_lanes_pending": list(pending_lanes),
+ "rescore_pending": rescore,
}
)
return
@@ -826,6 +852,10 @@ def status_command(path: str | None, workspace: bool, no_workspace: bool, fmt: s
if health_line:
console.print()
console.print(health_line)
+ if rescore:
+ if not health_line:
+ console.print()
+ console.print(f"[dim]{_RESCORE_LINES[tuple(rescore)]}[/dim]")
if incomplete is not None:
next_lines = [_incomplete_line(incomplete)]
diff --git a/tests/unit/cli/test_status_state_truth.py b/tests/unit/cli/test_status_state_truth.py
index 0f286ee1e..0cd48e1d2 100644
--- a/tests/unit/cli/test_status_state_truth.py
+++ b/tests/unit/cli/test_status_state_truth.py
@@ -232,3 +232,40 @@ class TestInitTestRun:
run = SimpleNamespace(repo_path=tmp_path, opts=SimpleNamespace(test_run=test_run))
_finish._stamp_test_run(run)
assert resolve_index_scope(load_state(tmp_path))["test_run"] is test_run
+
+
+class TestRescorePending:
+ """An upgrade that changed the analyzer or scanner is named before ``update`` runs."""
+
+ def _stamps(self, health_version) -> dict:
+ from repowise.core.analysis.security_scan import SECURITY_SCANNER_VERSION
+
+ return {
+ "last_sync_commit": "abc",
+ "health_analyzer_version": health_version,
+ "security_scanner_version": SECURITY_SCANNER_VERSION,
+ }
+
+ def test_an_older_analyzer_is_named(self, tmp_path, monkeypatch) -> None:
+ out = _status(tmp_path, monkeypatch, self._stamps(1))
+ assert "Health was scored by an older analyzer" in out
+ assert "repowise update re-scores it" in out
+
+ def test_current_stamps_print_nothing(self, tmp_path, monkeypatch) -> None:
+ from repowise.core.analysis.health import HEALTH_ANALYZER_VERSION
+
+ out = _status(tmp_path, monkeypatch, self._stamps(HEALTH_ANALYZER_VERSION))
+ assert "older" not in out
+ (tmp_path / "j").mkdir()
+ data = json.loads(
+ _status(tmp_path / "j", monkeypatch, self._stamps(HEALTH_ANALYZER_VERSION), fmt="json")
+ )
+ assert data["rescore_pending"] == []
+
+ def test_both_combine_into_one_line_and_json(self, tmp_path, monkeypatch) -> None:
+ state = {"last_sync_commit": "abc", "health_analyzer_version": 1}
+ out = _status(tmp_path, monkeypatch, state)
+ assert "Health and security results came from an older analyzer and scanner" in out
+ (tmp_path / "j").mkdir()
+ data = json.loads(_status(tmp_path / "j", monkeypatch, state, fmt="json"))
+ assert data["rescore_pending"] == ["health", "security"]