Files
ad/tests/api/docs/removed_internals.py
T
retoor 874c37350b Remove contributing and component docs from the public docs site
Drop the Contributing and internals section, Architecture, Frontend,
and dp-* component pages from the docs registry, prose files, nav, and
legacy redirect target. Guard with tests that fail if they return.
2026-10-05 15:55:35 +02:00

88 lines
2.4 KiB
Python

# retoor <retoor@molodetz.nl>
import re
from molodetz.docs_prose import DOCS_PAGES, PROSE_DIR, SECTIONS
BANNED_SECTION = "Contributing and internals"
BANNED_TITLES = {
"Architecture",
"Frontend and components",
"dp-avatar",
"dp-code",
"dp-content",
"dp-title",
"dp-toast",
"dp-dialog",
"dp-context-menu",
"dp-upload",
"dp-lightbox",
"dp-chat",
}
BANNED_SLUGS = {
"architecture",
"frontend",
"component-avatar",
"component-code",
"component-content",
"component-title",
"component-toast",
"component-dialog",
"component-context-menu",
"component-upload",
"component-lightbox",
"component-chat",
}
BANNED_FILES = {
"architecture.md",
"frontend.md",
*[
f"component-{name}.md"
for name in (
"avatar",
"code",
"content",
"title",
"toast",
"dialog",
"context-menu",
"upload",
"lightbox",
"chat",
)
],
}
def _docs_surfaces(html):
sidebar = re.search(r'<aside class="docs-sidebar">(.*?)</aside>', html, re.S)
content = re.search(r'<article class="docs-content[^"]*">(.*?)</article>', html, re.S)
return (sidebar.group(1) if sidebar else ""), (content.group(1) if content else "")
def test_docs_registry_excludes_removed_internals():
assert BANNED_SECTION not in SECTIONS
titles = {page["title"] for page in DOCS_PAGES}
slugs = {page["slug"] for page in DOCS_PAGES}
sections = {page["section"] for page in DOCS_PAGES}
assert not titles & BANNED_TITLES
assert not slugs & BANNED_SLUGS
assert BANNED_SECTION not in sections
for name in BANNED_FILES:
assert not (PROSE_DIR / name).exists(), name
def test_served_docs_hide_removed_internals(anon, admin):
banned_hrefs = {f"/docs/{slug}" for slug in BANNED_SLUGS}
for client in (anon, admin):
for path in ("/docs", "/docs/welcome", "/docs/api"):
html = client.get(path).text
sidebar, content = _docs_surfaces(html)
surface = f"{sidebar}\n{content}"
assert BANNED_SECTION not in surface, path
for title in BANNED_TITLES:
assert title not in surface, (path, title)
for href in banned_hrefs:
assert href not in surface, (path, href)
for slug in sorted(BANNED_SLUGS):
assert anon.get(f"/docs/{slug}").status_code == 404, slug