"""TDD — symbol indexer must not access commit_meta (dropped in migration 0020).""" from __future__ import annotations import pytest import msgpack from datetime import datetime, timezone from sqlalchemy.ext.asyncio import AsyncSession from muse.core.types import blob_id from musehub.db.musehub_repo_models import MusehubBranch, MusehubCommit, MusehubCommitRef, MusehubSnapshot, MusehubSnapshotRef from musehub.types.json_types import JSONObject from tests.factories import create_repo def _utc() -> datetime: return datetime.now(tz=timezone.utc) async def _add_snapshot(session: AsyncSession, repo_id: str, seed: str, manifest: JSONObject) -> str: snap_id = blob_id(f"snap-{seed}".encode()) session.add(MusehubSnapshot( snapshot_id=snap_id, directories=[], manifest_blob=msgpack.packb(manifest, use_bin_type=True), entry_count=len(manifest), created_at=_utc(), )) session.add(MusehubSnapshotRef(repo_id=repo_id, snapshot_id=snap_id)) await session.commit() return snap_id async def _add_commit(session: AsyncSession, repo_id: str, seed: str, snap_id: str, **kwargs: typing.Any) -> MusehubCommit: row = MusehubCommit( commit_id=blob_id(seed.encode()), branch="dev", parent_ids=[], message=f"feat: {seed}", author="gabriel", timestamp=_utc(), snapshot_id=snap_id, **kwargs, ) session.add(row) session.add(MusehubCommitRef(repo_id=repo_id, commit_id=row.commit_id)) session.add(MusehubBranch( branch_id=blob_id(f"br-{seed}".encode()), repo_id=repo_id, name="dev", head_commit_id=row.commit_id, )) await session.commit() return row # --------------------------------------------------------------------------- # SI1 — index_new_commits does not crash with AttributeError on commit_meta # --------------------------------------------------------------------------- @pytest.mark.asyncio async def test_si1_index_new_commits_no_commit_meta( db_session: AsyncSession, ) -> None: """Symbol indexer must not raise AttributeError on commit.commit_meta.""" from musehub.services.musehub_symbol_indexer import build_symbol_index repo = await create_repo(db_session, owner="gabriel", visibility="public") oid = blob_id(b"file-content") snap_id = await _add_snapshot(db_session, repo.repo_id, "si1", {"src/app.py": oid}) commit = await _add_commit(db_session, repo.repo_id, "si1-c1", snap_id, agent_id="claude-code", model_id="claude-sonnet-4-6") # Must not raise — falls back to snapshot diffing since no structured_delta await build_symbol_index(db_session, repo.repo_id, commit.commit_id) # --------------------------------------------------------------------------- # SI2 — re-index path does not crash with AttributeError on commit_meta # --------------------------------------------------------------------------- @pytest.mark.asyncio async def test_si2_reindex_no_commit_meta( db_session: AsyncSession, ) -> None: """Re-index path must not raise AttributeError on commit_meta column select.""" from musehub.services.musehub_symbol_indexer import backfill_raw_ops_from_commits repo = await create_repo(db_session, owner="gabriel", visibility="public") oid = blob_id(b"reindex-content") snap_id = await _add_snapshot(db_session, repo.repo_id, "si2", {"src/main.py": oid}) await _add_commit(db_session, repo.repo_id, "si2-c1", snap_id) # Must not raise even with no structured_delta await backfill_raw_ops_from_commits(db_session, repo.repo_id)