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(cli): status sync totals agree with the pages table (#3889)
Raghav Chamadiyad63816f5a7cc
diff --git a/packages/cli/src/repowise/cli/commands/status_cmd.py b/packages/cli/src/repowise/cli/commands/status_cmd.pyindex cc80eba1a..412e64c38 100644--- a/packages/cli/src/repowise/cli/commands/status_cmd.py+++ b/packages/cli/src/repowise/cli/commands/status_cmd.py@@ -659,18 +659,32 @@ def status_command(path: str | None, workspace: bool, no_workspace: bool, fmt: s)return- # State table. Printed before the page query runs, not after: the query is- # unguarded, and on a wiki.db whose schema predates the current models it- # raises. Ordering it first means a reader still gets the sync state that- # tells them the index is old.+ # The page query runs first so the state table can show its totals, but+ # its error is held until the state table is printed: on a wiki.db whose+ # schema predates the current models it raises, and a reader should still+ # get the sync state that tells them the index is old.+ counts: dict[str, int] = {}+ total_db_tokens = 0+ page_query_error: Exception | None = None+ if has_db:+ try:+ counts, total_db_tokens = run_async(_query_pages(repo_path))+ except Exception as exc:+ page_query_error = exc++ # Totals from the live rows when the query worked. state.json counts+ # tombstoned pages too, and its token total is stamped only by init, so+ # beside the per-type table below it disagreed with it.+ total_pages = sum(counts.values()) if counts else state.get("total_pages", 0)+ total_tokens = total_db_tokens if counts else state.get("total_tokens", 0)state_table = Table(title="Sync State")state_table.add_column("Key", style="cyan")state_table.add_column("Value")state_table.add_row("Last sync commit", state.get("last_sync_commit", "—") or "—")- state_table.add_row("Total pages", str(state.get("total_pages", 0)))+ state_table.add_row("Total pages", str(total_pages))state_table.add_row("Provider", state.get("provider", "—") or "—")state_table.add_row("Model", state.get("model", "—") or "—")- state_table.add_row("Total tokens", f"{state.get('total_tokens', 0):,}")+ state_table.add_row("Total tokens", f"{total_tokens:,}")state_table.add_row("Index storage", format_bytes(storage_bytes))state_table.add_row("Scope",@@ -720,7 +734,8 @@ def status_command(path: str | None, workspace: bool, no_workspace: bool, fmt: sconsole.print(f"[yellow]Database not found at {db_path}.[/yellow]")return- counts, total_db_tokens = run_async(_query_pages(repo_path))+ if page_query_error is not None:+ raise page_query_errorif counts:pages_table = Table(title="Pages by Type")pages_table.add_column("Page Type", style="cyan")diff --git a/tests/unit/cli/test_status_storage.py b/tests/unit/cli/test_status_storage.pyindex 3aacfcb6a..87b20e296 100644--- a/tests/unit/cli/test_status_storage.py+++ b/tests/unit/cli/test_status_storage.py@@ -113,3 +113,31 @@ class TestStatusKeylessUpgradeNote:out = self._status_output(monkeypatch, tmp_path, {"docs_mode": "llm"})assert "Scope" in outassert "repowise generate writes the subsystem pages" not in out+++def test_sync_state_totals_match_the_pages_table(tmp_path: Path, monkeypatch) -> None:+ """state.json counts tombstones and only init stamps tokens; the table does neither."""+ import json++ from click.testing import CliRunner++ repowise_dir = tmp_path / ".repowise"+ repowise_dir.mkdir()+ (repowise_dir / "wiki.db").write_bytes(b"")+ (repowise_dir / "state.json").write_text(json.dumps({"total_pages": 12}))++ async def _pages(_path):+ return {"file_page": 7, "module_page": 3}, 4321++ monkeypatch.setattr(status_cmd, "_query_pages", _pages)+ monkeypatch.setattr(status_cmd, "_query_health_line", lambda _path: None)+ monkeypatch.setattr(status_cmd, "_load_actions", lambda _path: None)++ result = CliRunner().invoke(+ status_cmd.status_command, [str(tmp_path), "--no-workspace"], terminal_width=200+ )++ assert result.exit_code == 0, result.output+ sync = result.output.split("Pages by Type")[0]+ assert "│ 10 " in sync and "│ 12 " not in sync+ assert "4,321" in sync