polish: discovery hardening per code review (review round 2 minors)
- Fail fast with clear RuntimeError when themes/ directory is missing - Document underscore-prefix skip rule - Tests: broken-manifest/mismatch/no-manifest skip case, missing-dir fail-fast - tests/test_theme_pro_v3.py: drop fourth hardcoded list, import from core Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -6,8 +6,7 @@ import zipfile
|
||||
from pathlib import Path
|
||||
from bs4 import BeautifulSoup
|
||||
from test_factory_v2 import factory, site, zip_theme
|
||||
|
||||
THEMES=('automotive','industrial','corporate','minimal')
|
||||
from app.core import THEMES
|
||||
|
||||
def test_four_complete_theme_families_have_distinct_markup(factory):
|
||||
main=[]
|
||||
|
||||
@@ -14,5 +14,26 @@ def test_discover_returns_builtin_themes_with_manifests():
|
||||
assert manifest.get('id') == tid
|
||||
|
||||
def test_three_whitelists_agree():
|
||||
# Tripwire: the three names must stay the same object. Fails only if someone
|
||||
# reintroduces a hardcoded copy of the list anywhere.
|
||||
assert set(core.THEMES) == set(theme_pro.THEMES) == set(theme_store.BUILTIN)
|
||||
assert isinstance(core.THEMES, tuple)
|
||||
|
||||
def test_discover_skips_broken_theme_dirs(tmp_path, monkeypatch):
|
||||
themes = tmp_path / 'themes'
|
||||
good = themes / 'good-one'; good.mkdir(parents=True)
|
||||
(good / 'manifest.json').write_text(json.dumps({'id': 'good-one'}), encoding='utf-8')
|
||||
broken = themes / 'broken'; broken.mkdir()
|
||||
(broken / 'manifest.json').write_text('{not json', encoding='utf-8')
|
||||
mismatch = themes / 'mismatch'; mismatch.mkdir()
|
||||
(mismatch / 'manifest.json').write_text(json.dumps({'id': 'other-name'}), encoding='utf-8')
|
||||
no_manifest = themes / 'no-manifest'; no_manifest.mkdir()
|
||||
underscore = themes / '_shared'; underscore.mkdir()
|
||||
monkeypatch.setattr(core, 'ROOT', tmp_path)
|
||||
assert core.discover_themes() == ('good-one',)
|
||||
|
||||
def test_discover_fails_fast_when_themes_dir_missing(tmp_path, monkeypatch):
|
||||
monkeypatch.setattr(core, 'ROOT', tmp_path)
|
||||
import pytest
|
||||
with pytest.raises(RuntimeError, match='themes directory missing'):
|
||||
core.discover_themes()
|
||||
|
||||
Reference in New Issue
Block a user