"""Picking the real error out of a job log, for the failure-rate alert. Regression cover for two prod alerts (22-jul-2026) that named the wrong subsystem because the classifier read the tail of the log instead of the error: a Gemini blip was reported as "ffmpeg/render" and a silent upload as a broken download path. """ import pytest # app pulls in dotenv/fastapi/cloud at import time; the minimal CI env lacks # them, so skip there. Runs fully in the container/local where deps exist. app = pytest.importorskip("app") from cloud.alerts import _classify_failure def _classify(logs): return _classify_failure(app._job_error_text(logs)) def test_gemini_blip_is_not_blamed_on_ffmpeg(): # The render noise that followed the error used to win, because it was last. logs = [ "🤖 Analyzing with Gemini (2-pass: score → detail)...", " Built 5 scoring window(s).", "❌ Gemini Error: Gemini returned an empty response body.", "🚀 Reframe engine v2 (ffmpeg-native render)", "/app/scene_detection.py:109: UserWarning: The given NumPy array is not writable", "🎬 Scene engine: TransNetV2 — 67 scenes", "Analyzing Scenes: 0%| | 0/67 [00:00