Files
transcription/tests/test_media_path_safety.py
T
2026-08-20 16:14:44 -05:00

30 lines
1.0 KiB
Python

"""Guardrails for UI/API media path safety contracts."""
from __future__ import annotations
from pathlib import Path
PROJECT_ROOT = Path(__file__).resolve().parents[1]
UI_ROOT = PROJECT_ROOT / "src" / "transcription" / "ui"
API_ROOT = PROJECT_ROOT / "src" / "transcription" / "api"
SOURCES_PAGE = UI_ROOT / "pages" / "sources_page.py"
def _python_files(root: Path) -> list[Path]:
return sorted(root.rglob("*.py"))
def test_no_ui_or_api_python_file_uses_file_scheme_links():
violations: list[str] = []
for path in [*_python_files(UI_ROOT), *_python_files(API_ROOT)]:
text = path.read_text(encoding="utf-8")
if "file://" in text:
violations.append(str(path.relative_to(PROJECT_ROOT)).replace("\\", "/"))
assert violations == []
def test_sources_page_does_not_render_raw_file_path_value():
text = SOURCES_PAGE.read_text(encoding="utf-8")
assert 'metadata_row("Stored Path:", source.file_path)' not in text
assert "public_media_path_label(source.file_path" in text