// Reliability contract for repeated server-to-RCT profile changes.
//
// Scope: protect the script behavior needed to switch MJPEG/HEVC profiles and
// recover media endpoints between runs.
// Targets: scripts/manual/run_server_to_rc_mode_matrix.sh.
// Why: calibration only stays trustworthy if repeated mode/profile switches
// rebuild or wait for the physical UVC/UAC path cleanly before measuring.

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

#[test]
fn repeated_matrix_runs_keep_reconfigure_recovery_and_readiness_steps() {
    for marker in [
        "LESAVKA_SERVER_RC_REPEAT_COUNT=${LESAVKA_SERVER_RC_REPEAT_COUNT:-1}",
        "LESAVKA_SERVER_RC_RECONFIGURE_STRATEGY=${LESAVKA_SERVER_RC_RECONFIGURE_STRATEGY:-runtime}",
        "LESAVKA_SERVER_RC_ALLOW_GADGET_RESET=${LESAVKA_SERVER_RC_ALLOW_GADGET_RESET:-1}",
        "cycling UVC gadget descriptors",
        "wait_tethys_media_ready",
        "LESAVKA_SERVER_RC_SIGNAL_READY_ATTEMPTS=${LESAVKA_SERVER_RC_SIGNAL_READY_ATTEMPTS:-4}",
        "write_signal_readiness_attempts_summary",
    ] {
        assert!(
            MATRIX_SCRIPT.contains(marker),
            "server-to-RCT repeated run should preserve recovery marker {marker}"
        );
    }
}

#[test]
fn repeated_profile_switches_publish_static_calibration_evidence() {
    for marker in [
        "static_min_runs",
        "static_max_spread_us",
        "static_max_p95_skew_ms",
        "static_max_median_skew_ms",
        "mode_static_calibration_json",
        "mode_static_calibration_env",
        "static video delays",
        "static audio delays",
    ] {
        assert!(
            MATRIX_SCRIPT.contains(marker),
            "server-to-RCT static calibration should preserve marker {marker}"
        );
    }
}
