"""Phase-0 foundation smoke test. Proves the shared E2E scaffolding works before the per-route lanes are built: 1. ``/health`` answers through the in-process ASGI client. 2. ``app_state`` gives each test a private ``jobs`` dict (isolation). 3. A disk-seeded completed job is recoverable the same way a restart recovers. 4. The session ``media_factory`` produces ffprobe-able fixture videos. """ import json import subprocess import pytest pytestmark = pytest.mark.e2e async def test_health_ok(client): resp = await client.get("/health") assert resp.status_code == 200 assert resp.json() == {"status": "ok"} async def test_app_state_isolation_a(app_state): # Fresh per test: nothing seeded this dict. assert app_state.app.jobs == {} app_state.app.jobs["isolation-a"] = {"status": "sentinel"} async def test_app_state_isolation_b(app_state): # If the previous test's write leaked, this dict would not be empty. assert app_state.app.jobs == {} app_state.app.jobs["isolation-b"] = {"status": "sentinel"} async def test_disk_seeded_job_is_recoverable(app_state, seeded_job, client): job_id = seeded_job(job_id="job-smoke", base="smoke", clips=1) job = app_state.app.jobs[job_id] assert job["status"] == "completed" assert job["output_dir"] == str(app_state.out / job_id) clips = job["result"]["clips"] assert len(clips) == 1 assert clips[0]["video_url"].endswith("/smoke_clip_1.mp4") clip_path = app_state.out / job_id / "smoke_clip_1.mp4" assert clip_path.is_file() and clip_path.stat().st_size > 0 # The recovered clip is actually servable: this proves the /videos mount was # repointed at the per-test output tree (it captures its directory at # import time, so the app_state rebind has to move it explicitly). resp = await client.get(clips[0]["video_url"]) assert resp.status_code == 200 assert resp.content def _probe(path): out = subprocess.run( ["ffprobe", "-v", "error", "-show_entries", "format=duration:stream=codec_type", "-of", "json", str(path)], capture_output=True, text=True, check=True, ) return json.loads(out.stdout) def test_media_factory_files_are_probeable(media_factory): sixty = _probe(media_factory.sixty) assert float(sixty["format"]["duration"]) == pytest.approx(60.0, abs=1.0) assert {"video", "audio"} <= {s["codec_type"] for s in sixty["streams"]} six = _probe(media_factory.six) assert float(six["format"]["duration"]) == pytest.approx(6.0, abs=1.0) assert {"video", "audio"} <= {s["codec_type"] for s in six["streams"]} silent = _probe(media_factory.silent) assert {s["codec_type"] for s in silent["streams"]} == {"video"} cuts = _probe(media_factory.cuts) assert float(cuts["format"]["duration"]) == pytest.approx(6.0, abs=1.0) assert {"video"} <= {s["codec_type"] for s in cuts["streams"]}