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): don't pin the workspace root's own DB as the shared store (#2524)
Nathan Pride60307aaaccde
diff --git a/packages/cli/src/repowise/cli/commands/serve_cmd.py b/packages/cli/src/repowise/cli/commands/serve_cmd.pyindex 35c0dd425..d11226460 100644--- a/packages/cli/src/repowise/cli/commands/serve_cmd.py+++ b/packages/cli/src/repowise/cli/commands/serve_cmd.py@@ -627,7 +627,20 @@ def serve_command(# Auto-detect local .repowise/ directory if REPOWISE_DB_URL is not set.# repowise init writes to <repo>/.repowise/wiki.db, so honour it when# the user runs `repowise serve` from the same directory.- if not os.environ.get("REPOWISE_DB_URL"):+ #+ # Skip this when cwd is inside a workspace (has an upstream+ # .repowise-workspace.yaml). Setting REPOWISE_DB_URL here is read back+ # by the workspace-detection code in app.py as "the user explicitly+ # configured one shared database for the whole workspace" (the real,+ # separate shared-DB/Postgres feature), which then routes every repo+ # lookup through the workspace root's own near-empty coordinator+ # wiki.db instead of each repo's own <repo>/.repowise/wiki.db. Every+ # repo in the workspace then reports needs_index with zeroed stats,+ # and the UI can't open any of them even though each repo's own index+ # is complete and correct on disk.+ from repowise.core.workspace.config import find_workspace_root++ if not os.environ.get("REPOWISE_DB_URL") and find_workspace_root() is None:local_repowise = Path.cwd() / ".repowise"if local_repowise.exists():local_db = local_repowise / "wiki.db"diff --git a/tests/unit/cli/test_serve_db_url_isolation.py b/tests/unit/cli/test_serve_db_url_isolation.pyindex 8396d9a72..e8f386586 100644--- a/tests/unit/cli/test_serve_db_url_isolation.py+++ b/tests/unit/cli/test_serve_db_url_isolation.py@@ -80,6 +80,35 @@ def test_serve_adopts_the_local_store_when_nothing_is_set(assert tmp_path.name in os.environ["REPOWISE_DB_URL"]+def test_serve_does_not_pin_a_shared_db_at_a_workspace_root(+ stub_serve: None, monkeypatch, tmp_path+) -> None:+ """A workspace root's own .repowise/ must not become "the" shared database.++ Auto-detect exists for the single-repo case: a `.repowise/` beside cwd+ means a real store to open. A workspace root also keeps its own+ `.repowise/` (for the shared provider config), so the same check fires+ there too. But setting REPOWISE_DB_URL at a workspace root is read back+ by the server's workspace-detection code (``app.py``) as "the user+ explicitly configured one shared database for the whole workspace" — the+ real, separate shared-DB/Postgres feature — which then routes every+ member repo's lookup through the workspace root's own near-empty+ coordinator wiki.db instead of each repo's own <repo>/.repowise/wiki.db.+ Every repo in the workspace reports as unindexed with zeroed stats, and+ none of them open, even though each repo's own index is complete and+ correct on disk.+ """+ (tmp_path / ".repowise").mkdir()+ (tmp_path / ".repowise-workspace.yaml").write_text("version: 1\nrepos: []\n")+ monkeypatch.chdir(tmp_path)+ os.environ.pop("REPOWISE_DB_URL", None)++ result = CliRunner().invoke(serve_cmd.serve_command, ["--no-ui"])++ assert result.exit_code == 0, result.output+ assert "REPOWISE_DB_URL" not in os.environ++def test_the_previous_test_did_not_leak_its_db_url() -> None:"""The regression itself, and the reason this is a second test function.