Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.
test(player): add deterministic cross-platform contract tests and support // UNC paths
Samir Hossains62a623ba2f85
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 881f804..5e27e1d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -9,7 +9,7 @@- Pre-downloaded subtitles locally for `mpv` with remote URL fallback, parallelized subtitle downloads with `StreamRelay` sidecar startup, appended an 8-char URL hash to subtitle filenames, and sanitized commas in `--script-opts`.- Mounted `xdg-cache/moviebox-tui:ro`, `xdg-data/moviebox-tui`, and `/tmp:ro` in `flatpak run` while keeping custom user Flatpak flags so sandboxed `mpv` and `VLC` can read subtitles and write watch progress.- Served Termux private-storage subtitles over the local `StreamRelay` `/sub/` loopback endpoint when Android shared storage is unavailable, and restricted startup subtitle cleanup to internal cache and temp folders.- - Parsed player `stderr` and exit codes to report specific failure reasons (`HTTP 403`, `HTTP 404`, `HTTP 410`, timeout, connection refused).+ - Parsed player `stderr` and exit codes to report specific failure reasons (`HTTP 403`, `HTTP 404`, `HTTP 410`, timeout, connection refused), and added deterministic cross-platform contract integration tests (`tests/player_contract.rs`) asserting VLC Win32/UNC paths, IINA CLI option schemas, and header support across OSes.- **StreamRelay Proxy & Downloader**:- Forwarded `User-Agent` and `Referer` while isolating stream cookies (`Cookie: Edge-Cache-Cookie=...`) to same-host requests across `StreamRelay`, subtitle pre-downloads, and media downloads.- Capped `.m4s` segment chunk fetching in `StreamRelay` to batches of 16 concurrent `Range` requests, registered in-flight segment wait futures under lock, and required `http://` or `https://` schemes on `/proxy?url=` routes.diff --git a/src/player.rs b/src/player.rsindex 41218a1..7071edf 100644--- a/src/player.rs+++ b/src/player.rs@@ -1568,7 +1568,8 @@ fn vlc_subtitle_path(path: &str) -> String {}let bytes = path.as_bytes();let is_windows_drive = bytes.len() >= 2 && bytes[0].is_ascii_alphabetic() && bytes[1] == b':';- if is_windows_drive || path.starts_with(r"\\") {+ let is_unc = path.starts_with(r"\\") || path.starts_with("//");+ if is_windows_drive || is_unc {path.replace('/', r"\")} else {path.to_string()diff --git a/tests/player_contract.rs b/tests/player_contract.rsnew file mode 100644index 0000000..46a1dff--- /dev/null+++ b/tests/player_contract.rs@@ -0,0 +1,226 @@+use moviebox_tui::tui::player::{PlayerKind, command, supports_headers};+use std::process::Command;++fn get_cmd_args(cmd: &Command) -> Vec<String> {+ cmd.get_args()+ .map(|a| a.to_string_lossy().into_owned())+ .collect()+}++#[test]+fn test_vlc_win32_path_contract_never_emits_forward_slashes_for_local_subtitles() {+ let windows_drive_paths = [+ r"C:\Users\Default\AppData\Local\MovieBox-Tui\subs\Inception_a1b2c3d4.srt",+ "C:/Users/Default/AppData/Local/MovieBox-Tui/subs/Inception_a1b2c3d4.srt",+ r"D:\Media\Subtitles\Sub.ass",+ "D:/Media/Subtitles/Sub.ass",+ ];++ for path in windows_drive_paths {+ let cmd = command(+ PlayerKind::Vlc,+ "https://cdn.example.com/video.mp4",+ Some(path),+ &[],+ None,+ None,+ None,+ None,+ );+ let args = get_cmd_args(&cmd);+ let sub_arg = args+ .iter()+ .find(|a| a.starts_with("--sub-file="))+ .expect("VLC command must contain --sub-file argument");++ let sub_value = sub_arg.strip_prefix("--sub-file=").unwrap();+ assert!(+ !sub_value.contains('/'),+ "VLC Win32 contract violation: local Windows drive path must not contain forward slashes, got: {sub_value}"+ );+ assert!(+ sub_value.contains('\\'),+ "VLC Win32 contract violation: local Windows drive path must contain backslashes, got: {sub_value}"+ );+ assert!(+ sub_value.starts_with(r"C:\") || sub_value.starts_with(r"D:\"),+ "VLC Win32 contract violation: expected drive prefix, got: {sub_value}"+ );+ }+}++#[test]+fn test_vlc_unc_path_contract_preserves_network_share_backslashes() {+ let unc_paths = [+ r"\\nas\media\subtitles\movie.srt",+ "//nas/media/subtitles/movie.srt",+ ];++ for path in unc_paths {+ let cmd = command(+ PlayerKind::Vlc,+ "https://cdn.example.com/video.mp4",+ Some(path),+ &[],+ None,+ None,+ None,+ None,+ );+ let args = get_cmd_args(&cmd);+ let sub_arg = args+ .iter()+ .find(|a| a.starts_with("--sub-file="))+ .expect("VLC command must contain --sub-file argument");++ let sub_value = sub_arg.strip_prefix("--sub-file=").unwrap();+ assert!(+ sub_value.starts_with(r"\\"),+ "VLC UNC contract violation: path must start with \\\\, got: {sub_value}"+ );+ assert!(+ !sub_value[2..].contains('/'),+ "VLC UNC contract violation: path must not contain forward slashes, got: {sub_value}"+ );+ }+}++#[test]+fn test_vlc_http_remote_subtitle_contract_preserves_url_scheme() {+ let remote_urls = [+ "https://cdn.example.com/subtitles/movie.vtt?token=abc",+ "http://127.0.0.1:8080/sub/https%3A%2F%2Fcdn.example.com%2Fsub.srt",+ ];++ for url in remote_urls {+ let cmd = command(+ PlayerKind::Vlc,+ "https://cdn.example.com/video.mp4",+ Some(url),+ &[],+ None,+ None,+ None,+ None,+ );+ let args = get_cmd_args(&cmd);+ let sub_arg = args+ .iter()+ .find(|a| a.starts_with("--sub-file="))+ .expect("VLC command must contain --sub-file argument");++ let sub_value = sub_arg.strip_prefix("--sub-file=").unwrap();+ assert!(+ sub_value.starts_with("http://") || sub_value.starts_with("https://"),+ "VLC remote URL contract violation: URL scheme was altered, got: {sub_value}"+ );+ assert_eq!(+ sub_value, url,+ "VLC remote URL contract violation: URL was modified unexpectedly"+ );+ }+}++#[test]+fn test_iina_cli_contract_uses_plural_sub_files_and_filters_scripts() {+ let cmd = command(+ PlayerKind::Iina,+ "https://cdn.example.com/video.mp4",+ Some("/tmp/moviebox_subs/show_s01e01.vtt"),+ &[("Referer".to_string(), "https://example.com".to_string())],+ Some((1280, 720)),+ Some(120),+ Some(("moviebox", "subj_42", 1, 1)),+ Some(1080),+ );+ let args = get_cmd_args(&cmd);++ assert!(+ args.contains(&"--mpv-sub-files=/tmp/moviebox_subs/show_s01e01.vtt".to_string()),+ "IINA contract violation: iina-cli requires plural --mpv-sub-files, but argument was missing. Found args: {args:?}"+ );++ assert!(+ !args.iter().any(|a| a.starts_with("--mpv-sub-file=")),+ "IINA contract violation: singular alias --mpv-sub-file is rejected by iina-cli CLIParser.swift"+ );++ #[cfg(target_os = "macos")]+ assert!(+ !args.iter().any(|a| a.starts_with("--mpv-script=")),+ "IINA contract violation: external Lua tracker script is not executable via iina-cli CLI"+ );+}++#[test]+fn test_mpv_contract_uses_sub_file_and_sanitizes_script_opts() {+ let script_opts = moviebox_tui::tui::player::format_mpv_script_opts(+ "addons,malicious",+ "subj,evil=1",+ 2,+ 5,+ std::path::Path::new("/tmp/movie,state/test.json"),+ );++ assert!(+ !script_opts.contains("moviebox-provider=addons,malicious"),+ "mpv --script-opts contract violation: commas must be sanitized to prevent key-value option injection"+ );+ assert!(+ script_opts.contains("moviebox-provider=addons_malicious"),+ "mpv --script-opts contract violation: provider comma was not sanitized: {script_opts}"+ );+ assert!(+ script_opts.contains("moviebox-subject_id=subj_evil=1"),+ "mpv --script-opts contract violation: subject_id comma was not sanitized: {script_opts}"+ );+}++#[test]+fn test_vlc_single_instance_flag_contract_on_non_macos() {+ let cmd = command(+ PlayerKind::Vlc,+ "https://cdn.example.com/video.mp4",+ Some("/tmp/sub.srt"),+ &[("User-Agent".to_string(), "MovieBox".to_string())],+ None,+ Some(30),+ None,+ None,+ );+ let args = get_cmd_args(&cmd);++ #[cfg(not(target_os = "macos"))]+ assert!(+ args.contains(&"--no-one-instance".to_string()),+ "VLC contract violation on non-macOS: --no-one-instance required so running VLC windows do not strip subtitles or resume offset"+ );++ #[cfg(target_os = "macos")]+ assert!(+ !args.contains(&"--no-one-instance".to_string()),+ "VLC contract violation on macOS: VLC for macOS does not support --no-one-instance"+ );+}++#[test]+fn test_player_supports_headers_contract_matrix() {+ let dummy_headers = vec![("Authorization".to_string(), "Bearer secret".to_string())];++ assert!(+ supports_headers(PlayerKind::Mpv, &dummy_headers),+ "mpv must support custom headers"+ );+ assert!(+ supports_headers(PlayerKind::Iina, &dummy_headers),+ "IINA must support custom headers"+ );+ assert!(+ supports_headers(PlayerKind::Vlc, &dummy_headers),+ "VLC must support custom headers (via sidecar proxy or --http-*)"+ );+ assert!(+ supports_headers(PlayerKind::AndroidIntent, &dummy_headers),+ "AndroidIntent must support headers (via StreamRelay loopback)"+ );+}diff --git a/tests/update_lifecycle.rs b/tests/update_lifecycle.rsindex 4ca1366..7ee47ae 100644--- a/tests/update_lifecycle.rs+++ b/tests/update_lifecycle.rs@@ -317,7 +317,7 @@ fn test_homebrew_detection_and_safe_refusal() {);assert!(is_homebrew_managed(linuxbrew_path));- let standard_user_path = std::path::Path::new("/Users/samir/.local/bin/moviebox-tui");+ let standard_user_path = std::path::Path::new("/usr/local/bin/moviebox-tui");assert!(!is_homebrew_managed(standard_user_path));}