Files
automaton/tests/test_prompt_paths.py
T

45 lines
1.5 KiB
Python
Raw Normal View History

"""Regression test for task path conventions in prompts and templates."""
import re
from pathlib import Path
import pytest
ROOT = Path(__file__).resolve().parent.parent
PROMPTS_DIR = ROOT / "prompts"
TEMPLATES_DIR = ROOT / "templates"
# Legacy path pattern that should no longer appear.
LEGACY_PATH = re.compile(r"\{project\}/tasks/\{task-name\}/")
# Canonical path pattern that should be used instead.
CANONICAL_PATH = re.compile(r"\{project\}/\.automaton/tasks/\{task-name\}/")
def _markdown_files(*directories: Path) -> list[Path]:
files = []
for directory in directories:
if directory.exists():
files.extend(directory.rglob("*.md"))
return files
@pytest.mark.parametrize("path", _markdown_files(PROMPTS_DIR, TEMPLATES_DIR))
def test_no_legacy_task_paths(path: Path) -> None:
"""Every prompt/template must use the canonical .automaton/tasks path."""
text = path.read_text(encoding="utf-8")
legacy_matches = LEGACY_PATH.findall(text)
assert not legacy_matches, (
f"Found legacy task path in {path.relative_to(ROOT)}: {legacy_matches}\n"
"Use {project}/.automaton/tasks/{task-name}/ instead."
)
def test_canonical_path_present_in_prompts() -> None:
"""At least one prompt uses the canonical path (sanity check)."""
found = False
for path in _markdown_files(PROMPTS_DIR):
if CANONICAL_PATH.search(path.read_text(encoding="utf-8")):
found = True
break
assert found, "No prompt uses the canonical {project}/.automaton/tasks/{task-name}/ path"