From 684929fe850b744ef841475f88cf2a3189fbb986 Mon Sep 17 00:00:00 2001 From: xXJSONDeruloXx Date: Thu, 10 Sep 2026 14:32:00 -0400 Subject: refactor: make Flatpak support plugin-level --- tests/test_steam_service.py | 120 ++++++++++++++++++-------------------------- 1 file changed, 49 insertions(+), 71 deletions(-) (limited to 'tests/test_steam_service.py') diff --git a/tests/test_steam_service.py b/tests/test_steam_service.py index 636c87f..95bd2a2 100644 --- a/tests/test_steam_service.py +++ b/tests/test_steam_service.py @@ -1,3 +1,4 @@ +import tempfile import sys import types import unittest @@ -15,102 +16,79 @@ from lsfg_vk.steam_service import SteamService, classify_shortcut_transport class SteamTransportTests(unittest.TestCase): - def test_only_direct_canonical_flatpak_forms_are_classified(self): + def test_only_a_direct_usr_bin_flatpak_target_is_special(self): self.assertEqual( - classify_shortcut_transport( - "/usr/bin/flatpak", - "run com.example.PCSX2 --fullscreen", - ), - {"kind": "flatpak", "flatpakAppId": "com.example.PCSX2"}, - ) - self.assertEqual( - classify_shortcut_transport( - "flatpak", - "run com.example.PCSX2 --fullscreen", - ), - {"kind": "flatpak", "flatpakAppId": "com.example.PCSX2"}, - ) - self.assertEqual( - classify_shortcut_transport( - "/usr/bin/flatpak run com.example.PCSX2", - "--fullscreen", - ), - {"kind": "flatpak", "flatpakAppId": "com.example.PCSX2"}, - ) - self.assertEqual( - classify_shortcut_transport( - "/usr/bin/bash", - "~/launch-game.sh --fullscreen", - ), - {"kind": "host"}, - ) - self.assertEqual( - classify_shortcut_transport( - "/usr/bin/flatpak", - "--user run com.example.PCSX2", - ), - {"kind": "host"}, - ) - self.assertEqual( - classify_shortcut_transport( - "/usr/bin/flatpak", - "run bash ~/launch-game.sh", - ), - {"kind": "host"}, - ) - self.assertEqual( - classify_shortcut_transport( - "~/.lsfg", - "run --branch=stable --arch=x86_64 com.example.PCSX2", - ), - {"kind": "flatpak", "flatpakAppId": "com.example.PCSX2"}, + classify_shortcut_transport("/usr/bin/flatpak", "run com.example.Game --fullscreen"), + {"kind": "flatpak"}, ) + for executable, options in ( + ("flatpak", "run com.example.Game"), + ("/usr/bin/flatpak run com.example.Game", "--fullscreen"), + ("~/.lsfg", "run com.example.Game"), + ("/usr/bin/bash", "~/launch-game.sh --fullscreen"), + ): + with self.subTest(executable=executable, options=options): + self.assertEqual(classify_shortcut_transport(executable, options), {"kind": "host"}) + self.assertEqual( - classify_shortcut_transport( - "/home/deck/.lsfg", - "run com.example.PCSX2", - ), - {"kind": "flatpak", "flatpakAppId": "com.example.PCSX2"}, + classify_shortcut_transport("/usr/bin/flatpak", "--user run com.example.Game"), + {"kind": "flatpak"}, ) self.assertEqual( - classify_shortcut_transport("~/.lsfg", "--profile high"), - {"kind": "host"}, + classify_shortcut_transport('"~/.lsfg" "/usr/bin/flatpak"', "run com.example.Game"), + {"kind": "flatpak"}, ) + self.assertEqual(classify_shortcut_transport("~/.lsfg", "run com.example.Game"), {"kind": "host"}) - def test_shortcut_data_preserves_transport_inputs(self): + def test_direct_flatpak_shortcut_keeps_arguments_without_an_app_id(self): game = SteamService._shortcut_game( { "appid": 123456, - "AppName": "PCSX2 shortcut", + "AppName": "Flatpak shortcut", "Exe": "/usr/bin/flatpak", "LaunchOptions": "run net.pcsx2.PCSX2 --fullscreen", "StartDir": "/home/deck/Games", } ) - self.assertEqual(game["appid"], "123456") - self.assertEqual(game["transport"], { - "kind": "flatpak", - "flatpakAppId": "net.pcsx2.PCSX2", - }) + self.assertEqual(game["transport"], {"kind": "flatpak"}) self.assertEqual(game["executable"], "/usr/bin/flatpak") self.assertEqual(game["arguments"], "run net.pcsx2.PCSX2 --fullscreen") self.assertEqual(game["startDir"], "/home/deck/Games") - def test_wrapped_flatpak_shortcut_remains_a_flatpak_target(self): + def test_shell_targets_are_opaque_host_targets(self): game = SteamService._shortcut_game( { - "appid": 987654, - "AppName": "Wrapped Flatpak", - "Exe": "~/.lsfg", - "LaunchOptions": "run --branch=stable --arch=x86_64 com.example.Game", + "appid": 654321, + "AppName": "EmuDeck-style launcher", + "Exe": "/usr/bin/bash", + "LaunchOptions": "~/Emulators/launch-game.sh --game-id foo", } ) - self.assertEqual(game["transport"], { - "kind": "flatpak", - "flatpakAppId": "com.example.Game", - }) + self.assertEqual(game["transport"], {"kind": "host"}) + + def test_normal_steam_manifest_always_uses_host_transport(self): + with tempfile.TemporaryDirectory() as directory: + home = Path(directory) + steamapps = home / ".local/share/Steam/steamapps" + steamapps.mkdir(parents=True) + (steamapps / "appmanifest_123.acf").write_text( + '"AppState" {\n\t"name" "Steam game"\n}\n', + encoding="utf-8", + ) + service = SteamService() + service.user_home = home + + response = service.get_installed_games() + + self.assertTrue(response["success"]) + self.assertEqual(response["games"], [{ + "appid": "123", + "name": "Steam game", + "nonSteam": False, + "transport": {"kind": "host"}, + }]) if __name__ == "__main__": -- cgit v1.2.3