clipwright/tests/e2e/pipeline/test_cli_full_pipeline.py
pedro-bento 245a27c7a3 chore: drop watermark feature, CLI, docs, design.md; consolidate requirements
- 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.
2026-10-05 09:53:47 +01:00

119 lines
4.1 KiB
Python

"""L4 — full CLI pipeline (the keystone test).
Runs the REAL ``python -m clipwright.pipeline.main`` end to end with real
ffmpeg. The child interpreter is started with ``stub_env`` first on
``PYTHONPATH``, so ``sitecustomize.py`` injects the fake ultralytics/mediapipe
modules, stubs ASR, and patches the Gemini client. The test asserts on exit
code, metadata JSON, real clip files (ffprobe, never bytes) and the
``CLIP_READY`` markers — plus a failure variant that must write no metadata.
"""
import json
import subprocess
from pathlib import Path
import pytest
pytestmark = [pytest.mark.e2e, pytest.mark.pipeline]
def _cli_env(pipeline_env, **overrides):
"""Pin the deterministic, no-ML pipeline environment for the child."""
pipeline_env.update({
"GEMINI_API_KEY": "test",
"AUTO_LAYOUT": "0",
"SCENE_ENGINE": "pyscenedetect",
"FFMPEG_ENCODER": "x264",
"ASR_HOST_SLOTS": "0",
"CLIP_WORKERS": "2",
})
for var in ("AUTO_HOOK", "MAX_SOURCE_MINUTES",
"SOURCE_CAP_MINUTES", "DOWNLOAD_SKIP_STATICS"):
pipeline_env.pop(var, None)
pipeline_env.update(overrides)
return pipeline_env
def _probe(path):
out = subprocess.run(
["ffprobe", "-v", "error", "-select_streams", "v:0",
"-show_entries", "stream=width,height", "-of", "csv=p=0:s=x", str(path)],
capture_output=True, text=True, check=True)
width, height = out.stdout.strip().split("x")
return int(width), int(height)
def _ready_lines(stdout):
return [line for line in stdout.splitlines() if line.startswith("CLIP_READY ")]
def _assert_success(result, out, media, fmt):
assert result.returncode == 0, (
f"CLI failed ({result.returncode})\nSTDOUT:\n{result.stdout[-4000:]}\n"
f"STDERR:\n{result.stderr[-4000:]}")
metadata_files = list(out.glob("*_metadata.json"))
assert len(metadata_files) == 1
meta = json.loads(metadata_files[0].read_text())
assert meta["shorts"], "expected at least one clip"
assert meta["transcript"]["segments"], "expected the transcript in metadata"
assert meta["source_video"] == media.name
assert meta["output_format"] == fmt
base = media.stem
clips = sorted(out.glob(f"{base}_clip_*.mp4"))
assert len(clips) == len(meta["shorts"])
for clip in clips:
assert clip.stat().st_size > 1024
assert _probe(clip)[0] > 0
ready = _ready_lines(result.stdout)
assert len(ready) == len(meta["shorts"])
return meta, clips
def test_cli_full_pipeline_vertical(run_pipeline, pipeline_env, media_factory, tmp_path):
_cli_env(pipeline_env)
out = tmp_path / "out"
result = run_pipeline(media_factory.six, "-o", str(out), "--format", "vertical")
meta, clips = _assert_success(result, out, media_factory.six, "vertical")
width, height = _probe(clips[0])
assert height > width, f"vertical clip should be portrait, got {width}x{height}"
def test_cli_full_pipeline_horizontal(run_pipeline, pipeline_env, media_factory, tmp_path):
_cli_env(pipeline_env)
out = tmp_path / "out"
result = run_pipeline(media_factory.six, "-o", str(out), "--format", "horizontal")
meta, clips = _assert_success(result, out, media_factory.six, "horizontal")
width, height = _probe(clips[0])
assert width > height, f"horizontal clip should be landscape, got {width}x{height}"
def test_cli_failure_writes_no_metadata(run_pipeline, pipeline_env, media_factory, tmp_path):
# No Gemini key + no clips available -> the pipeline raises instead of
# shipping a silent render; nothing must be written to the output dir.
_cli_env(pipeline_env, GEMINI_API_KEY="")
out = tmp_path / "out"
result = run_pipeline(media_factory.silent, "-o", str(out), "--format", "vertical")
assert result.returncode != 0
assert not list(out.glob("*_metadata.json"))
assert not list(out.glob("*_clip_*.mp4"))
def test_cli_missing_input_exits_nonzero(run_pipeline, pipeline_env, tmp_path):
_cli_env(pipeline_env)
out = tmp_path / "out"
result = run_pipeline(tmp_path / "does-not-exist.mp4", "-o", str(out))
assert result.returncode != 0
assert not list(out.glob("*_metadata.json"))