Files
FabledSteward/tests/test_breadcrumbs.py
T
bvandeusenandClaude Opus 5.5 434127b3e1
CI / lint (push) Successful in 4s
CI / integration (push) Successful in 1m10s
CI / unit (push) Successful in 1m36s
CI / publish (push) Successful in 1m28s
feat(monitors): Monitors absorbs the Status page; Status is removed (#5270)
Status repeated the Monitors page's counts, check strip and uptime. Monitors
now has one header row and every column Status had: the last 30 checks,
latest response with its trend, uptime over 24h / 7d / 30d (the range picker
goes) and TLS days on every row. /status and /status/rows and the nav link
are removed outright; the dashboard Overview (/status/widget) stays and its
Details link goes to Monitors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 15:36:38 -04:00

56 lines
2.5 KiB
Python

"""Every page below a top-level section shows its trail back up (rule 134).
The breadcrumb block is empty by default, so a nested page that forgets it
ships with no way back up and nothing says so. Every full page (one that
extends base.html) must fill the block, unless it is a section's own top
page, a logged-out page or an error page: those are named below, so adding
one is a decision someone makes in this file.
"""
import re
from tests._templates import REPO, template_files
TOP_LEVEL = {
"steward/templates/dashboard/index.html",
"steward/templates/hosts/list.html",
"steward/templates/monitors/index.html",
"steward/templates/alerts/list.html",
"steward/templates/ansible/index.html",
"steward/templates/audit/list.html",
"steward/templates/ai_access/index.html",
"plugins/docker/templates/docker/index.html",
"plugins/snmp/templates/snmp/index.html",
"plugins/traefik/templates/traefik/index.html",
"plugins/unifi/templates/unifi/index.html",
# Logged out, or no page to go back up from.
"steward/templates/auth/login.html",
"steward/templates/auth/setup.html",
"steward/templates/errors/404.html",
"steward/templates/errors/500.html",
"steward/templates/errors/database_unavailable.html",
}
_EXTENDS_BASE = re.compile(r"""\{%-?\s*extends\s+["']base\.html["']""")
_BLOCK = re.compile(r"\{%-?\s*block\s+breadcrumb\s*-?%\}(.*?)\{%-?\s*endblock", re.S)
def needs_crumbs_and_lacks_them(text: str) -> bool:
block = _BLOCK.search(text)
return bool(_EXTENDS_BASE.search(text)) and not (block and "crumbs(" in block.group(1))
def test_the_guard_can_fail():
assert needs_crumbs_and_lacks_them('{% extends "base.html" %}{% block content %}x{% endblock %}')
assert needs_crumbs_and_lacks_them('{% extends "base.html" %}{% block breadcrumb %}{% endblock %}')
assert not needs_crumbs_and_lacks_them(
'{% extends "base.html" %}{% block breadcrumb %}{{ crumbs([("Hosts", "/hosts/"), ("x", "")]) }}{% endblock %}')
assert not needs_crumbs_and_lacks_them("<tr><td>a fragment</td></tr>")
def test_every_nested_page_has_a_trail():
pages = {str(p.relative_to(REPO)): p for p in template_files()}
assert TOP_LEVEL <= set(pages), sorted(TOP_LEVEL - set(pages)) # a renamed page leaves no stale entry
missing = sorted(name for name, p in pages.items()
if name not in TOP_LEVEL and needs_crumbs_and_lacks_them(p.read_text()))
assert not missing, f"add {{% block breadcrumb %}}{{{{ crumbs([...]) }}}} (rule 134): {missing}"