fix(content): refine installed update workflow

This commit is contained in:
objz committed 2026-08-05 11:36:41 +02:00
1 parent ed7387beb3
commit bfd8be6abe
19 files changed
+815 -216

No files matched your search

@@ -407,6 +407,7 @@ fn installed_version_popup_tracks_current_version_and_reinstalls_it() {
world_details: None,
title_suffix: None,
footer_label: None,
footer_change: None,
description: String::new(),
enabled: true,
icon_bytes: None,
+68 -7
View File
@@ -16,8 +16,8 @@ use ratatui::{
use super::{
ContentListState, WatcherEventHandling, available_description_width, description_text_width,
diff_directory, diff_event_paths, ellipsize, load_provider_metadata, read_dir_stems,
right_aligned_footer_spans, square_icon_columns, title_suffix_spans, watcher_event_handling,
world_descriptions, world_game_mode_color,
right_aligned_footer_spans, square_icon_columns, title_suffix_spans, version_change_spans,
watcher_event_handling, world_descriptions, world_game_mode_color,
};
fn entry(name: &str) -> ContentEntry {
@@ -30,6 +30,7 @@ fn entry(name: &str) -> ContentEntry {
world_details: None,
title_suffix: None,
footer_label: None,
footer_change: None,
description: String::new(),
enabled: true,
icon_bytes: None,
@@ -149,6 +150,60 @@ fn pure_toggle_does_not_request_reconciliation() {
);
}
#[test]
fn content_watcher_replaces_a_version_without_removing_its_row() {
let mut state = ContentListState::default();
let mut installed = entry("Example Mod");
installed.file_stem = "example-1.0".to_owned();
installed.path = PathBuf::from("mods/example-1.0.jar");
installed.description = "Cached description".to_owned();
installed.provider_description = true;
installed.icon_bytes = Some(vec![1, 2, 3]);
state.entries.push(installed);
*state.watcher_diff.lock().unwrap() = Some(super::WatcherDiff {
toggled: Vec::new(),
removed: vec!["example-1.0".to_owned()],
added: Vec::new(),
});
state.drain_watcher();
assert_eq!(state.entries.len(), 1);
let mut replacement = entry("Example Mod");
replacement.file_stem = "example-2.0".to_owned();
replacement.path = PathBuf::from("mods/example-2.0.jar");
*state.watcher_diff.lock().unwrap() = Some(super::WatcherDiff {
toggled: Vec::new(),
removed: Vec::new(),
added: vec![replacement],
});
state.drain_watcher();
assert_eq!(state.entries.len(), 1);
assert_eq!(state.entries[0].path, PathBuf::from("mods/example-2.0.jar"));
assert_eq!(state.entries[0].description, "Cached description");
assert_eq!(state.entries[0].icon_bytes, Some(vec![1, 2, 3]));
}
#[test]
fn content_watcher_removes_a_file_after_the_replacement_grace_period() {
let mut state = ContentListState::default();
let mut installed = entry("Removed Mod");
installed.file_stem = "removed".to_owned();
installed.path = PathBuf::from("mods/removed.jar");
state.entries.push(installed);
state.pending_removals.insert(
"removed".to_owned(),
std::time::Instant::now() - super::REMOVAL_GRACE,
);
let update = state.drain_watcher();
assert!(state.entries.is_empty());
assert!(update.requires_reconcile);
}
#[test]
fn irrelevant_watcher_paths_do_not_emit_an_empty_diff() {
let temp = tempfile::tempdir().unwrap();
@@ -250,9 +305,9 @@ fn description_width_reserves_the_row_chrome() {
#[test]
fn description_width_reserves_the_download_metadata() {
assert_eq!(description_text_width(40, Some("1.2K downloads"), true), 25);
assert_eq!(description_text_width(10, Some("1.2K downloads"), true), 0);
assert_eq!(description_text_width(40, None, true), 40);
assert_eq!(description_text_width(40, 14, true), 25);
assert_eq!(description_text_width(10, 14, true), 0);
assert_eq!(description_text_width(40, 0, true), 40);
}
#[test]
@@ -262,8 +317,7 @@ fn footer_metadata_is_right_aligned_without_a_separator() {
30,
"Description",
true,
"1.2K downloads",
Style::default(),
vec![Span::raw("1.2K downloads")],
));
let line = Line::from(spans);
@@ -271,6 +325,13 @@ fn footer_metadata_is_right_aligned_without_a_separator() {
assert_eq!(line.to_string(), "Description 1.2K downloads");
}
#[test]
fn version_changes_render_as_two_labels_with_a_directional_arrow() {
let spans = version_change_spans("1.0", "2.0");
assert_eq!(Line::from(spans).to_string(), " 1.0 ➜ 2.0 ");
}
#[test]
fn content_stream_inserts_entries_and_icons_incrementally() {
let mut state = ContentListState::default();
@@ -0,0 +1,28 @@
---
source: src/tui/tests/widgets/content/update.rs
expression: terminal.backend()
---
" "
" "
" "
" "
" "
" "
" "
" "
" "
" "
" ╭Update installed content──────────────────────────────────╮ "
" │▌▄▄▄▄▄▄ Example Mod Update │ "
" │▌▄▄▄▄▄▄ 1.0 ➜ 2.0 │ "
" │▌▄▄▄▄▄▄ │ "
" ╰───────────[j/k] navigate [Enter] update all [Esc] close╯ "
" "
" "
" "
" "
" "
" "
" "
" "
" "
+115
View File
@@ -0,0 +1,115 @@
use std::path::PathBuf;
use ratatui::{Terminal, backend::TestBackend};
use super::*;
fn entry(name: &str, path: &str) -> ContentEntry {
ContentEntry {
file_stem: name.to_lowercase(),
name: name.to_owned(),
source_slug: None,
installed_path: Some(PathBuf::from(path)),
provider_project: None,
world_details: None,
title_suffix: None,
footer_label: None,
footer_change: None,
description: "Existing project description".to_owned(),
enabled: true,
icon_bytes: None,
provider_icon: false,
provider_description: false,
path: PathBuf::from(path),
icon_lines: Some(crate::instance::content::fallback_icon()),
}
}
fn version(number: &str) -> crate::net::modrinth::VersionInfo {
crate::net::modrinth::VersionInfo {
id: number.to_owned(),
project_id: "project".to_owned(),
name: number.to_owned(),
version_number: number.to_owned(),
game_versions: Vec::new(),
loaders: Vec::new(),
version_type: crate::net::modrinth::VersionType::Release,
dependencies: Vec::new(),
date_published: String::new(),
files: Vec::new(),
}
}
fn plan() -> BulkUpdatePlan {
BulkUpdatePlan {
dependency_plan: crate::instance::content::dependencies::DependencyPlan {
items: Vec::new(),
root_count: 0,
optional_dependencies: 0,
},
roots: vec![crate::instance::content::updates::PlannedRootUpdate {
title: "Example Mod".to_owned(),
installed_path: PathBuf::from("mods/example.jar"),
current_version: "1.0".to_owned(),
target: version("2.0"),
}],
conflicts: Vec::new(),
}
}
fn snapshot() -> UpdateSnapshot {
UpdateSnapshot {
game_version: "1.21.1".to_owned(),
loader: crate::instance::ModLoader::Fabric,
inventory: Vec::new(),
updates: Vec::new(),
failures: Vec::new(),
}
}
#[test]
fn update_review_reuses_content_rows() {
let mut state = State::checking(
ContentKind::Mod,
None,
vec![entry("Example Mod", "mods/example.jar")],
);
state.push(PendingResult::Prepared(snapshot(), plan()));
state.drain();
let picker = ratatui_image::picker::Picker::halfblocks();
let mut terminal = Terminal::new(TestBackend::new(100, 24)).unwrap();
terminal
.draw(|frame| render(frame, &mut state, &picker))
.unwrap();
insta::assert_snapshot!(terminal.backend());
}
#[test]
fn update_conflicts_explain_why_the_item_was_not_updated() {
let mut plan = plan();
plan.conflicts
.push(crate::instance::content::updates::UpdateConflict {
title: "Example Mod".to_owned(),
installed_path: PathBuf::from("mods/example.jar"),
reason: "Parse error: Conflicting selected versions for 'Library': '1.0' and '2.0'"
.to_owned(),
});
let mut state = State::checking(
ContentKind::Mod,
None,
vec![entry("Example Mod", "mods/example.jar")],
);
state.push(PendingResult::Prepared(snapshot(), plan));
state.drain();
assert_eq!(
state.list.entries[0].title_suffix.as_deref(),
Some("Skipped")
);
assert_eq!(
state.list.entries[0].description,
"Other updates need different Library versions (1.0 and 2.0). This mod was left unchanged; update it separately with v."
);
}