#!/usr/bin/env bash
# Guard downstream eye-video stability before pushing video-related changes.
set -euo pipefail

ROOT=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." && pwd)
source "${ROOT}/scripts/ci/headless_run.sh"
cd "$ROOT"

VIDEO_TESTS=(
  --test client_launcher_layout_contract
  --test video_downstream_feed_contract
  --test downstream_blackout_recovery_contract
  --test downstream_video_latency_budget_contract
  --test downstream_video_mode_decoder_matrix_contract
  --test downstream_video_stall_chaos_contract
  --test server_video_include_contract
  --test video_support_contract
  --test client_output_video_include_contract
  --test server_video_sinks_include_contract
  --test server_video_sink_smoke_contract
)

VIDEO_IGNORE_REGEX='(^|/)(common/src/(hid|paste|process_metrics)\.rs|server/src/(audio|camera|calibration|capture_power|gadget|output_delay_probe|runtime_support|upstream_media_runtime)(/.*)?|server/src/(blind_healer|camera_runtime|handshake|paste|security|uvc_runtime)\.rs)'

cargo fmt --all -- --check
cargo check -q -p lesavka_client --bin lesavka-client
cargo check -q -p lesavka_server --bin lesavka-server
lesavka_ci_run_headless cargo test -q -p lesavka_tests "${VIDEO_TESTS[@]}"

cargo llvm-cov clean --workspace
lesavka_ci_run_headless cargo llvm-cov --workspace "${VIDEO_TESTS[@]}" \
  --ignore-filename-regex "$VIDEO_IGNORE_REGEX" \
  --fail-under-lines 95 \
  --summary-only
