gabriel / musehub public
test_musehub_js_cleanup.py python
162 lines 6.8 KB
Raw
sha256:d035733f21ccff27735fddebfbbe0ed24565a32a22db8de5885402262671ecd2 chore: bump version to 0.2.0rc15 for musehub#113 fix release Sonnet 4.6 patch 15 days ago
1 """Regression tests for the musehub.js cleanup (issue #586).
2
3 Verifies that displaced client-side rendering code has been removed from
4 musehub.js and all Jinja2 templates after the complete HTMX/SSR migration.
5
6 Covers:
7 - test_musehub_js_does_not_contain_render_rows — renderRows not in musehub.js
8 - test_musehub_js_does_not_contain_build_bulk_toolbar — buildBulkToolbar not in musehub.js
9 - test_musehub_js_does_not_contain_render_filter_sidebar — renderFilterSidebar not in musehub.js
10 - test_explore_base_html_deleted — explore_base.html has been removed
11 - test_all_template_page_script_blocks_empty_or_minimal — no legacy data-fetching
12 patterns survive in any page template
13 """
14
15 from __future__ import annotations
16
17 import pathlib
18
19
20 # ── Paths ─────────────────────────────────────────────────────────────────────
21
22 _REPO_ROOT = pathlib.Path(__file__).parent.parent
23 _MUSEHUB_JS = _REPO_ROOT / "musehub" / "templates" / "musehub" / "static" / "musehub.js"
24 _TEMPLATE_ROOT = _REPO_ROOT / "musehub" / "templates" / "musehub"
25 _EXPLORE_BASE = _TEMPLATE_ROOT / "explore_base.html"
26
27 # ── Helpers ───────────────────────────────────────────────────────────────────
28
29 def _musehub_js_text() -> str:
30 """Return the full text of musehub.js, or empty string if absent."""
31 if not _MUSEHUB_JS.exists():
32 return ""
33 return _MUSEHUB_JS.read_text(encoding="utf-8")
34
35
36 def _all_page_templates() -> list[pathlib.Path]:
37 """Return all .html files under the musehub pages/ directory.
38
39 user_profile.html is an intentional CSR shell (all data fetched
40 client-side so the page loads instantly and stays auth-agnostic).
41 It is excluded from the SSR-pattern enforcement check.
42 """
43 pages_dir = _TEMPLATE_ROOT / "pages"
44 _CSR_SHELLS = {"user_profile.html"}
45 return [p for p in pages_dir.glob("*.html") if p.name not in _CSR_SHELLS]
46
47
48 # ── Tests: musehub.js dead-code removal ───────────────────────────────────────
49
50
51 def test_musehub_js_does_not_contain_render_rows() -> None:
52 """renderRows was the main issue-list DOM renderer — now replaced by Jinja2."""
53 assert "renderRows" not in _musehub_js_text(), (
54 "renderRows() still present in musehub.js — it must be removed; "
55 "issue list HTML is now server-rendered."
56 )
57
58
59 def test_musehub_js_does_not_contain_build_bulk_toolbar() -> None:
60 """buildBulkToolbar was a client-side bulk-action UI builder — now gone."""
61 assert "buildBulkToolbar" not in _musehub_js_text(), (
62 "buildBulkToolbar() still present in musehub.js — it must be removed; "
63 "bulk toolbar HTML is now part of the server-rendered issue list fragment."
64 )
65
66
67 def test_musehub_js_does_not_contain_render_filter_sidebar() -> None:
68 """renderFilterSidebar was a client-side sidebar renderer — now Jinja2."""
69 assert "renderFilterSidebar" not in _musehub_js_text(), (
70 "renderFilterSidebar() still present in musehub.js — it must be removed; "
71 "filter sidebar is now rendered server-side."
72 )
73
74
75 def test_musehub_js_does_not_contain_load_issues() -> None:
76 """loadIssues was the client-side data-fetcher — replaced by route handlers."""
77 assert "function loadIssues" not in _musehub_js_text(), (
78 "loadIssues() still present in musehub.js — it must be removed; "
79 "issue data is now fetched server-side by the FastAPI route."
80 )
81
82
83 def test_musehub_js_does_not_contain_load_labels() -> None:
84 """loadLabels was a client-side data-fetcher for issue-list sidebar."""
85 assert "function loadLabels" not in _musehub_js_text(), (
86 "loadLabels() still present in musehub.js — replaced by server-side rendering."
87 )
88
89
90 def test_musehub_js_does_not_contain_render_right_sidebar() -> None:
91 """renderRightSidebar was a client-side renderer — now handled by Jinja2."""
92 assert "renderRightSidebar" not in _musehub_js_text(), (
93 "renderRightSidebar() still present in musehub.js — must be removed."
94 )
95
96
97
98 # ── Tests: template cleanup ────────────────────────────────────────────────────
99
100
101 def test_explore_base_html_deleted() -> None:
102 """explore_base.html must be deleted — no template extends it any more."""
103 assert not _EXPLORE_BASE.exists(), (
104 "explore_base.html still exists at "
105 f"{_EXPLORE_BASE} — it is no longer referenced by any "
106 "template and should be removed."
107 )
108
109
110 def test_all_template_page_script_blocks_empty_or_minimal() -> None:
111 """No page template should contain legacy client-side data-fetching patterns.
112
113 After the SSR/HTMX migration, the displaced fetch functions and state
114 variables must not appear in any {% block page_script %} section.
115 This is a regression guard: if a future merge re-introduces these patterns
116 the test will catch it immediately.
117 """
118 # Patterns that were removed as part of the HTMX migration.
119 # Their presence in any template indicates un-migrated client-side rendering.
120 displaced_patterns: list[str] = [
121 "function loadIssues",
122 "function loadLabels",
123 "function loadMilestones",
124 "function renderRows",
125 "function renderFilterSidebar",
126 "function renderRightSidebar",
127 "function buildBulkToolbar",
128 "function buildTemplatePicker",
129 "function loadCommentCounts",
130 "function loadReactionSummaries",
131 "function loadStashes",
132 "function loadNotifications",
133 "function loadReleases",
134 "function loadSessions",
135 "function loadCollaborators",
136 "function loadSettings",
137 "function loadActivity",
138 "const allIssues",
139 "let allIssues",
140 "var allIssues",
141 "const cachedOpen",
142 "let cachedOpen",
143 "const cachedClosed",
144 "let cachedClosed",
145 "const allLabels",
146 "let allLabels",
147 "const allMilestones",
148 "let allMilestones",
149 ]
150
151 violations: list[str] = []
152 for template in _all_page_templates():
153 text = template.read_text(encoding="utf-8")
154 for pattern in displaced_patterns:
155 if pattern in text:
156 violations.append(f"{template.name}: found '{pattern}'")
157
158 assert not violations, (
159 "Legacy client-side rendering patterns found in page templates.\n"
160 "These functions/variables were displaced by server-side rendering "
161 f"and must be removed:\n{'\n'.join(f' • {v}' for v in violations)}"
162 )
File History 11 commits
sha256:d035733f21ccff27735fddebfbbe0ed24565a32a22db8de5885402262671ecd2 chore: bump version to 0.2.0rc15 for musehub#113 fix release Sonnet 4.6 patch 15 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 30 days ago
sha256:a59da49c4611b970fc4b6ae48678ce4943261c213a07ddbd73ce9201df869b4a fix: remove false-positive proposal_comments index drop fro… Sonnet 4.6 patch 34 days ago
sha256:0a240d6dbff234f07d98a28a4a9a68db702f3f9ff9260196f24219bdb1c0b6f3 feat: render markdown mists as HTML with heading anchor links Sonnet 4.6 patch 35 days ago
sha256:24a7d47486ebc4ebd1832830580e177ec6f877b48dced8c000e198cdec4ce9d6 Merge 'task/bump-version-rc12' into 'dev' — proposal: Bump … Human 36 days ago
sha256:b9ff931d147e0114a1f17060f415b89ed551c170a91ff226c70437aa5c85f9ee Merge 'task/bump-version-rc12' into 'dev' — proposal: Bump … Human 36 days ago
sha256:d1122d21e73471879b460037b22c0b50fded7c423444a176f248428f75dac39c Merge 'task/fix-issue-pagination-cursor' into 'dev' — propo… Human 36 days ago
sha256:01e18975e73d2b3cd5b6db7929c895bef9aa6e0d4391dc5b2adfc548b41318dd Merge 'feat/adding-debug-logs-to-staging' into 'dev' — prop… Human 36 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