"""TDD — ui_user_profile must not query via commit_meta JSON path.""" 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)) await session.commit() return row # --------------------------------------------------------------------------- # UP1 — user profile route does not crash with AttributeError on commit_meta # --------------------------------------------------------------------------- @pytest.mark.asyncio async def test_up1_user_profile_no_commit_meta_error( db_session: AsyncSession, client: AsyncClient, auth_headers: Mapping[str, str], ) -> None: """User profile page must not raise AttributeError on commit_meta JSON path queries.""" repo = await create_repo(db_session, owner="gabriel", visibility="public") await _add_commit( db_session, repo.repo_id, "up-human-c1", agent_id="", model_id="", ) await _add_commit( db_session, repo.repo_id, "up-agent-c1", agent_id="claude-code", model_id="claude-sonnet-4-6", ) resp = await client.get( "/gabriel", headers=auth_headers, follow_redirects=True, ) assert resp.status_code != 500 # --------------------------------------------------------------------------- # UP2 — agent profile route does not crash with AttributeError on commit_meta # --------------------------------------------------------------------------- @pytest.mark.asyncio async def test_up2_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 JSON path queries.""" repo = await create_repo(db_session, owner="gabriel", visibility="public") await _add_commit( db_session, repo.repo_id, "up-agent-prof-c1", agent_id="claude-code", model_id="claude-sonnet-4-6", ) resp = await client.get( "/claude-code", headers=auth_headers, follow_redirects=True, ) assert resp.status_code != 500