"""TDD — ui_agents must not read commit_meta.""" from __future__ import annotations import typing from collections.abc import Mapping from datetime import datetime, timezone import pytest from httpx import AsyncClient from muse.core.types import blob_id from sqlalchemy.ext.asyncio import AsyncSession from musehub.db import musehub_repo_models as db from tests.factories import create_repo def _utc() -> datetime: return datetime.now(tz=timezone.utc) async def _add_commit(session: AsyncSession, repo_id: str, seed: str, **kwargs: typing.Any) -> db.MusehubCommit: row = db.MusehubCommit( commit_id=blob_id(seed.encode()), branch="dev", parent_ids=[], message=f"feat: {seed}", author="gabriel", timestamp=_utc(), **kwargs, ) session.add(row) session.add(db.MusehubCommitRef(repo_id=repo_id, commit_id=row.commit_id)) session.add(db.MusehubBranch( branch_id=blob_id(f"br-{seed}".encode()), repo_id=repo_id, name="dev", head_commit_id=row.commit_id, )) await session.commit() return row # --------------------------------------------------------------------------- # AG1 — agent profile route does not crash with AttributeError on commit_meta # --------------------------------------------------------------------------- @pytest.mark.asyncio async def test_ag1_agent_profile_no_commit_meta_error( db_session: AsyncSession, client: AsyncClient, auth_headers: Mapping[str, str], ) -> None: """Agent profile page must not raise AttributeError on commit_meta reads.""" repo = await create_repo(db_session, owner="gabriel", visibility="public") await _add_commit( db_session, repo.repo_id, "ag-c1", agent_id="claude-code", model_id="claude-sonnet-4-6", toolchain_id="muse-1", ) resp = await client.get( f"/gabriel/{repo.slug}/agents/claude-code", headers=auth_headers, follow_redirects=True, ) assert resp.status_code != 500