fix(content): preserve instance data and isolate provider caches
This commit is contained in:
1 parent
978fd3e971
commit
9d480f8bfb
11 files changed
+209
-155
No files matched your search
@@ -90,6 +90,15 @@ fn unique_name_with_collision() {
|
||||
assert_eq!(name, "TestPack (2)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unique_name_preserves_directory_without_config() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
std::fs::create_dir(tmp.path().join("TestPack")).unwrap();
|
||||
|
||||
assert_eq!(unique_instance_name("TestPack", tmp.path()), "TestPack (2)");
|
||||
assert!(tmp.path().join("TestPack").exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unique_name_multiple_collisions() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
@@ -173,3 +182,34 @@ fn failed_import_cleanup_removes_the_partial_instance() {
|
||||
|
||||
assert!(!instance_dir.exists());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn failed_import_creation_clears_progress_without_removing_existing_files() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let manager = InstanceManager::new(tmp.path().join("instances"), tmp.path().join("meta"));
|
||||
let summary = ImportSummary {
|
||||
name: "../invalid".to_owned(),
|
||||
pack_version: String::new(),
|
||||
game_version: "1.20.1".to_owned(),
|
||||
loader: ModLoader::Vanilla,
|
||||
loader_version: None,
|
||||
mod_count: 0,
|
||||
override_count: 0,
|
||||
format: PackFormat::Mmc,
|
||||
archive_path: tmp.path().join("missing.zip"),
|
||||
source: None,
|
||||
};
|
||||
let preserved = tmp.path().join("invalid");
|
||||
std::fs::write(&preserved, b"keep").unwrap();
|
||||
|
||||
assert!(execute_import(&summary, &manager).await.is_err());
|
||||
assert_eq!(std::fs::read(preserved).unwrap(), b"keep");
|
||||
assert!(
|
||||
!crate::feedback::progress::PROGRESS
|
||||
.lock()
|
||||
.unwrap()
|
||||
.current_action
|
||||
.as_deref()
|
||||
.is_some_and(|action| action.contains("../invalid"))
|
||||
);
|
||||
}
|
||||
@@ -62,6 +62,21 @@ fn delete_missing_instance_returns_not_found() {
|
||||
assert!(matches!(result, Err(InstanceError::NotFound(_))));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn create_preserves_directory_without_instance_config() {
|
||||
let (manager, tmp) = test_manager();
|
||||
let dir = tmp.path().join("existing");
|
||||
std::fs::create_dir(&dir).unwrap();
|
||||
std::fs::write(dir.join("world.zip"), b"keep").unwrap();
|
||||
|
||||
let result = manager
|
||||
.create("existing", "1.20.1", ModLoader::Vanilla, None)
|
||||
.await;
|
||||
|
||||
assert!(matches!(result, Err(InstanceError::AlreadyExists(_))));
|
||||
assert_eq!(std::fs::read(dir.join("world.zip")).unwrap(), b"keep");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn delete_rejects_path_traversal() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
|
||||
Reference in new issue
Block a user