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(workspace): update reports each repo's stored file and symbol counts (#4555)
Raghav Chamadiyaef9c290bce21
diff --git a/packages/core/src/repowise/core/workspace/update/state.py b/packages/core/src/repowise/core/workspace/update/state.pyindex ba68347ca..0db85bcdd 100644--- a/packages/core/src/repowise/core/workspace/update/state.py+++ b/packages/core/src/repowise/core/workspace/update/state.py@@ -392,3 +392,35 @@ async def reconcile_repo_head_commit(repo_path: Path, head: str | None) -> None:await session.flush()finally:await engine.dispose()+++async def stored_index_counts(repo_path: Path) -> tuple[int, int] | None:+ """``(files, symbols)`` as persisted for *repo_path*, or ``None`` when unreadable.++ The ``count_files`` / ``count_symbols`` figures ``workspace list`` and+ ``status`` show, so an update reports what it stored rather than what it+ parsed this run: a run with nothing to re-parse parsed nothing.+ """+ # Never raises: a count the store cannot give must not fail the update.+ try:+ from ...persistence import create_engine, create_session_factory, get_session+ from ...persistence.crud import count_files, count_symbols, get_repository_by_path+ from ...persistence.database import has_db_store, resolve_db_url++ if not has_db_store(repo_path):+ return None+ engine = create_engine(resolve_db_url(repo_path))+ try:+ async with get_session(create_session_factory(engine)) as session:+ repo = await get_repository_by_path(session, str(repo_path))+ if repo is None:+ return None+ return (+ await count_files(session, repo.id),+ await count_symbols(session, repo.id),+ )+ finally:+ await engine.dispose()+ except Exception:+ _log.debug("Could not read stored index counts for %s", repo_path, exc_info=True)+ return Nonediff --git a/packages/core/src/repowise/core/workspace/update/workspace_pass.py b/packages/core/src/repowise/core/workspace/update/workspace_pass.pyindex fbece9cad..00e9b3f96 100644--- a/packages/core/src/repowise/core/workspace/update/workspace_pass.py+++ b/packages/core/src/repowise/core/workspace/update/workspace_pass.py@@ -47,6 +47,7 @@ from .state import (read_repo_state,reconcile_repo_head_commit,stamp_workspace_entry,+ stored_index_counts,sync_workspace_state_from_disk,)@@ -337,6 +338,11 @@ async def _update_stale_repo(update_pass: _RepoUpdatePass, repo: _StaleRepo) -># Update workspace config entryif result.updated:+ # Report what the store holds, as `workspace list` does; the+ # run's own parse figures are 0/0 when nothing needed re-parsing.+ counts = await stored_index_counts(path)+ if counts is not None:+ result.file_count, result.symbol_count = countsentry = update_pass.ws_config.get_repo(alias)if entry is not None:stamp_workspace_entry(entry, path, new_head)diff --git a/tests/unit/workspace/test_update.py b/tests/unit/workspace/test_update.pyindex ee887ee29..05a64ac3b 100644--- a/tests/unit/workspace/test_update.py+++ b/tests/unit/workspace/test_update.py@@ -361,6 +361,67 @@ class TestUpdateWorkspace:saved_state = json.loads((repo / ".repowise" / "state.json").read_text(encoding="utf-8"))assert saved_state["phase_timings"]["run"] >= 0+ def test_reports_stored_counts_not_run_figures(self, tmp_path: Path) -> None:+ """A commit with nothing to re-parse reports 0/0 from the run; the result+ carries the store's files and symbols, the figures `workspace list` shows."""+ import asyncio++ from repowise.core.persistence import (+ create_engine,+ create_session_factory,+ get_session,+ init_db,+ upsert_repository,+ )+ from repowise.core.persistence.database import resolve_db_url+ from repowise.core.persistence.models import GraphNode+ from tests.unit.persistence.helpers import make_wiki_symbol++ repo = _make_git_repo(tmp_path, "backend")+ old_head = get_head_commit(repo)+ _write_state(repo, old_head)+ _add_commit(repo, "notes.txt")+ ws_config = WorkspaceConfig(+ repos=[RepoEntry(path="backend", alias="backend", last_commit_at_index=old_head)],+ )+ ws_config.save(tmp_path)++ async def _seed() -> None:+ engine = create_engine(resolve_db_url(repo))+ await init_db(engine)+ try:+ async with get_session(create_session_factory(engine)) as session:+ row = await upsert_repository(+ session, name="backend", local_path=str(repo), head_commit=old_head+ )+ session.add_all([+ GraphNode(repository_id=row.id, node_id="a.py", language="python"),+ GraphNode(repository_id=row.id, node_id="b.py", language="python"),+ # An import target is not an indexed file.+ GraphNode(repository_id=row.id, node_id="requests", language="external"),+ *(make_wiki_symbol(row.id, "a.py", n) for n in ("f", "g", "h")),+ ])+ await session.flush()+ finally:+ await engine.dispose()++ asyncio.run(_seed())+ done: list[RepoUpdateResult] = []++ async def _run():+ with patch(+ "repowise.core.workspace.update.workspace_pass.update_single_repo_index",+ new_callable=AsyncMock,+ return_value=RepoUpdateResult(alias="backend", updated=True),+ ):+ return await update_workspace(+ tmp_path, ws_config, run_hooks=False, on_repo_done=done.append+ )++ results = asyncio.run(_run())+ assert (results[0].file_count, results[0].symbol_count) == (2, 3)+ assert (done[0].file_count, done[0].symbol_count) == (2, 3)+def test_detects_config_only_staleness(self, tmp_path: Path) -> None:"""A workspace member with no new commit still runs when its localconfiguration changed."""