// Contracts for actionable, bounded diagnostic logging.
//
// Scope: inspect upstream/drop logging, audio recovery, and diagnostics text.
// Targets: client live-media and diagnostics source.
// Why: freshness-first media paths intentionally drop packets; those drops
// must be aggregated into useful evidence instead of warning on every packet.

const UPLINK_DROP_LOGGING_SRC: &str = include_str!(concat!(
    env!("CARGO_MANIFEST_DIR"),
    "/client/src/app/uplink_media/drop_logging.rs"
));
const AUDIO_RECOVERY_SRC: &str = include_str!(concat!(
    env!("CARGO_MANIFEST_DIR"),
    "/client/src/app/audio_recovery_config.rs"
));
const UPLINK_TELEMETRY_SRC: &str = include_str!(concat!(
    env!("CARGO_MANIFEST_DIR"),
    "/client/src/uplink_telemetry.rs"
));
const SNAPSHOT_REPORT_TEXT: &str = include_str!(concat!(
    env!("CARGO_MANIFEST_DIR"),
    "/client/src/launcher/diagnostics/snapshot_report_text.rs"
));

#[test]
fn freshness_first_drops_are_aggregated_before_warning() {
    for marker in [
        "UplinkDropLogLimiter",
        "suppressed_full",
        "suppressed_stale",
        "UPLINK_DROP_WARN_INTERVAL",
        "Duration::from_secs(5)",
        "dropped_queue_full",
        "dropped_stale",
        "upstream media queue drop suppressed from WARN noise",
    ] {
        assert!(
            UPLINK_DROP_LOGGING_SRC.contains(marker),
            "uplink drop logging should preserve aggregation marker {marker}"
        );
    }
}

#[test]
fn repeated_audio_recovery_logs_are_rate_limited() {
    for marker in [
        "AudioFailureLogLimiter",
        "AUDIO_FAILURE_WARN_INTERVAL",
        "self.suppressed_repeats = self.suppressed_repeats.saturating_add(1)",
        "audio stream repeated unhealthy state suppressed from WARN noise",
    ] {
        assert!(
            AUDIO_RECOVERY_SRC.contains(marker),
            "audio recovery logging should preserve rate-limit marker {marker}"
        );
    }
}

#[test]
fn diagnostics_report_exposes_drop_totals_without_log_spam() {
    for marker in [
        "dropped_packets",
        "dropped_queue_full_packets",
        "dropped_stale_packets",
        "drops(total/full/stale)",
        "planner_stale_audio_drops",
        "planner_stale_video_drops",
        "planner_skew_video_drops",
    ] {
        assert!(
            UPLINK_TELEMETRY_SRC.contains(marker) || SNAPSHOT_REPORT_TEXT.contains(marker),
            "diagnostics should preserve aggregate drop marker {marker}"
        );
    }
}
