"""Phase 6 TDD: HTML docs page at /muse/mists. Tests are written RED first. Run before touching ui_docs.py and creating the template to confirm failure, then implement. Work: 1. Add 'mists' entry to _PHASES in ui_docs.py. 2. Add GET /muse/mists route handler. 3. Create musehub/templates/musehub/pages/docs_muse_mists.html. 4. Link /muse/mists from the /muse index page. Tests operate against the live app client fixture (no DB state needed). """ from __future__ import annotations import pytest from httpx import AsyncClient class TestDocsMistsPage: @pytest.mark.asyncio async def test_docs_mists_page_returns_200(self, client: AsyncClient) -> None: """GET /muse/mists must return 200 with text/html content-type.""" r = await client.get("/muse/mists") assert r.status_code == 200, ( f"Expected 200 from GET /muse/mists; got {r.status_code}" ) assert "text/html" in r.headers.get("content-type", ""), ( "Expected HTML response from /muse/mists" ) @pytest.mark.asyncio async def test_docs_mists_page_contains_mist_keyword( self, client: AsyncClient ) -> None: """Page body must contain 'Mist' (the domain name).""" r = await client.get("/muse/mists") assert r.status_code == 200 assert "Mist" in r.text, "Page must contain the keyword 'Mist'" @pytest.mark.asyncio async def test_docs_mists_page_contains_artifact_keyword( self, client: AsyncClient ) -> None: """Page body must contain 'artifact' (core Mist concept).""" r = await client.get("/muse/mists") assert r.status_code == 200 assert "artifact" in r.text, "Page must contain the keyword 'artifact'" @pytest.mark.asyncio async def test_docs_mists_page_contains_content_addressed( self, client: AsyncClient ) -> None: """Page body must contain 'content-addressed'.""" r = await client.get("/muse/mists") assert r.status_code == 200 assert "content-addressed" in r.text, ( "Page must contain the keyword 'content-addressed'" ) @pytest.mark.asyncio async def test_docs_mists_page_contains_api_section( self, client: AsyncClient ) -> None: """Page must document the REST API surface (POST /api/mists etc.).""" r = await client.get("/muse/mists") assert r.status_code == 200 assert "/api/mists" in r.text, ( "Page must reference the /api/mists REST endpoint" ) @pytest.mark.asyncio async def test_docs_mists_page_contains_security_section( self, client: AsyncClient ) -> None: """Page must cover the security model.""" r = await client.get("/muse/mists") assert r.status_code == 200 assert "security" in r.text.lower(), ( "Page must contain a security section" ) @pytest.mark.asyncio async def test_docs_mists_page_has_sidebar_nav( self, client: AsyncClient ) -> None: """Page must render the sidebar navigation present on all doc pages.""" r = await client.get("/muse/mists") assert r.status_code == 200 assert "devdocs-nav" in r.text, ( "Page must include the devdocs sidebar nav (devdocs-nav class)" ) class TestDocsIndexLinksMists: @pytest.mark.asyncio async def test_docs_index_links_to_mists(self, client: AsyncClient) -> None: """GET /muse must contain a link to /muse/mists.""" r = await client.get("/muse") assert r.status_code == 200 assert "/muse/mists" in r.text, ( "The /muse index page must link to /muse/mists" ) @pytest.mark.asyncio async def test_docs_index_mists_entry_has_description( self, client: AsyncClient ) -> None: """The /muse index card for mists must include a non-empty description.""" r = await client.get("/muse") assert r.status_code == 200 # The index renders phase cards from _PHASES — each has a description. # Confirm the mists page is referenced alongside a meaningful description. assert "Mist" in r.text, ( "The /muse index must mention 'Mist' in a nav card or description" ) class TestDocsMistsRouteRegistration: def test_mists_slug_in_phases_list(self) -> None: """'mists' slug must appear in the _PHASES list in ui_docs.py.""" from musehub.api.routes.musehub.ui_docs import _PHASES slugs = [slug for slug, *_ in _PHASES] assert "mists" in slugs, ( f"'mists' must be in _PHASES slugs; got {slugs}" ) def test_docs_mists_route_exists(self) -> None: """The docs_mists route function must be defined in ui_docs.""" import musehub.api.routes.musehub.ui_docs as _mod assert hasattr(_mod, "docs_mists"), ( "ui_docs.py must define a 'docs_mists' route handler" )