test_musehub_ui_proposal_ssr.py
python
sha256:34035d72cef530c1ab9d6a6f53be18d803dde705fc3157617d70352a96d0747b
Merge branch 'fix/wire-push-external-parent-manifest' into dev
Human
8 days ago
| 1 | """SSR tests for MuseHub proposal list + proposal detail pages — issue #569. |
| 2 | |
| 3 | Validates that proposal data is rendered server-side into HTML (not deferred to client |
| 4 | JS) and that HTMX fragment requests return bare HTML without the full page shell. |
| 5 | |
| 6 | Covers GET /{owner}/{repo_slug}/proposals: |
| 7 | - test_proposal_list_renders_title_server_side — proposal title appears in HTML |
| 8 | - test_proposal_list_open_closed_counts_in_tabs — tab counts reflect seeded proposals |
| 9 | - test_proposal_list_htmx_fragment_on_tab_switch — HX-Request: true → fragment |
| 10 | |
| 11 | Covers GET /{owner}/{repo_slug}/proposals/{proposal_id}: |
| 12 | - test_proposal_detail_renders_title_server_side — proposal title in HTML server-side |
| 13 | - test_proposal_detail_renders_diff_stats — branch info in HTML |
| 14 | - test_proposal_detail_shows_cli_hint — CLI hint replaces write-capable form |
| 15 | - test_proposal_detail_unknown_number_404 — non-existent proposal_id → 404 |
| 16 | """ |
| 17 | from __future__ import annotations |
| 18 | |
| 19 | import pytest |
| 20 | from httpx import AsyncClient |
| 21 | from sqlalchemy.ext.asyncio import AsyncSession |
| 22 | |
| 23 | from muse.core.types import now_utc_iso |
| 24 | from musehub.core.genesis import compute_identity_id, compute_proposal_id, compute_repo_id |
| 25 | from musehub.db.musehub_repo_models import MusehubRepo |
| 26 | from musehub.db.musehub_social_models import MusehubProposal |
| 27 | |
| 28 | |
| 29 | # --------------------------------------------------------------------------- |
| 30 | # Seed helpers |
| 31 | # --------------------------------------------------------------------------- |
| 32 | |
| 33 | |
| 34 | async def _make_repo( |
| 35 | db: AsyncSession, |
| 36 | owner: str = "proposaldev", |
| 37 | slug: str = "proposal-ssr-album", |
| 38 | ) -> str: |
| 39 | """Seed a public repo and return its repo_id string.""" |
| 40 | from datetime import datetime, timezone |
| 41 | created_at = datetime.now(tz=timezone.utc) |
| 42 | owner_id = compute_identity_id(owner.encode()) |
| 43 | repo_id = compute_repo_id(owner_id, slug, "code", created_at.isoformat()) |
| 44 | repo = MusehubRepo( |
| 45 | repo_id=repo_id, |
| 46 | name=slug, |
| 47 | owner=owner, |
| 48 | slug=slug, |
| 49 | visibility="public", |
| 50 | owner_user_id=owner_id, |
| 51 | created_at=created_at, |
| 52 | updated_at=created_at, |
| 53 | ) |
| 54 | db.add(repo) |
| 55 | await db.commit() |
| 56 | await db.refresh(repo) |
| 57 | return str(repo.repo_id) |
| 58 | |
| 59 | |
| 60 | async def _make_proposal( |
| 61 | db: AsyncSession, |
| 62 | repo_id: str, |
| 63 | *, |
| 64 | proposal_number: int = 1, |
| 65 | title: str = "Add bossa nova bridge", |
| 66 | body: str = "Adds a new bossa nova bridge section.", |
| 67 | state: str = "open", |
| 68 | from_branch: str = "feat/bossa-nova", |
| 69 | to_branch: str = "main", |
| 70 | author: str = "beatmaker", |
| 71 | ) -> MusehubProposal: |
| 72 | """Seed a proposal and return the ORM object.""" |
| 73 | from datetime import datetime, timezone |
| 74 | author_id = compute_identity_id(author.encode()) |
| 75 | proposal = MusehubProposal( |
| 76 | proposal_id=compute_proposal_id(repo_id, author_id, from_branch, to_branch, now_utc_iso()), |
| 77 | repo_id=repo_id, |
| 78 | proposal_number=proposal_number, |
| 79 | title=title, |
| 80 | body=body, |
| 81 | state=state, |
| 82 | from_branch=from_branch, |
| 83 | to_branch=to_branch, |
| 84 | author=author, |
| 85 | ) |
| 86 | db.add(proposal) |
| 87 | await db.commit() |
| 88 | await db.refresh(proposal) |
| 89 | return proposal |
| 90 | |
| 91 | |
| 92 | # --------------------------------------------------------------------------- |
| 93 | # Proposal list SSR tests |
| 94 | # --------------------------------------------------------------------------- |
| 95 | |
| 96 | |
| 97 | async def test_proposal_list_renders_title_server_side( |
| 98 | client: AsyncClient, |
| 99 | db_session: AsyncSession, |
| 100 | ) -> None: |
| 101 | """Proposal title is rendered into the HTML response server-side without client JS.""" |
| 102 | repo_id = await _make_repo(db_session) |
| 103 | await _make_proposal(db_session, repo_id, title="Funk bridge with wah pedal") |
| 104 | response = await client.get("/proposaldev/proposal-ssr-album/proposals") |
| 105 | assert response.status_code == 200 |
| 106 | assert "text/html" in response.headers["content-type"] |
| 107 | assert "Funk bridge with wah pedal" in response.text |
| 108 | |
| 109 | |
| 110 | async def test_proposal_list_open_closed_counts_in_tabs( |
| 111 | client: AsyncClient, |
| 112 | db_session: AsyncSession, |
| 113 | ) -> None: |
| 114 | """State tabs display SSR-computed open/merged/closed counts.""" |
| 115 | repo_id = await _make_repo(db_session) |
| 116 | await _make_proposal(db_session, repo_id, proposal_number=1, title="Open proposal 1", state="open") |
| 117 | await _make_proposal(db_session, repo_id, proposal_number=2, title="Open proposal 2", state="open") |
| 118 | await _make_proposal(db_session, repo_id, proposal_number=3, title="Merged proposal", state="merged") |
| 119 | response = await client.get("/proposaldev/proposal-ssr-album/proposals") |
| 120 | assert response.status_code == 200 |
| 121 | body = response.text |
| 122 | # Tab counts for open and merged must appear as server-rendered numbers. |
| 123 | assert "2" in body # open_count |
| 124 | assert "1" in body # merged_count |
| 125 | |
| 126 | |
| 127 | async def test_proposal_list_htmx_fragment_on_tab_switch( |
| 128 | client: AsyncClient, |
| 129 | db_session: AsyncSession, |
| 130 | ) -> None: |
| 131 | """HX-Request: true with state=merged returns a bare HTML fragment.""" |
| 132 | repo_id = await _make_repo(db_session) |
| 133 | await _make_proposal(db_session, repo_id, title="Merged feature", state="merged") |
| 134 | response = await client.get( |
| 135 | "/proposaldev/proposal-ssr-album/proposals?state=merged", |
| 136 | headers={"HX-Request": "true"}, |
| 137 | ) |
| 138 | assert response.status_code == 200 |
| 139 | body = response.text |
| 140 | # Fragment must NOT contain the full HTML page shell. |
| 141 | assert "<html" not in body |
| 142 | assert "<head" not in body |
| 143 | # Proposal title must appear in the fragment. |
| 144 | assert "Merged feature" in body |
| 145 | |
| 146 | |
| 147 | # --------------------------------------------------------------------------- |
| 148 | # Proposal detail SSR tests |
| 149 | # --------------------------------------------------------------------------- |
| 150 | |
| 151 | |
| 152 | async def test_proposal_detail_renders_title_server_side( |
| 153 | client: AsyncClient, |
| 154 | db_session: AsyncSession, |
| 155 | ) -> None: |
| 156 | """Proposal title and branch info appear in the detail page HTML server-side.""" |
| 157 | repo_id = await _make_repo(db_session) |
| 158 | proposal = await _make_proposal( |
| 159 | db_session, repo_id, title="Add jazz chord voicings", from_branch="feat/jazz" |
| 160 | ) |
| 161 | response = await client.get(f"/proposaldev/proposal-ssr-album/proposals/{proposal.proposal_id}") |
| 162 | assert response.status_code == 200 |
| 163 | assert "text/html" in response.headers["content-type"] |
| 164 | assert "Add jazz chord voicings" in response.text |
| 165 | |
| 166 | |
| 167 | async def test_proposal_detail_renders_diff_stats( |
| 168 | client: AsyncClient, |
| 169 | db_session: AsyncSession, |
| 170 | ) -> None: |
| 171 | """Branch names (from_branch / to_branch) appear in the detail page HTML.""" |
| 172 | repo_id = await _make_repo(db_session) |
| 173 | proposal = await _make_proposal( |
| 174 | db_session, |
| 175 | repo_id, |
| 176 | title="Bass groove proposal", |
| 177 | from_branch="feat/bass-groove", |
| 178 | to_branch="dev", |
| 179 | ) |
| 180 | response = await client.get(f"/proposaldev/proposal-ssr-album/proposals/{proposal.proposal_id}") |
| 181 | assert response.status_code == 200 |
| 182 | body = response.text |
| 183 | # Both branch names must appear in the server-rendered HTML. |
| 184 | assert "feat/bass-groove" in body |
| 185 | assert "dev" in body |
| 186 | |
| 187 | |
| 188 | async def test_proposal_detail_shows_cli_hint( |
| 189 | client: AsyncClient, |
| 190 | db_session: AsyncSession, |
| 191 | ) -> None: |
| 192 | """The proposal detail page shows CLI merge hints instead of write-capable HTMX forms.""" |
| 193 | repo_id = await _make_repo(db_session) |
| 194 | proposal = await _make_proposal(db_session, repo_id, title="CLI-hint proposal", state="open") |
| 195 | response = await client.get(f"/proposaldev/proposal-ssr-album/proposals/{proposal.proposal_id}") |
| 196 | assert response.status_code == 200 |
| 197 | body = response.text |
| 198 | # MSign is stateless — no write forms; CLI hint must be present instead. |
| 199 | assert "hx-post" not in body |
| 200 | assert "muse hub proposal" in body.lower() |
| 201 | |
| 202 | |
| 203 | async def test_proposal_detail_unknown_number_404( |
| 204 | client: AsyncClient, |
| 205 | db_session: AsyncSession, |
| 206 | ) -> None: |
| 207 | """A request for a non-existent proposal id returns HTTP 404.""" |
| 208 | await _make_repo(db_session) |
| 209 | response = await client.get( |
| 210 | "/proposaldev/proposal-ssr-album/proposals/nonexistent-proposal-id" |
| 211 | ) |
| 212 | assert response.status_code == 404 |
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