// E2E contract for server-origin media observed at the RCT.
//
// Scope: protect the synthetic flash/tone path used to prove final RCT output.
// Targets: server/src/output_delay_probe/probe_runtime.rs,
// server/src/output_delay_probe/media_encoding.rs, and
// server/src/output_delay_probe/timeline_config.rs.
// Why: the server-to-RCT leg is considered complete enough to protect; future
// client transport work should not mutate the final-output probe into a weaker
// or less observable path.

const PROBE_RUNTIME: &str = include_str!(concat!(
    env!("CARGO_MANIFEST_DIR"),
    "/server/src/output_delay_probe/probe_runtime.rs"
));
const MEDIA_ENCODING: &str = include_str!(concat!(
    env!("CARGO_MANIFEST_DIR"),
    "/server/src/output_delay_probe/media_encoding.rs"
));
const TIMELINE_CONFIG: &str = include_str!(concat!(
    env!("CARGO_MANIFEST_DIR"),
    "/server/src/output_delay_probe/timeline_config.rs"
));

#[test]
fn server_output_probe_uses_final_uvc_uac_handoff_not_test_only_shortcuts() {
    for marker in [
        "same final server output handoff calls as received client media",
        "relay.feed(VideoPacket",
        "sink.push(&AudioPacket",
        "sink.finish();",
        "server-final-output-handoff",
        "video CameraRelay::feed; audio Voice::push",
        "client_uplink_included: false",
    ] {
        assert!(
            PROBE_RUNTIME.contains(marker) || TIMELINE_CONFIG.contains(marker),
            "server-to-RCT probe should preserve final handoff marker {marker}"
        );
    }
}

#[test]
fn server_output_probe_generates_identity_rich_flash_and_tone_media() {
    for marker in [
        "EVENT_COLORS",
        "DEFAULT_EVENT_WIDTH_CODES",
        "event_width_codes",
        "event signature code {code} is unsupported; use values 1..16",
        "render_audio_chunk",
        "probe_color_for_code",
        "coded flash schedule",
        "HEVC frames let the final RCT capture prove sync",
    ] {
        assert!(
            MEDIA_ENCODING.contains(marker) || TIMELINE_CONFIG.contains(marker),
            "server-to-RCT synthetic media should preserve coded marker {marker}"
        );
    }
}

#[test]
fn server_output_probe_timeline_exports_freshness_reference_fields() {
    for marker in [
        "lesavka.output-delay-server-timeline.v1",
        "theia-server-generated",
        "server generator -> UVC/UAC sinks",
        "server_pipeline_reference",
        "server_start_unix_ns",
        "video_feed_unix_ns",
        "audio_push_unix_ns",
        "server_feed_delta_ms",
    ] {
        assert!(
            TIMELINE_CONFIG.contains(marker),
            "server-to-RCT timeline should preserve freshness marker {marker}"
        );
    }
}
