gabriel / musehub public
test_repository_no_commit_meta.py python
98 lines 3.5 KB
Raw
sha256:ef10830ce231e0a20efcb0e2586cb879471247e916616e6fdd0d51df459e2595 fix: typing audit — 0 violations, 0 untyped defs across all… Sonnet 4.6 minor ⚠ breaking 23 days ago
1 """TDD — musehub_repository 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 musehub.db.musehub_repo_models import MusehubBranch, MusehubCommit, MusehubCommitRef, MusehubSnapshot, MusehubSnapshotRef
10 from musehub.types.json_types import JSONObject
11 from tests.factories import create_repo
12 from muse.core.types import blob_id
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 | None = None, **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 # RR1 — get_dag_graph does not crash with AttributeError on commit_meta
58 # ---------------------------------------------------------------------------
59
60 @pytest.mark.asyncio
61 async def test_rr1_dag_graph_no_commit_meta(
62 db_session: AsyncSession,
63 ) -> None:
64 """get_dag_graph must not raise AttributeError on commit_meta column."""
65 from musehub.services.musehub_repository import list_commits_dag
66
67 repo = await create_repo(db_session, owner="gabriel", visibility="public")
68 await _add_commit(
69 db_session, repo.repo_id, "rr1-c1",
70 agent_id="claude-code", model_id="claude-sonnet-4-6",
71 sem_ver_bump="minor",
72 )
73
74 result = await list_commits_dag(db_session, repo.repo_id)
75 assert result is not None
76 assert len(result.nodes) >= 1
77
78
79 # ---------------------------------------------------------------------------
80 # RR2 — _commit_record (via get_file_last_commits) does not crash
81 # ---------------------------------------------------------------------------
82
83 @pytest.mark.asyncio
84 async def test_rr2_file_last_commits_no_commit_meta(
85 db_session: AsyncSession,
86 ) -> None:
87 """get_file_last_commits must not raise AttributeError on commit_meta."""
88 from musehub.services.musehub_repository import get_file_last_commits
89
90 repo = await create_repo(db_session, owner="gabriel", visibility="public")
91 snap_id = await _add_snapshot(db_session, repo.repo_id, "rr2", {"src/app.py": blob_id(b"content")})
92 await _add_commit(
93 db_session, repo.repo_id, "rr2-c1", snap_id,
94 agent_id="claude-code", model_id="claude-sonnet-4-6",
95 )
96
97 result = await get_file_last_commits(db_session, repo.repo_id, paths=["src/app.py"])
98 assert isinstance(result, dict)
File History 1 commit
sha256:ef10830ce231e0a20efcb0e2586cb879471247e916616e6fdd0d51df459e2595 fix: typing audit — 0 violations, 0 untyped defs across all… Sonnet 4.6 minor 23 days ago