// Contracts for T0-T5 freshness stage timing.
//
// Scope: inspect client-to-RCT black-box summary helpers.
// Targets: `scripts/manual/client_rct_transport_summary.py` and
// `scripts/manual/client_rct_transport_layers.py`.
// Why: upstream freshness failures should point to a stage, not just say the
// final RCT media was late.

const TRANSPORT_SUMMARY: &str = include_str!(concat!(
    env!("CARGO_MANIFEST_DIR"),
    "/scripts/manual/client_rct_transport_summary.py"
));
const TRANSPORT_LAYERS: &str = include_str!(concat!(
    env!("CARGO_MANIFEST_DIR"),
    "/scripts/manual/client_rct_transport_layers.py"
));

#[test]
fn freshness_summary_exposes_t0_to_t5_stage_markers() {
    for marker in [
        "client_start_unix_ns",
        "client_planned_start_us",
        "local_bundle_age_p95_ms",
        "camera_client_queue_age_p95_ms",
        "microphone_client_queue_age_p95_ms",
        "server_receive_age_p95_ms",
        "sink_late_p95_ms",
        "video_age_p95_ms",
        "audio_age_p95_ms",
        "post_client_send_worst_p95_ms",
    ] {
        assert!(
            TRANSPORT_SUMMARY.contains(marker) || TRANSPORT_LAYERS.contains(marker),
            "transport diagnostics should preserve T0-T5 marker {marker}"
        );
    }
}

#[test]
fn freshness_failures_are_classified_by_likely_bottleneck() {
    for marker in [
        "freshness_bottleneck",
        "within_limit",
        "evidence_incomplete",
        "client_queue_or_bundle_generation",
        "server_receive_or_ingress_queue",
        "client_to_server_transport",
        "post_client_send_to_rct_path",
        "needs_deeper_introspection",
    ] {
        assert!(
            TRANSPORT_SUMMARY.contains(marker) || TRANSPORT_LAYERS.contains(marker),
            "freshness failure should preserve bottleneck label {marker}"
        );
    }
}

#[test]
fn sync_and_smoothness_reports_keep_evidence_counts_near_stage_timing() {
    for marker in [
        "paired_event_count",
        "min_paired_events",
        "expected_event_count",
        "p95_abs_skew_ms",
        "video_hiccups",
        "audio_hiccups",
        "video_p95_jitter_ms",
        "synthetic evidence",
        "upstream sampler",
    ] {
        assert!(
            TRANSPORT_SUMMARY.contains(marker),
            "transport summary should preserve sync/smoothness marker {marker}"
        );
    }
}
