// Manual/lab contract for the server-to-RCT mode matrix.
//
// Scope: protect the hardware-backed matrix script as an artifact-producing
// manual test, not a default CI mutation.
// Targets: scripts/manual/run_server_to_rc_mode_matrix.sh.
// Why: server-to-RCT calibration values should remain rerunnable and auditable
// without accidentally turning routine CI into a gadget-resetting lab run.

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

#[test]
fn matrix_remains_operator_controlled_and_delayable() {
    for marker in [
        "Manual: validate server-generated UVC/UAC output",
        "LESAVKA_SERVER_RC_RECONFIGURE=${LESAVKA_SERVER_RC_RECONFIGURE:-0}",
        "LESAVKA_SERVER_RC_PROMPT_SUDO_EARLY=${LESAVKA_SERVER_RC_PROMPT_SUDO_EARLY:-1}",
        "Theia sudo password for %s",
        "LESAVKA_SERVER_RC_START_DELAY_SECONDS=${LESAVKA_SERVER_RC_START_DELAY_SECONDS:-0}",
        "remote sudo has already been primed; sleeping before prebuild/reconfigure/capture",
        "mode-matrix-run.log",
    ] {
        assert!(
            MATRIX_SCRIPT.contains(marker),
            "server-to-RCT matrix should preserve operator-control marker {marker}"
        );
    }
}

#[test]
fn matrix_preserves_sync_freshness_smoothness_and_coded_evidence_outputs() {
    for marker in [
        "LESAVKA_SERVER_RC_FRESHNESS_MAX_AGE_MS=${LESAVKA_SERVER_RC_FRESHNESS_MAX_AGE_MS:-350}",
        "LESAVKA_SERVER_RC_MIN_CODED_PAIRS=${LESAVKA_SERVER_RC_MIN_CODED_PAIRS:-${LESAVKA_SERVER_RC_FRESHNESS_MIN_PAIRS}}",
        "LESAVKA_SERVER_RC_REQUIRE_ALL_CODED_PAIRS=${LESAVKA_SERVER_RC_REQUIRE_ALL_CODED_PAIRS:-0}",
        "LESAVKA_SERVER_RC_REQUIRE_SMOOTHNESS_PASS=${LESAVKA_SERVER_RC_REQUIRE_SMOOTHNESS_PASS:-0}",
        "smoothness_warnings",
        "smoothness warning:",
        "signature_expected_event_count",
        "signature_paired_event_count",
        "mode-matrix-summary.json",
        "mode-static-calibration.json",
    ] {
        assert!(
            MATRIX_SCRIPT.contains(marker),
            "server-to-RCT matrix should preserve evidence marker {marker}"
        );
    }
}

#[test]
fn matrix_keeps_mjpeg_and_hevc_profiles_rerunnable() {
    for marker in [
        "LESAVKA_SERVER_RC_MJPEG_MODE_DELAYS_US",
        "LESAVKA_SERVER_RC_HEVC_MODE_DELAYS_US",
        "LESAVKA_SERVER_RC_NORMALIZED_PROFILE=mjpeg",
        "LESAVKA_SERVER_RC_NORMALIZED_PROFILE=hevc",
        "LESAVKA_SERVER_RC_AUDIO_PROFILE",
        "LESAVKA_SERVER_RC_CALIBRATION_PROFILE",
        "LESAVKA_CALIBRATION_PROFILE",
        "LESAVKA_UPLINK_CAMERA_CODEC",
        "LESAVKA_UPLINK_AUDIO_CODEC",
        "LESAVKA_UPSTREAM_HEVC_OPUS_AUDIO_PLAYOUT_MODE_OFFSETS_US",
    ] {
        assert!(
            MATRIX_SCRIPT.contains(marker),
            "server-to-RCT matrix should preserve profile marker {marker}"
        );
    }
}
