clipwright/tests/test_package_layout.py
pedro-bento 59e0db8c24 chore: remove dead code, unused assets, and the server-render chain
Backend:
- Drop unused imports/locals and zero-reference helpers (truncate_ip,
  in_split, GEMINI_PROMPT_TEMPLATE, legacy subtitles SRT path, dead paths)
- Remove unwired features (delete_uploaded, mark_ai_generated, unmark_job,
  compact_words, restoring_static restorer hook, gemini_worker __main__)
- Remove shelved panel_layout module + its flags/tests
- Remove the /api/render proxy + RENDER_SERVICE_URL

Frontend:
- Delete App.css, react.svg, vite.svg, agent screenshot, demo mp4s
- Remove dead exports (downloadBlobUrl, consent reopen machinery, dead zod
  schemas/CITED_STATS) and unused deps (@remotion/media-utils, zod)
- Drop the /render dev proxy; rewrite dashboard README

Repo/config:
- Delete render-service/ and top-level remotion/ (superseded by the
  dashboard's in-browser Remotion copy); drop the compose renderer service
- Delete docker-compose.e2e.local.yml and 4 unreferenced screenshots
- Prune .env.example dead keys, add GEMINI_API_KEY/MAX_CONCURRENT_JOBS
- Tighten .dockerignore/.gitignore; add dashboard lint to CI
- Fix stale compliance doc + README structure

Backend 709 passed / 18 skipped; dashboard lint+build green; compose valid.
2026-10-04 21:24:42 +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", "watermarked", "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())
)
)