gabriel / musehub public
test_ui_repo_no_commit_meta.py python
93 lines 3.1 KB
Raw
sha256:ef10830ce231e0a20efcb0e2586cb879471247e916616e6fdd0d51df459e2595 fix: typing audit — 0 violations, 0 untyped defs across all… Sonnet 4.6 minor ⚠ breaking 20 days ago
1 """TDD — ui_repo commit enrichment must not read commit_meta."""
2 from __future__ import annotations
3
4 import typing
5 from collections.abc import Mapping
6 from datetime import datetime, timezone
7
8 import pytest
9 from httpx import AsyncClient
10 from muse.core.types import blob_id
11 from sqlalchemy.ext.asyncio import AsyncSession
12
13 from musehub.db import musehub_repo_models as db
14 from tests.factories import create_repo
15
16
17 def _utc() -> datetime:
18 return datetime.now(tz=timezone.utc)
19
20
21 async def _add_commit(session: AsyncSession, repo_id: str, seed: str, **kwargs: typing.Any) -> db.MusehubCommit:
22 row = db.MusehubCommit(
23 commit_id=blob_id(seed.encode()),
24 branch="dev",
25 parent_ids=[],
26 message=f"feat: {seed}",
27 author="gabriel",
28 timestamp=_utc(),
29 **kwargs,
30 )
31 session.add(row)
32 session.add(db.MusehubCommitRef(repo_id=repo_id, commit_id=row.commit_id))
33 await session.commit()
34 return row
35
36
37 # ---------------------------------------------------------------------------
38 # R1 — ORM row has first-class columns, not commit_meta
39 # ---------------------------------------------------------------------------
40
41 @pytest.mark.asyncio
42 async def test_r1_musehub_commit_has_no_commit_meta_attribute(
43 db_session: AsyncSession,
44 ) -> None:
45 """MusehubCommit ORM row must expose agent_id/sem_ver_bump/etc. and not commit_meta."""
46 repo = await create_repo(db_session, owner="gabriel", visibility="public")
47 row = await _add_commit(
48 db_session, repo.repo_id, "repo-col-check",
49 agent_id="claude-code", model_id="claude-sonnet-4-6",
50 sem_ver_bump="minor", breaking_changes=[], toolchain_id="muse-1",
51 test_runs=2, reviewed_by=[],
52 )
53 await db_session.refresh(row)
54
55 assert not hasattr(row, "commit_meta"), "commit_meta must not exist on ORM row"
56 assert row.agent_id == "claude-code"
57 assert row.model_id == "claude-sonnet-4-6"
58 assert row.sem_ver_bump == "minor"
59 assert row.test_runs == 2
60 assert row.toolchain_id == "muse-1"
61
62
63 # ---------------------------------------------------------------------------
64 # R2 — route GET /owner/slug does not crash with AttributeError
65 # ---------------------------------------------------------------------------
66
67 @pytest.mark.asyncio
68 async def test_r2_repo_route_no_commit_meta_error(
69 db_session: AsyncSession,
70 client: AsyncClient,
71 auth_headers: Mapping[str, str],
72 ) -> None:
73 """Repo page must not raise AttributeError on commit_meta when enriching commits."""
74 repo = await create_repo(db_session, owner="gabriel", visibility="public")
75 commit = await _add_commit(
76 db_session, repo.repo_id, "repo-route-c1",
77 agent_id="claude-code", model_id="claude-sonnet-4-6",
78 sem_ver_bump="patch",
79 )
80 db_session.add(db.MusehubBranch(
81 branch_id=blob_id(b"repo-route-branch"),
82 repo_id=repo.repo_id,
83 name="dev",
84 head_commit_id=commit.commit_id,
85 ))
86 await db_session.commit()
87
88 resp = await client.get(
89 f"/gabriel/{repo.slug}",
90 headers=auth_headers,
91 follow_redirects=True,
92 )
93 assert resp.status_code == 200
File History 1 commit
sha256:ef10830ce231e0a20efcb0e2586cb879471247e916616e6fdd0d51df459e2595 fix: typing audit — 0 violations, 0 untyped defs across all… Sonnet 4.6 minor 20 days ago