gabriel / musehub public
test_symbol_indexer_no_commit_meta.py python
94 lines 3.6 KB Cold
Raw
sha256:ef10830ce231e0a20efcb0e2586cb879471247e916616e6fdd0d51df459e2595 fix: typing audit — 0 violations, 0 untyped defs across all… Sonnet 4.6 minor ⚠ breaking 172 days ago
1 """TDD — symbol indexer must not access commit_meta (dropped in migration 0020)."""
2 from __future__ import annotations
3
4 import pytest
5 import msgpack
6 from datetime import datetime, timezone
7 from sqlalchemy.ext.asyncio import AsyncSession
8
9 from muse.core.types import blob_id
10 from musehub.db.musehub_repo_models import MusehubBranch, MusehubCommit, MusehubCommitRef, MusehubSnapshot, MusehubSnapshotRef
11 from musehub.types.json_types import JSONObject
12 from tests.factories import create_repo
13
14
15 def _utc() -> datetime:
16 return datetime.now(tz=timezone.utc)
17
18
19 async def _add_snapshot(session: AsyncSession, repo_id: str, seed: str, manifest: JSONObject) -> str:
20 snap_id = blob_id(f"snap-{seed}".encode())
21 session.add(MusehubSnapshot(
22 snapshot_id=snap_id,
23 directories=[],
24 manifest_blob=msgpack.packb(manifest, use_bin_type=True),
25 entry_count=len(manifest),
26 created_at=_utc(),
27 ))
28 session.add(MusehubSnapshotRef(repo_id=repo_id, snapshot_id=snap_id))
29 await session.commit()
30 return snap_id
31
32
33 async def _add_commit(session: AsyncSession, repo_id: str, seed: str, snap_id: str, **kwargs: typing.Any) -> MusehubCommit:
34 row = MusehubCommit(
35 commit_id=blob_id(seed.encode()),
36 branch="dev",
37 parent_ids=[],
38 message=f"feat: {seed}",
39 author="gabriel",
40 timestamp=_utc(),
41 snapshot_id=snap_id,
42 **kwargs,
43 )
44 session.add(row)
45 session.add(MusehubCommitRef(repo_id=repo_id, commit_id=row.commit_id))
46 session.add(MusehubBranch(
47 branch_id=blob_id(f"br-{seed}".encode()),
48 repo_id=repo_id,
49 name="dev",
50 head_commit_id=row.commit_id,
51 ))
52 await session.commit()
53 return row
54
55
56 # ---------------------------------------------------------------------------
57 # SI1 — index_new_commits does not crash with AttributeError on commit_meta
58 # ---------------------------------------------------------------------------
59
60 @pytest.mark.asyncio
61 async def test_si1_index_new_commits_no_commit_meta(
62 db_session: AsyncSession,
63 ) -> None:
64 """Symbol indexer must not raise AttributeError on commit.commit_meta."""
65 from musehub.services.musehub_symbol_indexer import build_symbol_index
66
67 repo = await create_repo(db_session, owner="gabriel", visibility="public")
68 oid = blob_id(b"file-content")
69 snap_id = await _add_snapshot(db_session, repo.repo_id, "si1", {"src/app.py": oid})
70 commit = await _add_commit(db_session, repo.repo_id, "si1-c1", snap_id,
71 agent_id="claude-code", model_id="claude-sonnet-4-6")
72
73 # Must not raise — falls back to snapshot diffing since no structured_delta
74 await build_symbol_index(db_session, repo.repo_id, commit.commit_id)
75
76
77 # ---------------------------------------------------------------------------
78 # SI2 — re-index path does not crash with AttributeError on commit_meta
79 # ---------------------------------------------------------------------------
80
81 @pytest.mark.asyncio
82 async def test_si2_reindex_no_commit_meta(
83 db_session: AsyncSession,
84 ) -> None:
85 """Re-index path must not raise AttributeError on commit_meta column select."""
86 from musehub.services.musehub_symbol_indexer import backfill_raw_ops_from_commits
87
88 repo = await create_repo(db_session, owner="gabriel", visibility="public")
89 oid = blob_id(b"reindex-content")
90 snap_id = await _add_snapshot(db_session, repo.repo_id, "si2", {"src/main.py": oid})
91 await _add_commit(db_session, repo.repo_id, "si2-c1", snap_id)
92
93 # Must not raise even with no structured_delta
94 await backfill_raw_ops_from_commits(db_session, repo.repo_id)
File History 7 commits
sha256:ef10830ce231e0a20efcb0e2586cb879471247e916616e6fdd0d51df459e2595 fix: typing audit — 0 violations, 0 untyped defs across all… Sonnet 4.6 minor ⚠ 172 days ago
sha256:b8884c81af5e135510894a537784c16158ee9c2c05d074f978611bbcb611ca10 fix: port security checks inline, remove repo_id from Museh… Sonnet 4.6 minor ⚠ 181 days ago
sha256:2e9f6b5cc193e07b2c23d17fb71851db72e6160ba472013f5bccab8351264e79 refactor: migrate all musehub_models shim call sites to dom… Sonnet 4.6 minor ⚠ 188 days ago
sha256:c381a474ad0fc45130d1c9d0955178b9837beed4794c06326b082fdbf7dff46b fix(tests): fix all failing tests; bump to 0.2.0rc7; update docs Sonnet 4.6 minor ⚠ 195 days ago
sha256:3a29a6fd5c0da6ed1e40a498f5c491bee45c684b34936b55e64be6b76413cb52 refactor(tests): eliminate _sha/_sha256_oid/_blob_id wrappe… Sonnet 4.6 196 days ago
sha256:7918558cb69109fcd34288d56f1937ef56f739f117e9ed22bd8c8b8bf8e9567e refactor: route all sha256 ID construction through long_id(… Sonnet 4.6 patch 196 days ago
sha256:2999a8016059a56c67e6da3112199decfc082b39417d731c2963e3d288a5e7a8 fix: symbol indexer drops commit_meta reads; structured_del… Sonnet 4.6 patch 196 days ago