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(tests): stop the suite repointing the developer's global editor config (#1481)
Raghav Chamadiya2d31cd61d23a
diff --git a/tests/conftest.py b/tests/conftest.pyindex 9d87e9299..8d7e2a596 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -45,6 +45,38 @@ def _no_telemetry_network(tmp_path_factory: pytest.TempPathFactory):mp.undo()[email protected](scope="session", autouse=True)+def _no_real_editor_setup():+ """Guarantee no test repoints the developer's real global editor config.++ ``repowise init`` (and ``doctor``'s self-heal path) defaults to+ ``--editor-setup`` on, which rewrites the *global*, machine-wide MCP+ server registration (e.g. ``~/.claude/settings.json``) to point at+ whatever repo path was just indexed. A test that drives the real CLI+ against a ``tmp_path`` fixture repo — e.g.+ ``tests/integration/test_cli.py``'s lock/watcher tests, which call+ ``init`` through ``CliRunner`` in-process rather than mocking it out —+ was doing exactly that: it repointed the developer's actual Claude Code+ MCP entry at a pytest temp directory that gets wiped on reboot, breaking+ every other project's ``repowise`` MCP tools until the *next*+ ``doctor``/``update`` run happened to self-heal it back (and even then,+ an already-running Claude Code session keeps using the stale spawn+ command it cached at connect time, since it has no reason to re-read+ the file mid-session).++ ``REPOWISE_SKIP_EDITOR_SETUP`` is the exact env var editor_setup.py and+ doctor's self-heal migrations already gate on — set once, for the whole+ session, so no test (present or future) can hit this by omission the+ way the lock/watcher tests did.+ """+ from _pytest.monkeypatch import MonkeyPatch++ mp = MonkeyPatch()+ mp.setenv("REPOWISE_SKIP_EDITOR_SETUP", "1")+ yield+ mp.undo()++@pytest.fixture(autouse=True)def _isolate_structlog_config():"""Restore structlog's global configuration after every test.diff --git a/tests/unit/cli/test_agent_target_baseline.py b/tests/unit/cli/test_agent_target_baseline.pyindex d91344a04..109c1a930 100644--- a/tests/unit/cli/test_agent_target_baseline.py+++ b/tests/unit/cli/test_agent_target_baseline.py@@ -190,6 +190,13 @@ def baseline_env(tmp_path_factory, monkeypatch):monkeypatch.setenv("HOMEPATH", str(home)[len(home.drive) :])monkeypatch.setattr(Path, "home", lambda: home)+ # The session-wide guard in conftest.py stops every test writing global+ # editor config. This baseline exists to capture exactly those writes, and+ # the redirects above (including ``Path.home``) mean they land in the fake+ # home, so it opts out — otherwise the user scope loses the Claude Desktop+ # entry and the golden no longer matches.+ monkeypatch.delenv("REPOWISE_SKIP_EDITOR_SETUP", raising=False)+# Claude Desktop only registers when its config directory already exists,# so create it — the baseline should cover that write where the platform# supports it at all.diff --git a/tests/unit/cli/test_augment_hook_perf.py b/tests/unit/cli/test_augment_hook_perf.pyindex 89c018665..b10b2ecd6 100644--- a/tests/unit/cli/test_augment_hook_perf.py+++ b/tests/unit/cli/test_augment_hook_perf.py@@ -46,9 +46,16 @@ def _fake_home(tmp_path: Path) -> dict[str, str]:finds anything to migrate, and ``Path.home()`` reads ``USERPROFILE`` onWindows and ``HOME`` elsewhere. Both are redirected. What is under test isthe import graph, which is identical either way.++ ``REPOWISE_SKIP_EDITOR_SETUP`` is dropped rather than inherited: the+ session-wide guard in ``conftest.py`` sets it for every test, but this one+ measures the *default* user's import graph. Under that variable the stamp is+ never written, so every call falls through to the ``is_editor_setup_disabled``+ check and imports ``editor_setup`` — the exact thing this asserts against."""env = dict(os.environ)env["HOME"] = env["USERPROFILE"] = str(tmp_path)+ env.pop("REPOWISE_SKIP_EDITOR_SETUP", None)return envdiff --git a/tests/unit/cli/test_editor_setup.py b/tests/unit/cli/test_editor_setup.pyindex 0c5c65c97..f89aa9909 100644--- a/tests/unit/cli/test_editor_setup.py+++ b/tests/unit/cli/test_editor_setup.py@@ -282,6 +282,7 @@ def test_the_rewrite_hook_answer_decides_every_replacing_surface("""from repowise.cli.commands.init_cmd._interactive import offer_distill_rewrite_hook+ monkeypatch.delenv("REPOWISE_SKIP_EDITOR_SETUP", raising=False)(tmp_path / ".repowise").mkdir()monkeypatch.setattr("repowise.cli.agent_adapters.claude_code.ClaudeCodeAdapter.install_rewrite_hook",