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 init --dry-run writes nothing (#1526)
Felix-Ayush71dad3b25341
diff --git a/packages/cli/src/repowise/cli/commands/init_cmd/workspace.py b/packages/cli/src/repowise/cli/commands/init_cmd/workspace.pyindex 8e6fe75c5..5c12eac60 100644--- a/packages/cli/src/repowise/cli/commands/init_cmd/workspace.py+++ b/packages/cli/src/repowise/cli/commands/init_cmd/workspace.py@@ -387,7 +387,10 @@ def _ingest_and_generate_repo(repo: Any, idx: int, total: int, ctx: _WorkspaceCt)if ctx.dry_run:- console.print(f" [{WARN}]Dry run — skipping generation for this repo.[/]\n")+ console.print(+ f" [{WARN}]Dry run — `.repowise/` created; "+ "no DB, state, or pages written for this repo.[/]\n"+ )skip_reason = "dry run"elif ctx.run_mode == "fast":# Fast mode is a graph-and-git index by design; it skips the wiki so a@@ -446,6 +449,18 @@ def _ingest_and_generate_repo(repo: Any, idx: int, total: int, ctx: _WorkspaceCtdocs_outcome = (len(result.generated_pages or []), skip_reason)+ # A dry run must not touch the database or write any state, mirroring+ # single-repo init (which skips the resume controller and returns before+ # persistence). The index was computed in memory above only so the plan+ # and per-repo counts can be shown; nothing is written for this repo.+ if ctx.dry_run:+ return _RepoOutcome(+ file_count=result.file_count,+ symbol_count=result.symbol_count,+ pages_generated=pages_generated,+ docs_outcome=docs_outcome,+ )+# Persist to repo-local DBrun_async(persist_result(result, repo.path))@@ -725,8 +740,17 @@ def _workspace_init(repos=entries,default_repo=primary_alias,)- config_path = ws_config.save(root)- console.print(f" [{OK}]✓[/] Created {config_path.name}")+ if dry_run:+ # ensure_repowise_dir still creates `.repowise/` per repo (needed so a+ # later distill-hook decline can gate every selected path); dry-run+ # only means nothing is *written* into those directories or the workspace.+ console.print(+ f" [{WARN}]Dry run — `.repowise/` directories are created, "+ "but no config, index, or pages are written.[/]"+ )+ else:+ config_path = ws_config.save(root)+ console.print(f" [{OK}]✓[/] Created {config_path.name}")console.print()# Step 4: Index each selected repo (always generate_docs=False; generation is separate)@@ -793,17 +817,20 @@ def _workspace_init(total_pages += outcome.pages_generateddocs_outcomes[repo.alias] = outcome.docs_outcome- # Save workspace config with updated timestamps- ws_config.save(root)+ # Save workspace config with updated timestamps. On a dry run nothing is+ # written for any repo (see _ingest_and_generate_repo), so nothing is+ # written at the workspace level either.+ if not dry_run:+ ws_config.save(root)- # Step 5: Cross-repo analysis (co-changes, package deps, contracts)- _run_cross_repo_analysis(ws_config, root, selected, errors)+ # Step 5: Cross-repo analysis (co-changes, package deps, contracts)+ _run_cross_repo_analysis(ws_config, root, selected, errors)- # Step 6: Register primary repo with configured editor clients- primary_entry = ws_config.get_primary()- if primary_entry:- primary_path = (root / primary_entry.path).resolve()- register_editor_clients(console, primary_path, no_editor_setup=not editor_setup)+ # Step 6: Register primary repo with configured editor clients+ primary_entry = ws_config.get_primary()+ if primary_entry:+ primary_path = (root / primary_entry.path).resolve()+ register_editor_clients(console, primary_path, no_editor_setup=not editor_setup)# Step 7: Completion summaryelapsed = time.monotonic() - start@@ -820,9 +847,10 @@ def _workspace_init(docs_outcomes=docs_outcomes,)- # Offer to install post-commit hooks+ # Offer to install post-commit hooks. Skipped on a dry run, which must+ # not write anything.indexed_repos = [repo for repo in selected if repo.alias not in [e[0] for e in errors]]- if indexed_repos:+ if indexed_repos and not dry_run:offer_hook_install(console,[r.path for r in indexed_repos],@@ -835,11 +863,12 @@ def _workspace_init(# failed) because ensure_repowise_dir already created `.repowise/` in# each, and the hook treats any repo with `.repowise/` and no recorded# verdict as enabled — a decline must gate every one of them off.- offer_distill_rewrite_hook(- console,- [r.path for r in selected],- distill_hook,- yes=yes,- no_editor_setup=not editor_setup,- )+ if not dry_run:+ offer_distill_rewrite_hook(+ console,+ [r.path for r in selected],+ distill_hook,+ yes=yes,+ no_editor_setup=not editor_setup,+ )console.print()diff --git a/tests/unit/cli/test_workspace_init_dry_run.py b/tests/unit/cli/test_workspace_init_dry_run.pynew file mode 100644index 000000000..cdac95537--- /dev/null+++ b/tests/unit/cli/test_workspace_init_dry_run.py@@ -0,0 +1,135 @@+"""Workspace init ``--dry-run`` must not persist anything.++Regression anchor for #1504: single-repo ``repowise init --dry-run`` writes+nothing (skips the resume controller and returns before persistence), but the+workspace path ran the full pipeline and then persisted unconditionally —+``persist_result``, ``state.json``, KG JSON, editor files and config for every+repo. The dry-run flag only gated the *generation* branch.++These tests drive :func:`_ingest_and_generate_repo` with a stubbed pipeline and+assert that on a dry run nothing is written for the repo.+"""++from __future__ import annotations++from pathlib import Path+from types import SimpleNamespace++import pytest++from repowise.cli.commands.init_cmd import workspace as ws_mod+from repowise.cli.commands.init_cmd.workspace import _ingest_and_generate_repo, _WorkspaceCtx+++async def _fake_pipeline(*a: object, **k: object) -> SimpleNamespace:+ return _fake_result()+++def _fake_result() -> SimpleNamespace:+ return SimpleNamespace(+ file_count=3,+ symbol_count=9,+ generated_pages=[],+ knowledge_graph_result=None,+ repo_name="repo",+ )+++def _fake_repo(path: Path) -> SimpleNamespace:+ return SimpleNamespace(alias="repo", path=path)+++def _ctx(repo: Path, *, dry_run: bool) -> _WorkspaceCtx:+ return _WorkspaceCtx(+ provider=None,+ ws_config=SimpleNamespace(get_repo=lambda _alias: SimpleNamespace()),+ editor_options=SimpleNamespace(),+ index_only=False,+ dry_run=dry_run,+ force=False,+ follow_renames=False,+ include_submodules=False,+ exclude_patterns=[],+ skip_tests=False,+ skip_infra=False,+ concurrency=1,+ test_run=False,+ yes=True,+ resume=False,+ onboarding=False,+ harvest_decisions=False,+ wiki_style="default",+ language="en",+ resolved_reasoning="auto",+ embedder_name_resolved="mock",+ embedder_was_requested=False,+ resolved_commit_limit=10,+ run_mode="standard",+ )+++def _stub_pipeline(monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setattr(+ "repowise.core.pipeline.run_pipeline",+ _fake_pipeline,+ )+ monkeypatch.setattr(+ ws_mod,+ "persist_result",+ lambda *a, **k: (_ for _ in ()).throw(AssertionError("persist_result called on dry run")),+ )+ monkeypatch.setattr(+ ws_mod,+ "save_state",+ lambda *a, **k: (_ for _ in ()).throw(AssertionError("save_state called on dry run")),+ )+ monkeypatch.setattr(+ ws_mod,+ "save_knowledge_graph_json",+ lambda *a, **k: (_ for _ in ()).throw(+ AssertionError("save_knowledge_graph_json called on dry run")+ ),+ )+ monkeypatch.setattr(+ ws_mod,+ "write_editor_project_files",+ lambda *a, **k: (_ for _ in ()).throw(+ AssertionError("write_editor_project_files called on dry run")+ ),+ )+ monkeypatch.setattr(+ ws_mod,+ "save_config",+ lambda *a, **k: (_ for _ in ()).throw(AssertionError("save_config called on dry run")),+ )+ monkeypatch.setattr(+ ws_mod,+ "save_config_partial",+ lambda *a, **k: (_ for _ in ()).throw(+ AssertionError("save_config_partial called on dry run")+ ),+ )+++def test_workspace_dry_run_never_persists(tmp_path: Path, _stub_pipeline: None) -> None:+ repo = _fake_repo(tmp_path / "repo")+ (repo.path / ".repowise").mkdir(parents=True, exist_ok=True)++ outcome = _ingest_and_generate_repo(repo, 1, 1, _ctx(repo.path, dry_run=True))++ assert outcome.error is None+ assert outcome.file_count == 3+ assert outcome.symbol_count == 9+ assert not (repo.path / ".repowise" / "state.json").exists()+++def test_workspace_dry_run_still_counts_files(tmp_path: Path, _stub_pipeline: None) -> None:+ repo = _fake_repo(tmp_path / "repo")+ (repo.path / ".repowise").mkdir(parents=True, exist_ok=True)++ outcome = _ingest_and_generate_repo(repo, 1, 1, _ctx(repo.path, dry_run=True))++ assert outcome.file_count == 3+ assert outcome.symbol_count == 9+ assert outcome.pages_generated == 0