gabriel / musehub public

test_ui_view_no_commit_meta.py file-level

at sha256:2 · View file ↗ · Intel ↗

History
1 files
1 commits
0 hotspots
0 🧊 dead
0 💥 blast risk
sha256:0 fix: fall back to any indexed mpack in read_object_bytes when push mpac… · gabriel · Jun 17, 2026
1 """TDD — ui_view helpers must not read commit_meta (dropped in migration 0020).
2
3 Covers:
4 V1 _slim_commit reads agent_id from first-class column
5 V2 _compute_code_insights SELECT doesn't reference commit_meta
6 V3 _compute_code_insights counts agent commits via agent_id column
7 V4 _compute_code_insights reads sem_ver_bump from column
8 """
9 from __future__ import annotations
10
11 import pytest
12 from datetime import datetime, timezone
13 from sqlalchemy.ext.asyncio import AsyncSession
14
15 from musehub.db import musehub_repo_models as db
16 from muse.core.types import blob_id
17
18
19 def _utc() -> datetime:
20 return datetime.now(tz=timezone.utc)
21
22
23 async def _make_repo(session: AsyncSession, slug: str) -> str:
24 from musehub.core.genesis import compute_identity_id, compute_repo_id
25 owner = "gabriel"
26 uid = compute_identity_id(owner.encode())
27 created_at = _utc()
28 repo_id = compute_repo_id(uid, slug, "code", created_at.isoformat())
29 session.add(db.MusehubRepo(
30 repo_id=repo_id, name=slug, owner=owner, slug=slug,
31 visibility="public", owner_user_id=uid,
32 description="", tags=[], created_at=created_at,
33 ))
34 await session.commit()
35 return repo_id
36
37
38 async def _add_commit(
39 session: AsyncSession,
40 repo_id: str,
41 seed: str,
42 *,
43 agent_id: str = "",
44 sem_ver_bump: str = "none",
45 breaking_changes: list[str] | None = None,
46 ) -> db.MusehubCommit:
47 row = db.MusehubCommit(
48 commit_id=blob_id(seed.encode()),
49 branch="dev",
50 parent_ids=[],
51 message=f"feat: {seed}",
52 author="gabriel",
53 timestamp=_utc(),
54 agent_id=agent_id,
55 sem_ver_bump=sem_ver_bump,
56 breaking_changes=breaking_changes or [],
57 )
58 session.add(row)
59 session.add(db.MusehubCommitRef(repo_id=repo_id, commit_id=row.commit_id))
60 await session.commit()
61 await session.refresh(row)
62 return row
63
64
65 # ---------------------------------------------------------------------------
66 # V1 — _slim_commit reads agent_id from column, not commit_meta
67 # ---------------------------------------------------------------------------
68
69 @pytest.mark.asyncio
70 async def test_v1_slim_commit_reads_agent_id_from_column(
71 db_session: AsyncSession,
72 ) -> None:
73 from musehub.api.routes.musehub.ui_view import _slim_commit
74
75 repo_id = await _make_repo(db_session, "view-slim-001")
76 row = await _add_commit(db_session, repo_id, "slim-v1", agent_id="claude-code")
77
78 result = _slim_commit(row)
79
80 assert result["agentId"] == "claude-code"
81 assert result["id"] == row.commit_id
82
83
84 # ---------------------------------------------------------------------------
85 # V2+V3+V4 — _compute_code_insights doesn't touch commit_meta
86 # ---------------------------------------------------------------------------
87
88 @pytest.mark.asyncio
89 async def test_v2_code_insights_no_commit_meta_error(
90 db_session: AsyncSession,
91 ) -> None:
92 """_compute_code_insights must not raise AttributeError on commit_meta."""
93 from musehub.api.routes.musehub.ui_view import _compute_code_insights
94
95 repo_id = await _make_repo(db_session, "view-insights-001")
96 await _add_commit(db_session, repo_id, "ins-a", agent_id="claude-code", sem_ver_bump="minor")
97 await _add_commit(db_session, repo_id, "ins-b", agent_id="", sem_ver_bump="patch")
98
99 result = await _compute_code_insights(db_session, repo_id)
100 assert result["agent_count"] == 1
101 assert result["semver_counts"]["minor"] == 1
102 assert result["semver_counts"]["patch"] == 1