clipwright/tests/test_package_layout.py
pedro-bento 91a5465f81
All checks were successful
CI / unit (push) Successful in 45s
CI / backend-e2e (push) Successful in 1m16s
CI / dashboard-e2e (push) Successful in 2m29s
chore: drop watermark feature, CLI, docs, design.md; consolidate requirements (#6)
- Remove the watermark feature end to end (watermarked.py, apply_watermark/
  mark_delivery/watermark_filter, WATERMARK env, assets/) and its tests; self-host
  delivery is now unconditionally clean.
- Delete the unused cli/ package and .github/workflows/publish-cli.yml.
- Delete docs/ (compliance) and design.md; drop the dangling references in the
  legal page and the design-token/ui comments.
- Consolidate requirements: requirements.txt (runtime) + requirements-test.txt
  (unit + E2E); remove requirements-e2e.txt and requirements-ml-e2e.txt and
  point both CI jobs at the single test file. Add libgl1 to the unit job
  (scenedetect -> opencv-python links libGL).

Verified in the CI container: unit 701 passed; API E2E 209; pipeline E2E 127;
Playwright 19 passed / 1 skipped.

Reviewed-on: #6
Co-authored-by: pedro-bento <mail@pbento.pt>
Co-committed-by: pedro-bento <mail@pbento.pt>
2026-10-05 11:11:37 +01:00

94 lines
3.6 KiB
Python

"""Architecture guard for the package-layout refactor.
The backend's 37 top-level modules moved under ``clipwright/``. These tests pin
the invariants that made the move worth doing:
1. the repo root holds no importable ``*.py`` module any more;
2. every package ``__init__`` is a pure docstring (no code, no re-exports);
3. nothing under ``clipwright/`` or ``tests/`` still imports a module by its
old bare top-level name.
Failure messages name the offending files.
"""
import ast
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parents[1]
PACKAGE = REPO_ROOT / "clipwright"
TESTS = REPO_ROOT / "tests"
# The old top-level module names. ``from clipwright.<group> import <name>`` is
# the supported spelling; importing any of these bare names is a regression.
LEGACY_MODULES = frozenset({
"active_speaker", "app", "camera_inset", "clip_selection", "edit_builder",
"editor", "ffmpeg_utils", "file_hosts", "frame_sampler", "free_tools",
"gemini_worker", "hook_grounding", "hooks", "layout_picker",
"layout_ranges", "llm_backend", "main", "media_auth",
"postiz", "punch_in", "quality_probe", "recut", "reframe_v2",
"restoring_static", "scene_detection", "screencast_layout",
"security_utils", "split_layout", "subtitles", "thumbnail",
"transcribe_backends", "verify_aesthetic", "verify_custom_hook",
"verify_hooks", "yt_clients",
})
def _legacy_imports(path):
"""The legacy bare module names imported by the source at ``path``."""
tree = ast.parse(path.read_text(encoding="utf-8"), filename=str(path))
found = set()
for node in ast.walk(tree):
if isinstance(node, ast.Import):
for alias in node.names:
root = alias.name.split(".")[0]
if root in LEGACY_MODULES:
found.add(root)
elif isinstance(node, ast.ImportFrom):
# A relative import inside the package (``from . import x``) is
# not a bare top-level import; only absolute ones can be legacy.
if node.level:
continue
root = (node.module or "").split(".")[0]
if root in LEGACY_MODULES:
found.add(root)
return found
def test_repo_root_has_no_python_modules():
offenders = sorted(p.name for p in REPO_ROOT.glob("*.py"))
assert not offenders, (
"stray top-level modules at the repo root (move them under clipwright/): "
+ ", ".join(offenders)
)
def test_package_inits_are_docstring_only():
offenders = []
for init in sorted(PACKAGE.rglob("__init__.py")):
tree = ast.parse(init.read_text(encoding="utf-8"), filename=str(init))
for node in tree.body:
is_docstring = (
isinstance(node, ast.Expr)
and isinstance(node.value, ast.Constant)
and isinstance(node.value.value, str)
)
if not is_docstring:
offenders.append(f"{init.relative_to(REPO_ROOT)}:{node.lineno}")
assert not offenders, (
"package __init__ files must contain only a docstring: "
+ ", ".join(offenders)
)
def test_no_legacy_bare_module_imports():
offenders = {}
sources = sorted(PACKAGE.rglob("*.py")) + sorted(TESTS.glob("*.py"))
for path in sources:
found = _legacy_imports(path)
if found:
offenders[str(path.relative_to(REPO_ROOT))] = sorted(found)
assert not offenders, (
"legacy bare module imports (use clipwright.<group> instead): "
+ ", ".join(
f"{name} -> {mods}" for name, mods in sorted(offenders.items())
)
)