summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorxXJSONDeruloXx <danielhimebauch@gmail.com>2026-09-11 11:08:12 -0400
committerxXJSONDeruloXx <danielhimebauch@gmail.com>2026-09-11 11:08:12 -0400
commit954b2abc47d8772211cb8ecee523900f823184e8 (patch)
treec25109bebc87ccfb9e71a0863a10e81caa695908 /tests
parentbc73d150230f92d614962f7384a7430cf64dcd14 (diff)
downloaddecky-lsfg-vk-954b2abc47d8772211cb8ecee523900f823184e8.tar.gz
decky-lsfg-vk-954b2abc47d8772211cb8ecee523900f823184e8.zip
better uninstall cleanup
Diffstat (limited to 'tests')
-rw-r--r--tests/test_configuration_profiles.py19
-rw-r--r--tests/test_installation_cleanup.py63
-rw-r--r--tests/test_plugin_migration.py8
-rw-r--r--tests/test_wrapper_service.py29
4 files changed, 118 insertions, 1 deletions
diff --git a/tests/test_configuration_profiles.py b/tests/test_configuration_profiles.py
index 789842e..64db0f1 100644
--- a/tests/test_configuration_profiles.py
+++ b/tests/test_configuration_profiles.py
@@ -75,6 +75,25 @@ preserve_swapchain_image_count = false
self.assertIn("Steam Game", data["profiles"])
self.assertNotIn("flatpak:org.example.Game", data["profiles"])
+ def test_global_config_update_does_not_change_profile_values(self):
+ self.service.update_game_config("123", "Steam Game", {"multiplier": 2})
+
+ result = self.service.update_global_config({"no_fp16": True})
+ data = self.service._get_profile_data()
+
+ self.assertTrue(result["success"])
+ self.assertTrue(result["global_config"]["no_fp16"])
+ self.assertTrue(data["global_config"]["no_fp16"])
+ self.assertEqual(data["profiles"]["Steam Game"]["multiplier"], 2)
+
+ def test_profile_update_cannot_overwrite_global_fp16_setting(self):
+ self.service.update_global_config({"no_fp16": True})
+
+ self.service.update_game_config("123", "Steam Game", {"multiplier": 3, "no_fp16": False})
+
+ data = self.service._get_profile_data()
+ self.assertTrue(data["global_config"]["no_fp16"])
+
if __name__ == "__main__":
unittest.main()
diff --git a/tests/test_installation_cleanup.py b/tests/test_installation_cleanup.py
new file mode 100644
index 0000000..3336505
--- /dev/null
+++ b/tests/test_installation_cleanup.py
@@ -0,0 +1,63 @@
+import sys
+import tempfile
+import types
+import unittest
+from pathlib import Path
+from unittest.mock import Mock
+
+
+sys.modules.setdefault(
+ "decky",
+ types.SimpleNamespace(DECKY_USER_HOME="/home/deck", logger=Mock()),
+)
+sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "py_modules"))
+
+from lsfg_vk.base_service import BaseService
+from lsfg_vk.installation import InstallationService
+
+
+class InstallationCleanupTests(unittest.TestCase):
+ def test_uninstall_removes_legacy_files_and_prunes_only_empty_directories(self):
+ with tempfile.TemporaryDirectory() as temporary:
+ home = Path(temporary) / "home" / "deck"
+ service = InstallationService.__new__(InstallationService)
+ BaseService.__init__(service)
+ service.log = Mock()
+ service.user_home = home
+ service.local_bin_dir = home / ".local/bin"
+ service.local_lib_dir = home / ".local/lib"
+ service.local_share_dir = home / ".local/share/vulkan/implicit_layer.d"
+ service.config_dir = home / ".config/lsfg-vk"
+ service.config_file_path = service.config_dir / "conf.toml"
+ service.legacy_script_path = home / "lsfg"
+ service.lib_file = service.local_lib_dir / "liblsfg-vk-layer.so"
+ service.lib_x86_file = service.local_lib_dir / "liblsfg-vk-layer.x86.so"
+ service.json_file = service.local_share_dir / "VkLayer_LSFGVK_frame_generation.json"
+ service.json_x86_file = service.local_share_dir / "VkLayer_LSFGVK_frame_generation.x86.json"
+ service.cli_file = service.local_bin_dir / "lsfg-vk-cli"
+ service.legacy_lib_file = service.local_lib_dir / "liblsfg-vk.so"
+ service.legacy_json_file = service.local_share_dir / "VkLayer_LS_frame_generation.json"
+
+ for path in (
+ service.lib_file,
+ service.config_file_path,
+ service.legacy_script_path,
+ ):
+ path.parent.mkdir(parents=True, exist_ok=True)
+ path.write_text("owned", encoding="utf-8")
+ unrelated = home / ".local/bin/keep-me"
+ unrelated.parent.mkdir(parents=True, exist_ok=True)
+ unrelated.write_text("user file", encoding="utf-8")
+
+ result = service.uninstall()
+
+ self.assertTrue(result["success"])
+ self.assertFalse(service.lib_file.exists())
+ self.assertFalse(service.config_file_path.exists())
+ self.assertFalse(service.legacy_script_path.exists())
+ self.assertTrue(unrelated.exists())
+ self.assertTrue(service.local_bin_dir.exists())
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tests/test_plugin_migration.py b/tests/test_plugin_migration.py
index 7ab4621..1a7cb29 100644
--- a/tests/test_plugin_migration.py
+++ b/tests/test_plugin_migration.py
@@ -63,12 +63,16 @@ class PluginMigrationTests(unittest.TestCase):
plugin.installation_service = Mock()
plugin.flatpak_service = Mock()
plugin.configuration_service = Mock()
+ plugin.wrapper_service = Mock()
plugin.flatpak_service.remove_plugin_owned_environment.return_value = {"success": True}
+ plugin.configuration_service.reset_all_flatpak_configs.return_value = {"success": True}
+ plugin.wrapper_service.purge.return_value = {"success": True}
asyncio.run(plugin._uninstall())
plugin.flatpak_service.remove_plugin_owned_environment.assert_called_once_with()
plugin.configuration_service.reset_all_flatpak_configs.assert_called_once_with()
+ plugin.wrapper_service.purge.assert_called_once_with()
plugin.installation_service.cleanup_on_uninstall.assert_called_once_with()
finally:
self._restore(previous_decky, previous_tomllib, previous_plugin)
@@ -80,12 +84,14 @@ class PluginMigrationTests(unittest.TestCase):
plugin.installation_service = Mock()
plugin.flatpak_service = Mock()
plugin.configuration_service = Mock()
+ plugin.wrapper_service = Mock()
plugin.flatpak_service.remove_plugin_owned_environment.return_value = {"success": False, "error": "changed"}
asyncio.run(plugin._uninstall())
plugin.configuration_service.reset_all_flatpak_configs.assert_not_called()
- plugin.installation_service.cleanup_on_uninstall.assert_called_once_with()
+ plugin.wrapper_service.purge.assert_not_called()
+ plugin.installation_service.cleanup_on_uninstall.assert_not_called()
finally:
self._restore(previous_decky, previous_tomllib, previous_plugin)
diff --git a/tests/test_wrapper_service.py b/tests/test_wrapper_service.py
index 5c291c7..20a08ff 100644
--- a/tests/test_wrapper_service.py
+++ b/tests/test_wrapper_service.py
@@ -158,6 +158,35 @@ class WrapperServiceTests(unittest.TestCase):
)
self.assertEqual(result.stdout, "ok")
+ def test_purge_removes_owned_wrapper_and_state(self):
+ self.service.set("123", self._state(), non_steam=True)
+ self.assertTrue(self.service.get("123")["non_steam"])
+ self.assertEqual(self.service.list_apps()["apps"][0]["non_steam"], True)
+ response = self.service.purge()
+ self.assertTrue(response["success"])
+ self.assertEqual(response["removed_files"], [str(self.service.wrapper_path), str(self.service.sidecar_path)])
+ self.assertFalse(self.service.wrapper_path.exists())
+ self.assertFalse(self.service.sidecar_path.exists())
+
+ def test_purge_refuses_foreign_wrapper(self):
+ self.service.wrapper_path.write_text("#!/bin/sh\necho foreign\n", encoding="utf-8")
+ response = self.service.purge()
+ self.assertFalse(response["success"])
+ self.assertIn("unowned", response["error"])
+ self.assertTrue(self.service.wrapper_path.exists())
+
+ def test_purge_refuses_invalid_state(self):
+ self.service.config_dir.mkdir(parents=True, exist_ok=True)
+ self.service.sidecar_path.write_text("not json", encoding="utf-8")
+ self.service.wrapper_path.write_text(
+ f"#!/bin/sh\n{self.service.MARKER}\nexec \"$@\"\n",
+ encoding="utf-8",
+ )
+ response = self.service.purge()
+ self.assertFalse(response["success"])
+ self.assertTrue(self.service.wrapper_path.exists())
+ self.assertTrue(self.service.sidecar_path.exists())
+
if __name__ == "__main__":
unittest.main()