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
test: run pipeline tests on a tmp copy of sample_repo (#4091) (#4099)
Dhvani Dave3586e5c0179d
diff --git a/tests/conftest.py b/tests/conftest.pyindex ba7bba0c9..b7eebab26 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -3,6 +3,8 @@from __future__ import annotationsimport os+import shutil+import subprocessimport sysfrom pathlib import Path@@ -249,6 +251,26 @@ def sample_repo_path(repo_root: Path) -> Path:return path+def sample_repo_copy(sample_repo_path: Path, tmp_path: Path) -> Path:+ """A git-backed copy of sample_repo for tests that write into it.++ The pipeline reads git history, so the copy gets one commit of its own.+ """+ dest = tmp_path / "sample_repo"+ shutil.copytree(sample_repo_path, dest)+ env = {+ **os.environ,+ "GIT_AUTHOR_NAME": "t",+ "GIT_AUTHOR_EMAIL": "[email protected]",+ "GIT_COMMITTER_NAME": "t",+ "GIT_COMMITTER_EMAIL": "[email protected]",+ }+ for args in (["init", "-q"], ["add", "-A"], ["commit", "-q", "-m", "init"]):+ subprocess.run(["git", *args], cwd=dest, check=True, capture_output=True, env=env)+ return dest++@pytest.fixture(scope="session")def fixtures_dir(repo_root: Path) -> Path:"""Path to the tests/fixtures/ directory."""diff --git a/tests/integration/conftest.py b/tests/integration/conftest.pynew file mode 100644index 000000000..b371795c7--- /dev/null+++ b/tests/integration/conftest.py@@ -0,0 +1,18 @@+"""Shared setup for the integration tests."""++from __future__ import annotations++from pathlib import Path++import pytest++[email protected](scope="session", autouse=True)+def sample_repo_stays_clean(sample_repo_path: Path):+ """Fail the run if a test wrote .repowise/ into the shared sample repo."""+ leftover = sample_repo_path / ".repowise"+ yield+ assert not leftover.exists(), (+ f"{leftover} was created during the run. Use the sample_repo_copy "+ "fixture for tests that write into the sample repo."+ )diff --git a/tests/integration/test_pipeline_fast_checkpoint.py b/tests/integration/test_pipeline_fast_checkpoint.pyindex 585304fbd..0cb56a686 100644--- a/tests/integration/test_pipeline_fast_checkpoint.py+++ b/tests/integration/test_pipeline_fast_checkpoint.py@@ -55,10 +55,10 @@ class _FakeJobStore:return matches[:limit]-async def test_fast_mode_skips_generation_and_co_change(sample_repo_path: Path) -> None:+async def test_fast_mode_skips_generation_and_co_change(sample_repo_copy: Path) -> None:store = _FakeJobStore()result = await run_pipeline(- sample_repo_path,+ sample_repo_copy,generate_docs=True, # FAST must override this to False (no LLM client passed)mode=OrchestratorMode.FAST,job_store=store,@@ -72,15 +72,15 @@ async def test_fast_mode_skips_generation_and_co_change(sample_repo_path: Path)assert meta.get("co_change_partners_json", "[]") == "[]"-async def test_checkpoints_recorded_for_completed_phases(sample_repo_path: Path) -> None:+async def test_checkpoints_recorded_for_completed_phases(sample_repo_copy: Path) -> None:store = _FakeJobStore()await run_pipeline(- sample_repo_path,+ sample_repo_copy,mode=OrchestratorMode.FAST,job_store=store,)- completed = await find_completed_phases(store, str(Path(sample_repo_path).resolve()))+ completed = await find_completed_phases(store, str(Path(sample_repo_copy).resolve()))# parse + git always run; both should be recorded COMPLETED.assert "parse" in completedassert "git" in completeddiff --git a/tests/integration/test_pipeline_resume.py b/tests/integration/test_pipeline_resume.pyindex b4694e47a..c187dd584 100644--- a/tests/integration/test_pipeline_resume.py+++ b/tests/integration/test_pipeline_resume.py@@ -42,12 +42,12 @@ async def _make_repo(sf, path: Path) -> str:return repo.id-async def test_first_run_checkpoints_index(sf, sample_repo_path: Path) -> None:- repo_id = await _make_repo(sf, sample_repo_path)+async def test_first_run_checkpoints_index(sf, sample_repo_copy: Path) -> None:+ repo_id = await _make_repo(sf, sample_repo_copy)ctrl = ResumeController(sf, repo_id, resume=False)result = await run_pipeline(- sample_repo_path,+ sample_repo_copy,mode=OrchestratorMode.FAST,resume_controller=ctrl,)@@ -58,12 +58,12 @@ async def test_first_run_checkpoints_index(sf, sample_repo_path: Path) -> None:assert ResumePhase.INDEX in completed-async def test_resume_skips_index_compute(sf, sample_repo_path: Path, monkeypatch) -> None:- repo_id = await _make_repo(sf, sample_repo_path)+async def test_resume_skips_index_compute(sf, sample_repo_copy: Path, monkeypatch) -> None:+ repo_id = await _make_repo(sf, sample_repo_copy)# First run persists the INDEX phase.await run_pipeline(- sample_repo_path,+ sample_repo_copy,mode=OrchestratorMode.FAST,resume_controller=ResumeController(sf, repo_id, resume=False),)@@ -82,7 +82,7 @@ async def test_resume_skips_index_compute(sf, sample_repo_path: Path, monkeypatcmonkeypatch.setattr(orch, "_run_git_indexing", _boom_git)result = await run_pipeline(- sample_repo_path,+ sample_repo_copy,mode=OrchestratorMode.FAST,resume_controller=ResumeController(sf, repo_id, resume=True),)@@ -93,10 +93,10 @@ async def test_resume_skips_index_compute(sf, sample_repo_path: Path, monkeypatcassert result.graph_builder.graph().number_of_nodes() > 0, "graph should be rehydrated"-async def test_first_run_checkpoints_analysis(sf, sample_repo_path: Path) -> None:- repo_id = await _make_repo(sf, sample_repo_path)+async def test_first_run_checkpoints_analysis(sf, sample_repo_copy: Path) -> None:+ repo_id = await _make_repo(sf, sample_repo_copy)await run_pipeline(- sample_repo_path,+ sample_repo_copy,mode=OrchestratorMode.FAST,resume_controller=ResumeController(sf, repo_id, resume=False),)@@ -107,12 +107,12 @@ async def test_first_run_checkpoints_analysis(sf, sample_repo_path: Path) -> Nonassert ResumePhase.ANALYSIS in completed-async def test_resume_skips_analysis_recompute(sf, sample_repo_path: Path, monkeypatch) -> None:- repo_id = await _make_repo(sf, sample_repo_path)+async def test_resume_skips_analysis_recompute(sf, sample_repo_copy: Path, monkeypatch) -> None:+ repo_id = await _make_repo(sf, sample_repo_copy)# First run persists INDEX + ANALYSIS.await run_pipeline(- sample_repo_path,+ sample_repo_copy,mode=OrchestratorMode.FAST,resume_controller=ResumeController(sf, repo_id, resume=False),)@@ -135,7 +135,7 @@ async def test_resume_skips_analysis_recompute(sf, sample_repo_path: Path, monkemonkeypatch.setattr(orch, "_run_decision_extraction", _boom_decisions)result = await run_pipeline(- sample_repo_path,+ sample_repo_copy,mode=OrchestratorMode.FAST,resume_controller=ResumeController(sf, repo_id, resume=True),)@@ -143,14 +143,14 @@ async def test_resume_skips_analysis_recompute(sf, sample_repo_path: Path, monkeasync def test_analysis_checkpoint_receives_the_runs_vector_store(- sf, sample_repo_path: Path, monkeypatch+ sf, sample_repo_copy: Path, monkeypatch) -> None:"""The store a caller hands ``run_pipeline`` has to reach the checkpoint.Dropping it there is invisible: the run still succeeds and still embeds, itjust stores a duplicate instead of folding it."""- repo_id = await _make_repo(sf, sample_repo_path)+ repo_id = await _make_repo(sf, sample_repo_copy)seen: list[object] = []async def _capture(_self: object, **kwargs: object) -> None:@@ -160,7 +160,7 @@ async def test_analysis_checkpoint_receives_the_runs_vector_store(store = object()await run_pipeline(- sample_repo_path,+ sample_repo_copy,vector_store=store,resume_controller=ResumeController(sf, repo_id, resume=False),)diff --git a/tests/integration/test_upgrade_fast_to_full.py b/tests/integration/test_upgrade_fast_to_full.pyindex d5b0a225a..1db6cb457 100644--- a/tests/integration/test_upgrade_fast_to_full.py+++ b/tests/integration/test_upgrade_fast_to_full.py@@ -53,16 +53,16 @@ async def session():async def test_fast_index_then_full_upgrade(- sample_repo_path: Path,+ sample_repo_copy: Path,session: AsyncSession,tmp_path: Path,monkeypatch: pytest.MonkeyPatch,) -> None:# --- 1. Fast index + persist (ESSENTIAL git, no docs). ---- repo = await upsert_repository(session, name="sample", local_path=str(sample_repo_path))+ repo = await upsert_repository(session, name="sample", local_path=str(sample_repo_copy))repo_id = repo.id- result = await run_pipeline(sample_repo_path, mode=OrchestratorMode.FAST)+ result = await run_pipeline(sample_repo_copy, mode=OrchestratorMode.FAST)assert result.generated_pages is None # FAST never generates docsassert result.git_metadata_list, "expected git metadata for the sample repo"assert all(@@ -89,14 +89,14 @@ async def test_fast_index_then_full_upgrade(monkeypatch.setattr(GraphBuilder, "build", _spy_build)# --- 3. Rehydrate the graph from SQL — equivalence + zero resolution. ---- rehydrated = await rehydrate_graph_builder(session, repo_id, sample_repo_path)+ rehydrated = await rehydrate_graph_builder(session, repo_id, sample_repo_copy)assert rehydrated.graph().number_of_nodes() == original_nodesassert rehydrated.graph().number_of_edges() == original_edgesassert rehydrated.pagerank() == original_pagerankassert build_calls["n"] == 0, "rehydration must not re-resolve the graph"# --- 4. Backfill the git tier ESSENTIAL -> FULL (resumable via JobStore). ---- indexer = GitIndexer(sample_repo_path, tier=GitIndexTier.FULL)+ indexer = GitIndexer(sample_repo_copy, tier=GitIndexTier.FULL)job_store = SqlJobStore(session)summary, git_results = await backfill_full_tier(indexer, repo_id, job_store=job_store)await session.commit()