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): a state.json that is not an object no longer blocks the workspace update (#4036)
Venius2491e9415f6bb8
diff --git a/packages/core/src/repowise/core/workspace/update/workspace_pass.py b/packages/core/src/repowise/core/workspace/update/workspace_pass.pyindex ac2b4fbd1..61af92af8 100644--- a/packages/core/src/repowise/core/workspace/update/workspace_pass.py+++ b/packages/core/src/repowise/core/workspace/update/workspace_pass.py@@ -45,6 +45,7 @@ from .repo import RepoUpdateResult, _has_persisted_repo_index, update_single_repfrom .state import (check_repo_staleness,clear_stale_update_pending,+ read_repo_state,reconcile_repo_head_commit,sync_workspace_state_from_disk,)@@ -223,15 +224,8 @@ async def _repo_is_stale(abs_path: Path, include_working_tree: bool) -> tuple[bofrom ...repo_config import config_fingerprint# Check staleness against stored commit in state.json- state_path = abs_path / ".repowise" / "state.json"- stored_commit = None- state: dict[str, Any] = {}- if state_path.is_file():- try:- state = _json.loads(state_path.read_text(encoding="utf-8"))- stored_commit = state.get("last_sync_commit")- except Exception:- pass+ state = read_repo_state(abs_path)+ stored_commit = state.get("last_sync_commit")is_stale, current_head, _commits_behind = check_repo_staleness(abs_path,@@ -392,10 +386,7 @@ def _write_repo_state() -> None:"""Advance ``state.json`` to *new_head* after a successful repo update."""state_path = path / ".repowise" / "state.json"- state: dict[str, Any] = {}- if state_path.is_file():- with suppress(Exception):- state = _json.loads(state_path.read_text(encoding="utf-8"))+ state = read_repo_state(path)# Falsy, not absent: an explicit null survives a# membership test and strands the pointer permanently.diff --git a/tests/unit/workspace/test_update.py b/tests/unit/workspace/test_update.pyindex 337d4a854..3c8c2e0fd 100644--- a/tests/unit/workspace/test_update.py+++ b/tests/unit/workspace/test_update.py@@ -616,6 +616,41 @@ class TestUpdateWorkspace:updated = [r for r in results if r.updated]assert len(updated) == 0+ @pytest.mark.parametrize("content", ["[]", '"x"', "null", "0"])+ def test_dry_run_tolerates_a_state_file_that_is_not_an_object(+ self, tmp_path: Path, content: str+ ) -> None:+ """A member whose state.json is valid JSON but not an object must not block the workspace."""+ _make_git_repo(tmp_path, "api")+ web = _make_git_repo(tmp_path, "web")+ (web / ".repowise").mkdir(exist_ok=True)+ (web / ".repowise" / "state.json").write_text(content, encoding="utf-8")++ ws_config = WorkspaceConfig(+ repos=[RepoEntry(path="api", alias="api"), RepoEntry(path="web", alias="web")],+ )++ import asyncio++ results = asyncio.run(update_workspace(tmp_path, ws_config, dry_run=True, run_hooks=False))+ assert isinstance(results, list) # reaching here is the point: it used to raise AttributeError++ def test_write_repo_state_replaces_a_state_file_that_is_not_an_object(+ self, tmp_path: Path+ ) -> None:+ from repowise.core.workspace.update import RepoUpdateResult, _write_repo_state++ repo = _make_git_repo(tmp_path, "web")+ head = get_head_commit(repo)+ (repo / ".repowise").mkdir(exist_ok=True)+ (repo / ".repowise" / "state.json").write_text("[]", encoding="utf-8")++ result = RepoUpdateResult(alias="web", updated=True)+ _write_repo_state(repo, "web", head, False, result)++ state = json.loads((repo / ".repowise" / "state.json").read_text(encoding="utf-8"))+ assert state["last_sync_commit"] == head+@pytest.mark.parametrize("failure_stage",["start", "mkdir", "lock", "index", "state", "stamp", "pending"],