gabriel / musehub public
test_ui_view_no_commit_meta.py python
102 lines 3.4 KB
Raw
sha256:34035d72cef530c1ab9d6a6f53be18d803dde705fc3157617d70352a96d0747b Merge branch 'fix/wire-push-external-parent-manifest' into dev Human 8 days ago
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
File History 14 commits
sha256:34035d72cef530c1ab9d6a6f53be18d803dde705fc3157617d70352a96d0747b Merge branch 'fix/wire-push-external-parent-manifest' into dev Human 8 days ago
sha256:fc04e4cae9e1774d6a21b65c45daeed0e6787eb581d13aa1b03bfe9384a34226 Merge branch 'fix/two-column-scroll-layout' into dev Human 8 days ago
sha256:408916fc5973ba59c6e4eebaa80ebdcc801c0a63205651e25009d11548f79454 chore: bump version to 0.2.0.dev2 — nightly.2, matching muse Sonnet 4.6 patch 11 days ago
sha256:d035733f21ccff27735fddebfbbe0ed24565a32a22db8de5885402262671ecd2 chore: bump version to 0.2.0rc15 for musehub#113 fix release Sonnet 4.6 patch 14 days ago
sha256:0032d6cfa33bc3c8367436ad768e7dd0e339b4332153160247da8266cb5fa352 Merge branch 'task/version-tags-phase3-server' into dev Human 17 days ago
sha256:4669620efda9ff41c55bdefd1f7bfe1c239d468428744c84ead9957e5a003a53 merge: rescue snapshot-recovery hardening (c00aa21d) into d… Opus 4.8 minor 29 days ago
sha256:a59da49c4611b970fc4b6ae48678ce4943261c213a07ddbd73ce9201df869b4a fix: remove false-positive proposal_comments index drop fro… Sonnet 4.6 patch 33 days ago
sha256:0a240d6dbff234f07d98a28a4a9a68db702f3f9ff9260196f24219bdb1c0b6f3 feat: render markdown mists as HTML with heading anchor links Sonnet 4.6 patch 34 days ago
sha256:24a7d47486ebc4ebd1832830580e177ec6f877b48dced8c000e198cdec4ce9d6 Merge 'task/bump-version-rc12' into 'dev' — proposal: Bump … Human 35 days ago
sha256:b9ff931d147e0114a1f17060f415b89ed551c170a91ff226c70437aa5c85f9ee Merge 'task/bump-version-rc12' into 'dev' — proposal: Bump … Human 35 days ago
sha256:d1122d21e73471879b460037b22c0b50fded7c423444a176f248428f75dac39c Merge 'task/fix-issue-pagination-cursor' into 'dev' — propo… Human 35 days ago
sha256:01e18975e73d2b3cd5b6db7929c895bef9aa6e0d4391dc5b2adfc548b41318dd Merge 'feat/adding-debug-logs-to-staging' into 'dev' — prop… Human 35 days ago
sha256:6b1949fc2797ca4c1936a637a4cbfec828ef56cf52398a2e74ca3c4f494e728f fix: use wire_bytes not mpack_bytes_raw in compute_object_b… Sonnet 4.6 patch 48 days ago
sha256:b99f2455dc346966d040133f5203297e6e3ef5803a93728a2c30568d0a0f7583 rename: delta_add → delta_upsert across wire format, models… Sonnet 4.6 patch 50 days ago