From 5e0f5cb9cd18fa5932d4c32154116781eeffb7e3 Mon Sep 17 00:00:00 2001 From: Boran Miao <84240213+realRurichan@users.noreply.github.com> Date: Thu, 5 Nov 2026 16:20:27 +0800 Subject: [PATCH] fix: install bundled PPSSPP through the Flatpak helper --- .../overlay/usr/local/bin/droiddeck-emulators | 2 +- tools/tests/test_emulators_install.py | 87 +++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 tools/tests/test_emulators_install.py diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-emulators b/tools/linuxfs/overlay/usr/local/bin/droiddeck-emulators index a937b4e8eb..ec9e8b69d9 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-emulators +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-emulators @@ -11,7 +11,7 @@ install) droiddeck-root /usr/bin/apt-get install -y -q retroarch retroarch-assets $cores || { echo "== FAIL apt-get install"; exit 1; } echo "== STEP PPSSPP" flatpak remote-add --user --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo || { echo "== FAIL flathub"; exit 1; } - flatpak install --user -y --noninteractive flathub org.ppsspp.PPSSPP || { echo "== FAIL org.ppsspp.PPSSPP"; exit 1; } + /usr/bin/python3 /usr/local/bin/droiddeck-flatpak install org.ppsspp.PPSSPP || { echo "== FAIL org.ppsspp.PPSSPP"; exit 1; } printf '#!/bin/sh\nexec /usr/local/bin/droiddeck-flatpak-run org.ppsspp.PPSSPP "$@"\n' > /usr/local/bin/PPSSPPSDL.new && chmod 755 /usr/local/bin/PPSSPPSDL.new && mv -f /usr/local/bin/PPSSPPSDL.new /usr/local/bin/PPSSPPSDL || { echo "== FAIL PPSSPPSDL"; exit 1; } ;; diff --git a/tools/tests/test_emulators_install.py b/tools/tests/test_emulators_install.py new file mode 100644 index 0000000000..03d135bda0 --- /dev/null +++ b/tools/tests/test_emulators_install.py @@ -0,0 +1,87 @@ +import os +from pathlib import Path +import subprocess +import tempfile +import unittest + + +SCRIPT = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-emulators" + + +class EmulatorsInstallTest(unittest.TestCase): + def run_install(self, failure=""): + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + bin_dir = root / "bin" + bin_dir.mkdir() + calls = root / "calls" + launcher = root / "PPSSPPSDL" + helper = root / "droiddeck-flatpak" + helper.write_text( + "import os, sys\n" + "with open(os.environ['CALLS'], 'a') as f:\n" + " f.write('helper ' + ' '.join(sys.argv[1:]) + '\\n')\n" + "sys.exit(1 if os.environ['FAILURE'] == 'helper' else 0)\n" + ) + stubs = { + "droiddeck-root": + 'echo "apt $*" >> "$CALLS"\n' + '[ "$FAILURE" != "apt-$2" ]', + "flatpak": + 'echo "flatpak $*" >> "$CALLS"\n' + 'if [ "$1" = install ]; then\n' + ' echo "Could not connect: No such file or directory" >&2\n' + ' exit 1\n' + 'fi\n' + '[ "$FAILURE" != remote ]', + } + for name, body in stubs.items(): + path = bin_dir / name + path.write_text("#!/bin/sh\n" + body + "\n") + path.chmod(0o755) + script = root / "install" + script.write_text(SCRIPT.read_text() + .replace("/usr/local/bin/droiddeck-flatpak install", str(helper) + " install") + .replace("/usr/local/bin/PPSSPPSDL", str(launcher))) + env = dict(os.environ, PATH=str(bin_dir) + os.pathsep + os.environ["PATH"], + CALLS=str(calls), FAILURE=failure) + result = subprocess.run(["bash", str(script), "install"], env=env, + capture_output=True, text=True, timeout=30) + return result, calls.read_text(), launcher.read_text() if launcher.exists() else None, \ + os.access(launcher, os.X_OK) + + def test_install_without_a_system_bus_uses_the_helper_and_creates_the_launcher(self): + result, calls, launcher, executable = self.run_install() + self.assertEqual(0, result.returncode, result.stdout + result.stderr) + self.assertIn("helper install org.ppsspp.PPSSPP\n", calls) + self.assertNotIn("flatpak install ", calls) + self.assertIn('exec /usr/local/bin/droiddeck-flatpak-run org.ppsspp.PPSSPP "$@"', launcher) + self.assertTrue(executable) + + def test_helper_failure_does_not_publish_a_launcher(self): + result, calls, launcher, _ = self.run_install("helper") + self.assertNotEqual(0, result.returncode) + self.assertIn("helper install org.ppsspp.PPSSPP\n", calls) + self.assertIn("== FAIL org.ppsspp.PPSSPP", result.stdout) + self.assertIsNone(launcher) + + def test_apt_failure_stops_before_flatpak(self): + for stage in ("update", "install"): + with self.subTest(stage=stage): + result, calls, launcher, _ = self.run_install("apt-" + stage) + self.assertNotEqual(0, result.returncode) + self.assertIn("== FAIL apt-get " + stage, result.stdout) + self.assertNotIn("flatpak ", calls) + self.assertNotIn("helper ", calls) + self.assertIsNone(launcher) + + def test_remote_failure_stops_before_the_helper(self): + result, calls, launcher, _ = self.run_install("remote") + self.assertNotEqual(0, result.returncode) + self.assertIn("== FAIL flathub", result.stdout) + self.assertNotIn("helper ", calls) + self.assertIsNone(launcher) + + +if __name__ == "__main__": + unittest.main()