mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-08-06 19:28:06 +00:00
Three lightweight static checks, all enrolled in CI's unit-test allowlist along with the new web-cache test: - test_template_targets.py: every literal render_template() target must exist (would have caught the weather/stocks partial 500s at commit time). - test_widget_scripts.py: every widget JS file must be script-included in base.html or explicitly allowlisted with a reason (would have caught the unloaded time-picker/file-upload-single/plugin-file-manager widgets), and allowlisted files must NOT be included (prevents the example widget from shadowing the real color-picker). - test_doc_links.py: relative markdown links in active docs must resolve (docs/archive/ exempt). Each guard was verified to fail against the pre-PR tree and pass now. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SXb4mKcAkVaxkeTb3YnAdr
34 lines
1.3 KiB
Python
34 lines
1.3 KiB
Python
"""Guard: every literal render_template() target must exist on disk.
|
|
|
|
Catches routes that reference templates deleted in a refactor (a real bug
|
|
class: the weather/stocks partials 500'd for months because their
|
|
templates were removed when those displays became plugins).
|
|
"""
|
|
import re
|
|
from pathlib import Path
|
|
|
|
PROJECT_ROOT = Path(__file__).resolve().parent.parent
|
|
TEMPLATE_ROOT = PROJECT_ROOT / 'web_interface' / 'templates'
|
|
RENDER_RE = re.compile(r"""render_template\(\s*['"]([^'"]+)['"]""")
|
|
|
|
|
|
def _python_sources():
|
|
yield PROJECT_ROOT / 'web_interface' / 'app.py'
|
|
yield from (PROJECT_ROOT / 'web_interface' / 'blueprints').glob('*.py')
|
|
|
|
|
|
def test_all_literal_render_template_targets_exist():
|
|
missing = []
|
|
for source in _python_sources():
|
|
text = source.read_text(encoding='utf-8')
|
|
for lineno, line in enumerate(text.splitlines(), 1):
|
|
for target in RENDER_RE.findall(line):
|
|
if not (TEMPLATE_ROOT / target).is_file():
|
|
missing.append(
|
|
f'{source.relative_to(PROJECT_ROOT)}:{lineno} -> {target}'
|
|
)
|
|
assert not missing, (
|
|
'render_template() references templates that do not exist under '
|
|
f'web_interface/templates/:\n' + '\n'.join(missing)
|
|
)
|