// Contract tests for the virtual-camera client uplink probe.
//
// Scope: statically guard the local virtual-camera probe and dummy server.
// Targets: `scripts/manual/run_client_uplink_virtual_camera_probe.py` and
// `client/src/bin/lesavka-uplink-dummy-server.rs`.
// Why: this probe validates that client-origin frames survive the real capture
// path before server-side decoding, so it must stay reproducible in the lab.

use std::path::PathBuf;

const SCRIPT: &str =
    include_str!("../../../../scripts/manual/run_client_uplink_virtual_camera_probe.py");
const DUMMY_SERVER: &str =
    include_str!("../../../../client/src/bin/lesavka-uplink-dummy-server.rs");

#[test]
fn virtual_camera_probe_exercises_real_client_capture_before_server_path() {
    for expected in [
        "lesavka-uplink-dummy-server",
        "LESAVKA_HEADLESS",
        "LESAVKA_CAM_SOURCE",
        "LESAVKA_CAM_FORMAT",
        "LESAVKA_REQUIRE_EXPLICIT_MEDIA_SOURCES",
        "--device is required for --source virtual",
        "format=yuyv422",
        "StreamWebcamMedia",
        "StreamCamera",
        "client-uplink-frame-metrics.jsonl",
        "lesavka.client-uplink-virtual-camera.analysis.v1",
        "probe.analyze_frame",
        "probe.synthetic_gray",
    ] {
        assert!(
            SCRIPT.contains(expected),
            "client uplink virtual probe should preserve marker {expected}"
        );
    }
}

#[test]
fn dummy_server_records_exact_uplink_packets_for_decode_and_frame_comparison() {
    for expected in [
        "stream_webcam_media",
        "stream_camera",
        "UpstreamMediaBundle",
        "VideoPacket",
        "video-packets",
        "uplink-media.jsonl",
        "lesavka.client-uplink-dummy-server.packet.v1",
        "client_capture_pts_us",
        "client_send_pts_us",
        "camera_codec",
        "bundled_webcam_media",
    ] {
        assert!(
            DUMMY_SERVER.contains(expected),
            "dummy uplink server should preserve marker {expected}"
        );
    }
}

#[test]
fn virtual_camera_probe_script_parses_as_python() {
    let script = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("scripts/manual/run_client_uplink_virtual_camera_probe.py");
    let status = std::process::Command::new("python3")
        .arg("-m")
        .arg("py_compile")
        .arg(&script)
        .status()
        .expect("run python parser");
    assert!(status.success(), "probe script should parse cleanly");
}
