From 11d2888cb8e2789c2aecaf219920133e3f0b1171 Mon Sep 17 00:00:00 2001 From: "BOLTMAN-WINDOWS\\bryan" Date: Wed, 11 Dec 2024 00:15:21 -0500 Subject: [PATCH 1/6] fix: make tests pass on Windows --- library/src/android.rs | 39 +++++++++++++++++++----------- library/src/cache/patch_manager.rs | 7 ++---- library/src/config.rs | 9 +++++-- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/library/src/android.rs b/library/src/android.rs index adc8c16..cdce784 100644 --- a/library/src/android.rs +++ b/library/src/android.rs @@ -210,18 +210,29 @@ pub fn libapp_path_from_settings(original_libapp_paths: &[String]) -> Result) { + fn create_zip_with_empty_files(zip_path: &Path, files: Vec) { let file = File::create(zip_path).unwrap(); let mut zip = ZipWriter::new(file); for file in files { - zip.start_file(file, FileOptions::default()).unwrap(); + zip.start_file(file.to_string_lossy(), FileOptions::default()) + .unwrap(); } zip.finish().unwrap(); } @@ -230,7 +241,7 @@ mod tests { fn find_and_open_lib_test() { let tmp_dir = TempDir::new("example").unwrap(); let error = super::find_and_open_lib(tmp_dir.path(), "libapp.so").unwrap_err(); - assert!(error.to_string().contains("No such file or directory")); + assert_error_is_file_not_found(&error); // Write an empty file (invalid apk) to the base apk. let base_apk_path = tmp_dir.path().join("base.apk"); @@ -253,12 +264,12 @@ mod tests { let base_apk_path = tmp_dir.path().join("base.apk"); let arch = super::android_arch_names(); - let lib_path = format!("lib/{}/libapp.so", arch.lib_dir); - create_zip_with_empty_files(&base_apk_path, vec![&lib_path]); + let lib_path = Path::new("lib").join(arch.lib_dir).join("libapp.so"); + create_zip_with_empty_files(&base_apk_path, vec![lib_path.clone()]); let zip_location = super::find_and_open_lib(tmp_dir.path(), "libapp.so").unwrap(); // Success! - assert_eq!(zip_location.internal_path, lib_path); + assert_eq!(Path::new(&zip_location.internal_path), &lib_path); // Otherwise coverage complains that we haven't used the Debug trait // even though the Debug trait is required for assert_eq!. let debug_str = format!("{:?}", zip_location); @@ -273,28 +284,28 @@ mod tests { // Write a base.apk with the wrong arch. let base_apk_path = tmp_dir.path().join("base.apk"); - create_zip_with_empty_files(&base_apk_path, vec!["lib/wrong/libapp.so"]); + create_zip_with_empty_files(&base_apk_path, vec![PathBuf::from("lib/wrong/libapp.so")]); // Write a split apk with the right arch. let arch = super::android_arch_names(); let split_apk_name = format!("app-hdpi{}-release.apk", arch.apk_split); let split_apk_path: std::path::PathBuf = tmp_dir.path().join(split_apk_name); - let lib_path = format!("lib/{}/libapp.so", arch.lib_dir); - create_zip_with_empty_files(&split_apk_path, vec![&lib_path]); + let lib_path = Path::new("lib").join(arch.lib_dir).join("libapp.so"); + create_zip_with_empty_files(&split_apk_path, vec![lib_path.clone()]); // Write another apk early in the alphabet we skip over since it isn't // a split apk. let split_apk_path: std::path::PathBuf = tmp_dir.path().join("aaa.apk"); - create_zip_with_empty_files(&split_apk_path, vec![&lib_path]); + create_zip_with_empty_files(&split_apk_path, vec![lib_path.clone()]); // Write an apk with our arch name but not our library. let split_apk_name = format!("aaa{}.apk", arch.apk_split); - let split_apk_path: std::path::PathBuf = tmp_dir.path().join(split_apk_name); + let split_apk_path = tmp_dir.path().join(split_apk_name); create_zip_with_empty_files(&split_apk_path, vec![]); let zip_location = super::find_and_open_lib(tmp_dir.path(), "libapp.so").unwrap(); // Success! - assert_eq!(zip_location.internal_path, lib_path); + assert_eq!(Path::new(&zip_location.internal_path), lib_path); } #[test] @@ -311,6 +322,6 @@ mod tests { fn open_base_lib_test() { let tmp_dir = TempDir::new("example").unwrap(); let error = super::open_base_lib(tmp_dir.path(), "libapp.so").unwrap_err(); - assert!(error.to_string().contains("No such file or directory")); + assert_error_is_file_not_found(&error); } } diff --git a/library/src/cache/patch_manager.rs b/library/src/cache/patch_manager.rs index 2c71309..275e394 100644 --- a/library/src/cache/patch_manager.rs +++ b/library/src/cache/patch_manager.rs @@ -530,11 +530,8 @@ mod debug_tests { fn patch_manager_is_debug() { let temp_dir = TempDir::new("patch_manager").unwrap(); let patch_manager = PatchManager::new(temp_dir.path().to_owned(), Some("public_key")); - let expected_str = format!( - "PatchManager {{ root_dir: \"{}\", patches_state: PatchesState {{ last_booted_patch: None, next_boot_patch: None, currently_booting_patch: None, known_bad_patches: {{}} }}, patch_public_key: Some(\"public_key\") }}", - temp_dir.path().display() - ); - assert_eq!(format!("{:?}", patch_manager), expected_str); + let actual = format!("{:?}", patch_manager); + assert!(actual.contains(r#"patches_state: PatchesState { last_booted_patch: None, next_boot_patch: None, currently_booting_patch: None, known_bad_patches: {} }, patch_public_key: Some("public_key") }"#)); } } diff --git a/library/src/config.rs b/library/src/config.rs index d60b2a8..684eb7f 100644 --- a/library/src/config.rs +++ b/library/src/config.rs @@ -164,6 +164,8 @@ pub fn current_platform() -> &'static str { #[cfg(test)] mod tests { + use std::path::PathBuf; + use super::set_config; use crate::{network::NetworkHooks, testing_reset_config, AppConfig, ExternalFileProvider}; use anyhow::Result; @@ -222,8 +224,11 @@ mod tests { )?; let config = super::with_config(|config| Ok(config.clone())).unwrap(); - assert_eq!(config.storage_dir.to_str(), Some("/app_storage")); - assert_eq!(config.download_dir.to_str(), Some("/code_cache/downloads")); + assert_eq!(config.storage_dir, PathBuf::from("/app_storage")); + assert_eq!( + config.download_dir, + PathBuf::from("/").join("code_cache").join("downloads") + ); assert!(config.auto_update); assert_eq!(config.channel, "fake_channel"); assert_eq!(config.app_id, "fake_app_id"); From 9927b3acb4ceebe3191474f50d4cd1fd061a67ea Mon Sep 17 00:00:00 2001 From: "BOLTMAN-WINDOWS\\bryan" Date: Wed, 11 Dec 2024 00:18:18 -0500 Subject: [PATCH 2/6] Run ci on all supported building OSes --- .github/workflows/main.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 77f4476..21cd0a6 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -84,9 +84,10 @@ jobs: strategy: matrix: + os: [macos-latest, windows-latest, ubuntu-latest] package: ${{ fromJSON(needs.changes.outputs.needs_flutter_build) }} - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} name: 🎯 Build ${{ matrix.package }} From 246305b70cc4e6141451972e14d0b0aef50170c4 Mon Sep 17 00:00:00 2001 From: "BOLTMAN-WINDOWS\\bryan" Date: Wed, 11 Dec 2024 00:19:42 -0500 Subject: [PATCH 3/6] Add os name to CI step --- .github/workflows/main.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 21cd0a6..da66bed 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -89,7 +89,7 @@ jobs: runs-on: ${{ matrix.os }} - name: 🎯 Build ${{ matrix.package }} + name: 🎯 Build ${{ matrix.package }} (${{ matrix.os }}) steps: - name: 📚 Git Checkout From 1643745ed2f695a66ee80e7571854228494beb13 Mon Sep 17 00:00:00 2001 From: "BOLTMAN-WINDOWS\\bryan" Date: Wed, 11 Dec 2024 00:21:36 -0500 Subject: [PATCH 4/6] Build rust crates on all oses --- .github/workflows/main.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index da66bed..78cccfc 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -63,8 +63,9 @@ jobs: strategy: matrix: crate: ${{ fromJSON(needs.changes.outputs.needs_rust_build) }} + os: [macos-latest, windows-latest, ubuntu-latest] - runs-on: macos-latest + runs-on: ${{ matrix.os }} name: 🦀 Build ${{ matrix.crate }} From dbc5a899f9a43c6c3cb253ef10f98d9fea2b5186 Mon Sep 17 00:00:00 2001 From: "BOLTMAN-WINDOWS\\bryan" Date: Wed, 11 Dec 2024 00:22:03 -0500 Subject: [PATCH 5/6] tweak --- .github/workflows/main.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 78cccfc..3b165f1 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -67,7 +67,7 @@ jobs: runs-on: ${{ matrix.os }} - name: 🦀 Build ${{ matrix.crate }} + name: 🦀 Build ${{ matrix.crate }} ${{ matrix.os }} steps: - name: 📚 Git Checkout From be4c7e86f5d251144a94a0486b9e073b38e21576 Mon Sep 17 00:00:00 2001 From: "BOLTMAN-WINDOWS\\bryan" Date: Wed, 11 Dec 2024 00:24:53 -0500 Subject: [PATCH 6/6] Only run rust on multiple oses for now --- .github/workflows/main.yaml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 3b165f1..dfb749e 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -67,7 +67,7 @@ jobs: runs-on: ${{ matrix.os }} - name: 🦀 Build ${{ matrix.crate }} ${{ matrix.os }} + name: 🦀 Build ${{ matrix.crate }} (${{ matrix.os }}) steps: - name: 📚 Git Checkout @@ -85,12 +85,11 @@ jobs: strategy: matrix: - os: [macos-latest, windows-latest, ubuntu-latest] package: ${{ fromJSON(needs.changes.outputs.needs_flutter_build) }} - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest - name: 🎯 Build ${{ matrix.package }} (${{ matrix.os }}) + name: 🎯 Build ${{ matrix.package }} steps: - name: 📚 Git Checkout