use crate::brain::tools::analyze_video::detect_video_mime_type;
#[test]
fn detects_common_video_mime_types() {
assert_eq!(detect_video_mime_type("clip.mp4"), "video/mp4");
assert_eq!(detect_video_mime_type("clip.m4v"), "video/mp4");
assert_eq!(detect_video_mime_type("clip.mov"), "video/quicktime");
assert_eq!(detect_video_mime_type("clip.webm"), "video/webm");
assert_eq!(detect_video_mime_type("clip.mkv"), "video/x-matroska");
assert_eq!(detect_video_mime_type("clip.avi"), "video/x-msvideo");
assert_eq!(detect_video_mime_type("clip.3gp"), "video/3gpp");
assert_eq!(detect_video_mime_type("clip.flv"), "video/x-flv");
}
#[test]
fn mime_detection_is_case_insensitive() {
assert_eq!(detect_video_mime_type("CLIP.MP4"), "video/mp4");
assert_eq!(detect_video_mime_type("Movie.MOV"), "video/quicktime");
}
#[test]
fn unknown_extension_defaults_to_mp4() {
assert_eq!(detect_video_mime_type("clip.xyz"), "video/mp4");
assert_eq!(detect_video_mime_type("noext"), "video/mp4");
}
#[test]
fn full_path_is_handled() {
assert_eq!(
detect_video_mime_type("/tmp/opencrabs/downloads/recording.webm"),
"video/webm"
);
}
const ANALYZE_VIDEO_SRC: &str = include_str!("../brain/tools/analyze_video.rs");
#[test]
fn fallback_constants_are_used_by_extraction() {
let code: String = ANALYZE_VIDEO_SRC
.lines()
.filter(|l| !l.trim_start().starts_with("//"))
.collect::<Vec<_>>()
.join("\n");
assert!(
code.contains("FALLBACK_MAX_FRAMES.to_string()"),
"FALLBACK_MAX_FRAMES must feed ffmpeg's -frames:v cap — if this fails the \
frame-extraction fallback was removed or the constant went dead again."
);
assert!(
code.contains("fps={FALLBACK_FPS}") || code.contains("FALLBACK_FPS"),
"FALLBACK_FPS must drive the ffmpeg fps filter and the per-frame timestamps."
);
assert!(
code.contains("frame_extraction_fallback"),
"the frame-extraction fallback method must exist"
);
assert!(
code.contains("ffmpeg"),
"the fallback must shell out to ffmpeg for frame extraction"
);
}
#[test]
fn native_failure_triggers_fallback_not_immediate_error() {
let code: String = ANALYZE_VIDEO_SRC
.lines()
.filter(|l| !l.trim_start().starts_with("//"))
.collect::<Vec<_>>()
.join("\n");
assert!(
code.contains("try_native_video") && code.contains("frame_extraction_fallback"),
"execute must try native video then fall back on failure"
);
assert!(
code.contains("Ok(result) if result.success => return Ok(result)"),
"only a successful native result short-circuits; failures must fall through to fallback"
);
}