| 1 |
"""Every shipped starter template must parse cleanly. |
| 2 |
|
| 3 |
Guards the cookbook recipes: if a schema bump lands (Sprint 12b |
| 4 |
migrator chain), the templates need to move forward with it. This |
| 5 |
test fails loudly if a checked-in template drifts. |
| 6 |
""" |
| 7 |
|
| 8 |
from __future__ import annotations |
| 9 |
|
| 10 |
from pathlib import Path |
| 11 |
|
| 12 |
import pytest |
| 13 |
|
| 14 |
from dlm.doc.parser import parse_file |
| 15 |
from dlm.templates import bundled_templates_dir |
| 16 |
|
| 17 |
|
| 18 |
def _template_paths() -> list[Path]: |
| 19 |
return sorted(bundled_templates_dir().glob("*.dlm")) |
| 20 |
|
| 21 |
|
| 22 |
def test_templates_dir_is_populated() -> None: |
| 23 |
# Guard against a silent deletion of the bundled gallery. |
| 24 |
paths = _template_paths() |
| 25 |
assert len(paths) >= 8, ( |
| 26 |
f"expected at least 8 gallery templates under {bundled_templates_dir()}, got {len(paths)}" |
| 27 |
) |
| 28 |
|
| 29 |
|
| 30 |
@pytest.mark.parametrize("template", _template_paths(), ids=lambda p: p.name) |
| 31 |
def test_template_parses_and_has_sections(template: Path) -> None: |
| 32 |
parsed = parse_file(template) |
| 33 |
assert parsed.frontmatter.dlm_id, f"{template.name} missing dlm_id" |
| 34 |
assert parsed.frontmatter.base_model, f"{template.name} missing base_model" |
| 35 |
assert len(parsed.sections) >= 1, f"{template.name} has no body sections" |