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

ROOT=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." && pwd)
cd "$ROOT"

VIDEO_TESTS=(
  --test client_launcher_layout_contract
  --test video_downstream_feed_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|camera_runtime|capture_power|gadget|paste|runtime_support|uvc_runtime)\.rs)'

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

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