Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.
feat(updater): synchronize modal geometry and add single-flight update check
Samir Hossains4fada24995dd
diff --git a/src/tui/app/mouse.rs b/src/tui/app/mouse.rsindex e56e07a..f22da10 100644--- a/src/tui/app/mouse.rs+++ b/src/tui/app/mouse.rs@@ -88,18 +88,17 @@ impl App {return true;}- if self.state.update_available.is_some() {- let popup = crate::tui::overlay::centered(area, 46, 7, 36, 60);- if popup.contains(ratatui::layout::Position::new(col, row)) {- let dismiss_y = popup.y + popup.height.saturating_sub(2);- if row == dismiss_y {- if col < popup.x + popup.width / 2 {- if let Some((ver, _)) = &self.state.update_available {- let url = format!(- "https://github.com/mesamirh/MovieBox-Tui/releases/tag/v{ver}"- );- let _ = open::that(&url);- }+ if let Some((ver, notes)) = &self.state.update_available {+ let layout = crate::tui::overlay::update_modal_layout(area, notes);+ if layout+ .popup_area+ .contains(ratatui::layout::Position::new(col, row))+ {+ if row == layout.button_row_y {+ if col < layout.open_button_midpoint_x {+ let url =+ format!("https://github.com/mesamirh/MovieBox-Tui/releases/tag/v{ver}");+ let _ = open::that(&url);}self.state.update_available = None;}diff --git a/src/tui/app/run.rs b/src/tui/app/run.rsindex 74fde78..4660efb 100644--- a/src/tui/app/run.rs+++ b/src/tui/app/run.rs@@ -411,30 +411,17 @@ impl App {use ratatui::text::{Line, Span};use ratatui::widgets::{Block, Borders, Paragraph};+ let layout = crate::tui::overlay::update_modal_layout(area, notes);+ let popup_area = layout.popup_area;+ let display_count = layout.display_count;+ let has_more = layout.has_more;+let note_lines: Vec<&str> = notes.lines().map(|l| l.trim()).filter(|l| !l.is_empty()).collect();- let min_w: u16 = 46;- let max_w: u16 = 72;- let desired_w = max_w.min(area.width.saturating_sub(4)).max(min_w);-- let header_rows: u16 = 5;- let footer_rows: u16 = 3;- let available_height = area.height.saturating_sub(4);- let available_note_rows =- (available_height.saturating_sub(header_rows + footer_rows) as usize).clamp(2, 10);-- let display_count = note_lines.len().min(available_note_rows);- let has_more = note_lines.len() > display_count;- let total_rows =- header_rows + (display_count as u16) + (if has_more { 1 } else { 0 }) + footer_rows;- let desired_h = total_rows.clamp(10, available_height.max(10));-- let popup_area =- crate::tui::overlay::centered(area, desired_w, desired_h, min_w, max_w);crate::tui::clear_area(frame, area, &self.theme);let mut text = vec![diff --git a/src/tui/app/search.rs b/src/tui/app/search.rsindex 5e934c2..4452d06 100644--- a/src/tui/app/search.rs+++ b/src/tui/app/search.rs@@ -143,11 +143,16 @@ impl App {crate::tui::commands::ParsedCommand::Update => {self.state.search_query.clear();self.state.input_mode = InputMode::Normal;- self.state.update_available = None;- self.state.manual_update_check = true;- self.state- .set_status("Checking GitHub for updates...".to_string(), 180);- self.action_sender.send(Action::CheckForUpdates).ok();+ if !self.state.is_checking_updates {+ self.state.update_available = None;+ self.state.manual_update_check = true;+ self.state+ .set_status("Checking GitHub for updates...".to_string(), 180);+ self.action_sender.send(Action::CheckForUpdates).ok();+ } else {+ self.state+ .set_status("Checking GitHub for updates...".to_string(), 180);+ }Some(true)}crate::tui::commands::ParsedCommand::ToggleUpdate => {diff --git a/src/tui/app/system.rs b/src/tui/app/system.rsindex 8dd4898..13e81aa 100644--- a/src/tui/app/system.rs+++ b/src/tui/app/system.rs@@ -340,14 +340,23 @@ impl App {}Action::CheckForUpdates => {+ if self.state.is_checking_updates {+ return None;+ }+ self.state.is_checking_updates = true;let update_sender = self.action_sender.clone();tokio::spawn(async move {- let result = crate::tui::updater::check(env!("CARGO_PKG_VERSION")).await;+ let task = tokio::spawn(crate::tui::updater::check(env!("CARGO_PKG_VERSION")));+ let result = match task.await {+ Ok(res) => res,+ Err(join_err) => Err(format!("update check task error: {join_err}")),+ };update_sender.send(Action::UpdateAvailable(result)).ok();});}Action::UpdateAvailable(result) => {+ self.state.is_checking_updates = false;self.state.last_update_check = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap_or_default()diff --git a/src/tui/overlay.rs b/src/tui/overlay.rsindex f42939d..8c7452a 100644--- a/src/tui/overlay.rs+++ b/src/tui/overlay.rs@@ -367,3 +367,128 @@ fn notification_style(NotificationKind::Error => ("ERROR", theme.error),}}++#[derive(Debug, Clone, Copy, PartialEq, Eq)]+pub struct UpdateModalLayout {+ pub popup_area: Rect,+ pub display_count: usize,+ pub has_more: bool,+ pub button_row_y: u16,+ pub open_button_midpoint_x: u16,+}++pub fn update_modal_layout(area: Rect, notes: &str) -> UpdateModalLayout {+ let note_lines_count = notes+ .lines()+ .map(|l| l.trim())+ .filter(|l| !l.is_empty())+ .count();++ let min_w: u16 = 46;+ let max_w: u16 = 72;+ let desired_w = max_w.min(area.width.saturating_sub(4)).max(min_w);++ let header_rows: u16 = 5;+ let footer_rows: u16 = 3;+ let available_height = area.height.saturating_sub(4);+ let available_note_rows =+ (available_height.saturating_sub(header_rows + footer_rows) as usize).clamp(2, 10);++ let display_count = note_lines_count.min(available_note_rows);+ let has_more = note_lines_count > display_count;+ let total_rows =+ header_rows + (display_count as u16) + (if has_more { 1 } else { 0 }) + footer_rows;+ let desired_h = total_rows.clamp(10, available_height.max(10));++ let popup_area = centered(area, desired_w, desired_h, min_w, max_w);+ let button_row_y = popup_area.y + popup_area.height.saturating_sub(2);+ let open_button_midpoint_x = popup_area.x + popup_area.width / 2;++ UpdateModalLayout {+ popup_area,+ display_count,+ has_more,+ button_row_y,+ open_button_midpoint_x,+ }+}++#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn test_update_modal_mouse_hitbox_matches_rendered_geometry() {+ let area = Rect::new(0, 0, 80, 24);+ let notes = "Line 1\nLine 2\nLine 3\nLine 4";+ let layout = update_modal_layout(area, notes);++ assert_eq!(layout.popup_area.width, 72);+ assert_eq!(layout.display_count, 4);+ assert!(!layout.has_more);+ assert_eq!(layout.popup_area.height, 12);+ assert_eq!(layout.popup_area.x, (80 - 72) / 2);+ assert_eq!(layout.popup_area.y, (24 - 12) / 2);+ assert_eq!(layout.button_row_y, layout.popup_area.y + 10);+ assert_eq!(layout.open_button_midpoint_x, layout.popup_area.x + 36);+ }++ #[test]+ fn test_update_modal_open_release_click() {+ let area = Rect::new(0, 0, 80, 24);+ let notes = "### Highlights\n- Feature A\n- Feature B";+ let layout = update_modal_layout(area, notes);++ let click_x = layout.popup_area.x + 5;+ let click_y = layout.button_row_y;++ assert!(+ layout+ .popup_area+ .contains(ratatui::layout::Position::new(click_x, click_y))+ );+ assert_eq!(click_y, layout.button_row_y);+ assert!(click_x < layout.open_button_midpoint_x);+ }++ #[test]+ fn test_update_modal_dismiss_click() {+ let area = Rect::new(0, 0, 80, 24);+ let notes = "Feature A";+ let layout = update_modal_layout(area, notes);++ let dismiss_x = layout.open_button_midpoint_x + 5;+ let dismiss_y = layout.button_row_y;++ assert!(+ layout+ .popup_area+ .contains(ratatui::layout::Position::new(dismiss_x, dismiss_y))+ );+ assert_eq!(dismiss_y, layout.button_row_y);+ assert!(dismiss_x >= layout.open_button_midpoint_x);++ let outside_x = layout.popup_area.x.saturating_sub(2);+ let outside_y = layout.popup_area.y.saturating_sub(2);+ assert!(+ !layout+ .popup_area+ .contains(ratatui::layout::Position::new(outside_x, outside_y))+ );+ }++ #[test]+ fn test_update_modal_geometry_bounds_various_screens() {+ let notes = "Line 1\nLine 2\nLine 3\nLine 4\nLine 5\nLine 6\nLine 7\nLine 8\nLine 9\nLine 10\nLine 11";++ let compact = update_modal_layout(Rect::new(0, 0, 40, 15), notes);+ assert!(compact.popup_area.width <= 38);+ assert!(compact.popup_area.height <= 13);+ assert!(compact.has_more);++ let large = update_modal_layout(Rect::new(0, 0, 160, 50), notes);+ assert_eq!(large.popup_area.width, 72);+ assert_eq!(large.display_count, 10);+ assert!(large.has_more);+ }+}diff --git a/src/tui/state.rs b/src/tui/state.rsindex c7c91a5..5c89433 100644--- a/src/tui/state.rs+++ b/src/tui/state.rs@@ -137,6 +137,7 @@ pub struct AppState {pub auto_update: bool,pub last_update_check: u64,pub manual_update_check: bool,+ pub is_checking_updates: bool,pub download_progress: Option<f64>,pub download_status: Option<String>,@@ -279,6 +280,7 @@ impl Default for AppState {auto_update: true,last_update_check: 0,manual_update_check: false,+ is_checking_updates: false,download_progress: None,download_status: None,diff --git a/src/updater.rs b/src/updater.rsindex 918a6be..dd229b3 100644--- a/src/updater.rs+++ b/src/updater.rs@@ -1,7 +1,97 @@const OWNER: &str = "mesamirh";const REPOSITORY: &str = "MovieBox-Tui";-pub async fn check(current: &str) -> Result<Option<(String, String)>, String> {+#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]+pub struct ReleaseAsset {+ pub name: String,+ pub download_url: String,+ pub size: Option<u64>,+}++#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]+pub struct Release {+ pub version: String,+ pub tag_name: String,+ pub notes: String,+ pub assets: Vec<ReleaseAsset>,+}++#[derive(Debug, Clone, Copy, PartialEq, Eq)]+pub enum TargetPlatform {+ MacosUniversal,+ LinuxX64,+ LinuxArm64,+ WindowsX64,+ WindowsArm64,+}++impl TargetPlatform {+ pub fn current() -> Option<Self> {+ Self::detect(+ std::env::consts::OS,+ std::env::consts::ARCH,+ is_termux_environment(),+ )+ }++ pub fn detect(os: &str, arch: &str, is_termux: bool) -> Option<Self> {+ if is_termux {+ if arch == "aarch64" || arch == "arm64" {+ return Some(Self::LinuxArm64);+ } else {+ return None;+ }+ }++ match os {+ "macos" | "darwin" => Some(Self::MacosUniversal),+ "linux" => match arch {+ "x86_64" | "x86-64" | "x64" | "amd64" => Some(Self::LinuxX64),+ "aarch64" | "arm64" => Some(Self::LinuxArm64),+ _ => None,+ },+ "windows" => match arch {+ "x86_64" | "x86-64" | "x64" | "amd64" => Some(Self::WindowsX64),+ "aarch64" | "arm64" => Some(Self::WindowsArm64),+ _ => None,+ },+ _ => None,+ }+ }++ pub fn expected_asset_name(self) -> &'static str {+ match self {+ Self::MacosUniversal => "MovieBox_macOS_Universal.tar.gz",+ Self::LinuxX64 => "MovieBox_Linux_x64.tar.gz",+ Self::LinuxArm64 => "MovieBox_Linux_arm64.tar.gz",+ Self::WindowsX64 => "MovieBox_Windows_x64.zip",+ Self::WindowsArm64 => "MovieBox_Windows_arm64.zip",+ }+ }+}++pub fn is_termux_environment() -> bool {+ std::env::var("PREFIX").is_ok_and(|p| p.contains("com.termux"))+}++impl Release {+ pub fn find_compatible_asset(&self, platform: TargetPlatform) -> Option<&ReleaseAsset> {+ let expected = platform.expected_asset_name();+ self.assets.iter().find(|a| a.name == expected)+ }++ pub fn find_checksum_asset(&self) -> Option<&ReleaseAsset> {+ self.assets.iter().find(|a| a.name == "SHA256SUMS")+ }++ pub fn is_compatible_with_current_platform(&self) -> bool {+ TargetPlatform::current()+ .and_then(|p| self.find_compatible_asset(p))+ .is_some()+ }+}++pub async fn check_release(current: &str) -> Result<Option<Release>, String> {let release = match fetch_release().await {Ok(release) => release,Err(error) => {@@ -10,7 +100,9 @@ pub async fn check(current: &str) -> Result<Option<(String, String)>, String> {log::info!("resolved latest release via redirect: {tag}");Release {version: tag.trim_start_matches('v').to_string(),+ tag_name: tag,notes: String::new(),+ assets: Vec::new(),}}};@@ -19,7 +111,12 @@ pub async fn check(current: &str) -> Result<Option<(String, String)>, String> {return Ok(None);}- Ok(Some((release.version.clone(), release.notes.clone())))+ Ok(Some(release))+}++pub async fn check(current: &str) -> Result<Option<(String, String)>, String> {+ let release = check_release(current).await?;+ Ok(release.map(|r| (r.version, r.notes)))}fn is_newer(current: &str, other: &str) -> bool {@@ -52,9 +149,28 @@ async fn fetch_release() -> Result<Release, String> {let item: serde_json::Value = resp.json().await.map_err(|e| format!("bad JSON: {e}"))?;let tag = item["tag_name"].as_str().ok_or("missing tag_name")?;let notes = item["body"].as_str().unwrap_or("").to_string();+ let assets = if let Some(arr) = item["assets"].as_array() {+ arr.iter()+ .filter_map(|a| {+ let name = a["name"].as_str()?.to_string();+ let download_url = a["browser_download_url"].as_str()?.to_string();+ let size = a["size"].as_u64();+ Some(ReleaseAsset {+ name,+ download_url,+ size,+ })+ })+ .collect()+ } else {+ Vec::new()+ };+Ok(Release {version: tag.trim_start_matches('v').to_string(),+ tag_name: tag.to_string(),notes,+ assets,})}@@ -89,7 +205,190 @@ fn http_client() -> Result<reqwest::Client, String> {.map_err(|e| format!("HTTP client: {e}"))}-struct Release {- version: String,- notes: String,+#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn test_is_newer_comprehensive_matrix() {+ assert!(is_newer("0.1.9", "0.1.10"));+ assert!(is_newer("0.1.10", "0.1.11"));+ assert!(is_newer("0.1.12", "0.1.13"));+ assert!(is_newer("1.9.0", "1.10.0"));+ assert!(is_newer("0.9.9", "1.0.0"));++ assert!(!is_newer("0.1.12", "0.1.12"));+ assert!(!is_newer("1.0.0", "1.0.0"));++ assert!(!is_newer("0.1.13", "0.1.12"));+ assert!(!is_newer("1.10.0", "1.9.0"));+ assert!(!is_newer("2.0.0", "1.9.9"));++ assert!(is_newer("v0.1.9", "v0.1.10"));+ assert!(is_newer("0.1.9", "v0.1.10"));+ assert!(is_newer("v0.1.9", "0.1.10"));+ assert!(!is_newer("v0.1.12", "v0.1.12"));+ assert!(!is_newer("v0.1.13", "v0.1.12"));++ assert!(is_newer("1.0.0-beta", "1.0.0"));+ assert!(is_newer("1.0.0-rc.1", "1.0.0"));+ assert!(is_newer("1.0.0-beta.1", "1.0.0-beta.2"));+ assert!(!is_newer("1.0.0", "1.0.0-beta"));+ }++ #[test]+ fn test_is_newer_non_semver_fallback() {+ assert!(is_newer("0.1.12", "custom-build-1"));+ assert!(!is_newer("custom-build-1", "custom-build-1"));+ }++ #[test]+ fn test_release_json_deserialization() {+ let raw_json = "{\"tag_name\": \"v0.1.13\", \"body\": \"### New Features\\n- Added cool feature\\n- Fixed bugs\"}";+ let item: serde_json::Value = serde_json::from_str(raw_json).unwrap();+ let tag = item["tag_name"].as_str().unwrap();+ let notes = item["body"].as_str().unwrap_or("").to_string();+ let release = Release {+ version: tag.trim_start_matches('v').to_string(),+ tag_name: tag.to_string(),+ notes,+ assets: Vec::new(),+ };+ assert_eq!(release.version, "0.1.13");+ assert!(release.notes.contains("### New Features"));+ }++ #[test]+ fn test_release_json_missing_body_graceful() {+ let raw_json = "{\"tag_name\": \"v0.1.13\"}";+ let item: serde_json::Value = serde_json::from_str(raw_json).unwrap();+ let tag = item["tag_name"].as_str().unwrap();+ let notes = item["body"].as_str().unwrap_or("").to_string();+ assert_eq!(notes, "");+ assert_eq!(tag.trim_start_matches('v'), "0.1.13");+ }++ fn sample_release_with_all_assets() -> Release {+ Release {+ version: "0.1.13".to_string(),+ tag_name: "v0.1.13".to_string(),+ notes: "Bug fixes and improvements".to_string(),+ assets: vec![+ ReleaseAsset {+ name: "MovieBox_macOS_Universal.tar.gz".to_string(),+ download_url: "https://github.com/mesamirh/MovieBox-Tui/releases/download/v0.1.13/MovieBox_macOS_Universal.tar.gz".to_string(),+ size: Some(15_000_000),+ },+ ReleaseAsset {+ name: "MovieBox_Linux_x64.tar.gz".to_string(),+ download_url: "https://github.com/mesamirh/MovieBox-Tui/releases/download/v0.1.13/MovieBox_Linux_x64.tar.gz".to_string(),+ size: Some(12_000_000),+ },+ ReleaseAsset {+ name: "MovieBox_Linux_arm64.tar.gz".to_string(),+ download_url: "https://github.com/mesamirh/MovieBox-Tui/releases/download/v0.1.13/MovieBox_Linux_arm64.tar.gz".to_string(),+ size: Some(11_500_000),+ },+ ReleaseAsset {+ name: "MovieBox_Windows_x64.zip".to_string(),+ download_url: "https://github.com/mesamirh/MovieBox-Tui/releases/download/v0.1.13/MovieBox_Windows_x64.zip".to_string(),+ size: Some(13_000_000),+ },+ ReleaseAsset {+ name: "MovieBox_Windows_arm64.zip".to_string(),+ download_url: "https://github.com/mesamirh/MovieBox-Tui/releases/download/v0.1.13/MovieBox_Windows_arm64.zip".to_string(),+ size: Some(12_500_000),+ },+ ReleaseAsset {+ name: "SHA256SUMS".to_string(),+ download_url: "https://github.com/mesamirh/MovieBox-Tui/releases/download/v0.1.13/SHA256SUMS".to_string(),+ size: Some(512),+ },+ ],+ }+ }++ #[test]+ fn test_update_asset_selection_for_current_platform() {+ let release = sample_release_with_all_assets();++ let mac_platform = TargetPlatform::detect("macos", "aarch64", false).unwrap();+ let mac_asset = release.find_compatible_asset(mac_platform).unwrap();+ assert_eq!(mac_asset.name, "MovieBox_macOS_Universal.tar.gz");++ let linux_x64 = TargetPlatform::detect("linux", "x86_64", false).unwrap();+ let linux_x64_asset = release.find_compatible_asset(linux_x64).unwrap();+ assert_eq!(linux_x64_asset.name, "MovieBox_Linux_x64.tar.gz");++ let linux_arm64 = TargetPlatform::detect("linux", "aarch64", false).unwrap();+ let linux_arm64_asset = release.find_compatible_asset(linux_arm64).unwrap();+ assert_eq!(linux_arm64_asset.name, "MovieBox_Linux_arm64.tar.gz");++ let win_x64 = TargetPlatform::detect("windows", "x86_64", false).unwrap();+ let win_x64_asset = release.find_compatible_asset(win_x64).unwrap();+ assert_eq!(win_x64_asset.name, "MovieBox_Windows_x64.zip");++ let win_arm64 = TargetPlatform::detect("windows", "arm64", false).unwrap();+ let win_arm64_asset = release.find_compatible_asset(win_arm64).unwrap();+ assert_eq!(win_arm64_asset.name, "MovieBox_Windows_arm64.zip");++ let checksum = release.find_checksum_asset().unwrap();+ assert_eq!(checksum.name, "SHA256SUMS");+ }++ #[test]+ fn test_update_asset_missing_for_current_platform() {+ let partial_release = Release {+ version: "0.1.13".to_string(),+ tag_name: "v0.1.13".to_string(),+ notes: "Partial release".to_string(),+ assets: vec![ReleaseAsset {+ name: "MovieBox_Linux_x64.tar.gz".to_string(),+ download_url: "https://...".to_string(),+ size: Some(1000),+ }],+ };++ let mac = TargetPlatform::detect("macos", "arm64", false).unwrap();+ assert!(partial_release.find_compatible_asset(mac).is_none());++ let win = TargetPlatform::detect("windows", "x86_64", false).unwrap();+ assert!(partial_release.find_compatible_asset(win).is_none());+ }++ #[test]+ fn test_update_asset_rejects_wrong_architecture() {+ assert!(TargetPlatform::detect("linux", "mips", false).is_none());+ assert!(TargetPlatform::detect("linux", "riscv64", false).is_none());+ assert!(TargetPlatform::detect("windows", "ia64", false).is_none());+ }++ #[test]+ fn test_update_asset_rejects_wrong_platform() {+ assert!(TargetPlatform::detect("freebsd", "x86_64", false).is_none());+ assert!(TargetPlatform::detect("openbsd", "x86_64", false).is_none());+ assert!(TargetPlatform::detect("solaris", "x86_64", false).is_none());+ }++ #[test]+ fn test_update_asset_termux_arm64_selection() {+ let release = sample_release_with_all_assets();+ let termux_arm64 = TargetPlatform::detect("linux", "aarch64", true).unwrap();+ assert_eq!(termux_arm64, TargetPlatform::LinuxArm64);++ let asset = release.find_compatible_asset(termux_arm64).unwrap();+ assert_eq!(asset.name, "MovieBox_Linux_arm64.tar.gz");++ assert!(TargetPlatform::detect("linux", "x86_64", true).is_none());+ }++ #[test]+ fn test_update_asset_multiple_candidates_deterministic() {+ let release = sample_release_with_all_assets();+ let platform = TargetPlatform::LinuxX64;+ let a1 = release.find_compatible_asset(platform);+ let a2 = release.find_compatible_asset(platform);+ assert_eq!(a1, a2);+ assert_eq!(a1.unwrap().name, "MovieBox_Linux_x64.tar.gz");+ }}diff --git a/tests/update_lifecycle.rs b/tests/update_lifecycle.rsnew file mode 100644index 0000000..9bada6c--- /dev/null+++ b/tests/update_lifecycle.rs@@ -0,0 +1,194 @@+use moviebox_tui::tui::action::Action;+use moviebox_tui::tui::app::App;+use moviebox_tui::tui::overlay::update_modal_layout;+use moviebox_tui::updater::{Release, ReleaseAsset, TargetPlatform};+use ratatui::layout::Rect;++#[tokio::test]+async fn test_update_check_single_flight() {+ let mut app = App::new();+ assert!(!app.state().is_checking_updates);++ app.handle_action(Action::CheckForUpdates).await;+ assert!(app.state().is_checking_updates);++ app.handle_action(Action::CheckForUpdates).await;+ assert!(app.state().is_checking_updates);++ app.handle_action(Action::UpdateAvailable(Ok(None))).await;+ assert!(!app.state().is_checking_updates);+}++#[tokio::test]+async fn test_update_check_guard_clears_on_error() {+ let mut app = App::new();+ app.handle_action(Action::CheckForUpdates).await;+ assert!(app.state().is_checking_updates);++ app.handle_action(Action::UpdateAvailable(Err(+ "GitHub API rate limited (403)".to_string(),+ )))+ .await;+ assert!(!app.state().is_checking_updates);+}++#[tokio::test]+async fn test_update_check_guard_clears_on_success() {+ let mut app = App::new();+ app.handle_action(Action::CheckForUpdates).await;+ assert!(app.state().is_checking_updates);++ app.handle_action(Action::UpdateAvailable(Ok(Some((+ "0.1.13".to_string(),+ "Release notes content".to_string(),+ )))))+ .await;++ assert!(!app.state().is_checking_updates);+ assert_eq!(+ app.state().update_available,+ Some(("0.1.13".to_string(), "Release notes content".to_string()))+ );+}++#[tokio::test]+async fn test_update_modal_mouse_hitbox_matches_rendered_geometry() {+ let area = Rect::new(0, 0, 80, 24);+ let notes = "• Feature 1\n• Feature 2\n• Feature 3";+ let layout = update_modal_layout(area, notes);++ assert_eq!(layout.popup_area.width, 72);+ assert_eq!(layout.display_count, 3);+ assert!(!layout.has_more);+ assert_eq!(layout.popup_area.height, 11);++ assert_eq!(layout.button_row_y, layout.popup_area.y + 9);+ assert_eq!(layout.open_button_midpoint_x, layout.popup_area.x + 36);+}++#[tokio::test]+async fn test_update_modal_open_release_click() {+ let mut app = App::new();+ app.state_mut().update_available = Some((+ "0.1.13".to_string(),+ "### Notes\n• Major performance improvements".to_string(),+ ));++ let (cols, rows) = crossterm::terminal::size().unwrap_or((80, 24));+ let area = Rect::new(0, 0, cols, rows);+ let layout = update_modal_layout(area, &app.state().update_available.as_ref().unwrap().1);++ let click_x = layout.popup_area.x + 5;+ let click_y = layout.button_row_y;++ app.handle_action(Action::MouseClick(click_x, click_y))+ .await;++ assert!(app.state().update_available.is_none());+}++#[tokio::test]+async fn test_update_modal_dismiss_click() {+ let mut app = App::new();+ app.state_mut().update_available = Some(("0.1.13".to_string(), "• Bug fix".to_string()));++ let (cols, rows) = crossterm::terminal::size().unwrap_or((80, 24));+ let area = Rect::new(0, 0, cols, rows);+ let layout = update_modal_layout(area, &app.state().update_available.as_ref().unwrap().1);++ let click_x = layout.open_button_midpoint_x + 5;+ let click_y = layout.button_row_y;++ app.handle_action(Action::MouseClick(click_x, click_y))+ .await;++ assert!(app.state().update_available.is_none());+}++#[test]+fn test_update_asset_selection_for_current_platform() {+ let release = Release {+ version: "0.1.13".to_string(),+ tag_name: "v0.1.13".to_string(),+ notes: "Notes".to_string(),+ assets: vec![+ ReleaseAsset {+ name: "MovieBox_macOS_Universal.tar.gz".to_string(),+ download_url: "https://.../MovieBox_macOS_Universal.tar.gz".to_string(),+ size: Some(15000),+ },+ ReleaseAsset {+ name: "MovieBox_Linux_x64.tar.gz".to_string(),+ download_url: "https://.../MovieBox_Linux_x64.tar.gz".to_string(),+ size: Some(12000),+ },+ ReleaseAsset {+ name: "MovieBox_Linux_arm64.tar.gz".to_string(),+ download_url: "https://.../MovieBox_Linux_arm64.tar.gz".to_string(),+ size: Some(11000),+ },+ ReleaseAsset {+ name: "MovieBox_Windows_x64.zip".to_string(),+ download_url: "https://.../MovieBox_Windows_x64.zip".to_string(),+ size: Some(13000),+ },+ ReleaseAsset {+ name: "MovieBox_Windows_arm64.zip".to_string(),+ download_url: "https://.../MovieBox_Windows_arm64.zip".to_string(),+ size: Some(12000),+ },+ ReleaseAsset {+ name: "SHA256SUMS".to_string(),+ download_url: "https://.../SHA256SUMS".to_string(),+ size: Some(512),+ },+ ],+ };++ let mac = TargetPlatform::detect("macos", "arm64", false).unwrap();+ assert_eq!(+ release.find_compatible_asset(mac).unwrap().name,+ "MovieBox_macOS_Universal.tar.gz"+ );++ let linux = TargetPlatform::detect("linux", "x86_64", false).unwrap();+ assert_eq!(+ release.find_compatible_asset(linux).unwrap().name,+ "MovieBox_Linux_x64.tar.gz"+ );++ let win = TargetPlatform::detect("windows", "x86_64", false).unwrap();+ assert_eq!(+ release.find_compatible_asset(win).unwrap().name,+ "MovieBox_Windows_x64.zip"+ );+}++#[test]+fn test_update_asset_missing_for_current_platform() {+ let release = Release {+ version: "0.1.13".to_string(),+ tag_name: "v0.1.13".to_string(),+ notes: "Notes".to_string(),+ assets: vec![ReleaseAsset {+ name: "MovieBox_Linux_x64.tar.gz".to_string(),+ download_url: "https://...".to_string(),+ size: Some(1000),+ }],+ };++ let mac = TargetPlatform::detect("macos", "arm64", false).unwrap();+ assert!(release.find_compatible_asset(mac).is_none());+}++#[test]+fn test_update_asset_rejects_wrong_architecture() {+ assert!(TargetPlatform::detect("linux", "ppc64", false).is_none());+ assert!(TargetPlatform::detect("windows", "arm", false).is_none());+}++#[test]+fn test_update_asset_rejects_wrong_platform() {+ assert!(TargetPlatform::detect("solaris", "x86_64", false).is_none());+ assert!(TargetPlatform::detect("netbsd", "x86_64", false).is_none());+}