// Contract tests for the hardware media smoke harness.
//
// Scope: inspect `scripts/manual/run_hardware_media_smoke.sh`.
// Targets: accelerated media artifacts and non-mutating Theia smoke probes.
// Why: hardware acceleration regressions are expensive to debug in the lab, so
// the manual proof script must stay artifact-backed, hardware-first, and safe
// to run without mutating Theia's USB gadget state.

const HARDWARE_SMOKE: &str = include_str!(concat!(
    env!("CARGO_MANIFEST_DIR"),
    "/scripts/manual/run_hardware_media_smoke.sh"
));

#[test]
fn hardware_media_smoke_stays_manual_and_artifact_backed() {
    for marker in [
        "Manual: local/remote hardware media smoke evidence; not part of CI.",
        "summary_json: ${SUMMARY_JSON}",
        "summary_txt: ${SUMMARY_TXT}",
        "upstream-hevc-hardware.hevc",
        "upstream-hevc-hardware-frame.png",
        "downstream-h264-hardware.h264",
        "downstream-h264-hardware-frame.png",
        "audio-aac-roundtrip.wav",
        "audio-aac-roundtrip-rms.json",
    ] {
        assert!(
            HARDWARE_SMOKE.contains(marker),
            "hardware smoke harness should preserve artifact marker {marker}"
        );
    }
}

#[test]
fn hardware_media_smoke_uses_accelerated_video_paths() {
    for marker in [
        "hevc_nvenc",
        "h264_nvenc",
        "ffmpeg_nvenc_usable",
        "vah265enc",
        "vah265dec",
        "vah264dec",
        "vulkanh264dec",
        "v4l2slh264dec",
        "v4l2slh265dec",
        "LESAVKA_ALLOW_VULKAN_H264_DECODER",
        "no sudo, no systemctl, no UVC gadget reset",
    ] {
        assert!(
            HARDWARE_SMOKE.contains(marker),
            "hardware smoke harness should include hardware/safety marker {marker}"
        );
    }

    for forbidden in [
        "x264enc",
        "x265enc",
        "avdec_h264",
        "avdec_h265",
        "openh264dec",
        "decodebin",
        "LESAVKA_ALLOW_SOFTWARE_VIDEO=1",
        "LESAVKA_FORCE_GADGET_REBUILD",
    ] {
        assert!(
            !HARDWARE_SMOKE.contains(forbidden),
            "hardware smoke harness should not depend on {forbidden}"
        );
    }
}

#[test]
fn hardware_media_smoke_has_optional_non_mutating_theia_probe() {
    for marker in [
        "LESAVKA_RUN_REMOTE_MEDIA_SMOKE",
        "LESAVKA_SERVER_HOST",
        "no service/gadget mutation",
        "set LESAVKA_RUN_REMOTE_MEDIA_SMOKE=1",
        "gst-inspect-1.0 v4l2slh265dec",
    ] {
        assert!(
            HARDWARE_SMOKE.contains(marker),
            "remote smoke probe should preserve marker {marker}"
        );
    }
}
