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(generation): stamp CLAUDE.md with the indexed commit, not live HEAD (#1877)
Bakayanga7603e5475f5
diff --git a/packages/core/src/repowise/core/generation/editor_files/fetcher.py b/packages/core/src/repowise/core/generation/editor_files/fetcher.pyindex 23781f1c2..8f9f1e711 100644--- a/packages/core/src/repowise/core/generation/editor_files/fetcher.py+++ b/packages/core/src/repowise/core/generation/editor_files/fetcher.py@@ -67,10 +67,18 @@ class EditorFileDataFetcher:kg_layers, kg_tour = await self._get_kg_data()+ # The stamp must report the commit the index was built against, not+ # the live HEAD: a rebase fires the regeneration hook per replayed+ # commit while the index underneath is unchanged, so a live-HEAD+ # stamp walks forward on its own and silently misdates everything+ # below it. Fall back to the shell-out only when the column is empty+ # (pre-backfill indexes).+ stored_commit = ((repo.head_commit or "")[:7]) if repo else ""+return EditorFileData(repo_name=repo_name,indexed_at=datetime.now(UTC).strftime("%Y-%m-%d"),- indexed_commit=_get_head_short_sha(self._repo_path),+ indexed_commit=stored_commit or _get_head_short_sha(self._repo_path),architecture_summary=await self._get_architecture_summary(),key_modules=await self._get_key_modules(),entry_points=await self._get_entry_points(),diff --git a/tests/unit/generation/test_editor_file_fetcher.py b/tests/unit/generation/test_editor_file_fetcher.pyindex a597479b8..3b2629112 100644--- a/tests/unit/generation/test_editor_file_fetcher.py+++ b/tests/unit/generation/test_editor_file_fetcher.py@@ -372,3 +372,45 @@ async def test_fetch_indexed_at_is_date_string(session, repo, tmp_path):import reassert re.match(r"^\d{4}-\d{2}-\d{2}$", data.indexed_at)+++async def test_fetch_indexed_commit_reports_stored_head_commit(session, tmp_path):+ """The stamp must report the commit the index was built against.++ Regression test for #1874: the stamp used to shell out for the live HEAD,+ which drifts from the indexed commit (e.g. a rebase rewrites CLAUDE.md+ with the then-current HEAD while the index underneath is unchanged).+ """+ stored_commit = "a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2"+ repo = await upsert_repository(+ session,+ name="test-repo",+ local_path="/tmp/test-repo",+ url="",+ head_commit=stored_commit,+ )+ await session.commit()++ # tmp_path is not a git checkout, so any shell-out for live HEAD would+ # return "" — the stamp must still carry the stored commit's short form.+ fetcher = EditorFileDataFetcher(session, repo.id, tmp_path)+ data = await fetcher.fetch()++ assert data.indexed_commit == stored_commit[:7]+++async def test_fetch_indexed_commit_falls_back_to_live_head_when_stored_is_empty(session, tmp_path):+ """Pre-backfill indexes (head_commit NULL) keep the legacy shell-out path."""+ repo = await upsert_repository(+ session,+ name="test-repo",+ local_path="/tmp/test-repo",+ url="",+ )+ await session.commit()++ fetcher = EditorFileDataFetcher(session, repo.id, tmp_path)+ data = await fetcher.fetch()++ # tmp_path is not a git checkout, so the fallback resolves to "".+ assert data.indexed_commit == ""