From b26196c5be3d660caaffb4afe482477cc5ef3fd1 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 29 Sep 2026 08:47:44 +0000 Subject: [PATCH 1/2] 3.0.1: keep the user manager bus when the updater relaunches itself The systemd-run --user launcher runs with a deliberately stripped environment, which also stripped the locator the client needs to reach the per-user service manager. On a host where that launcher runs without an inherited XDG_RUNTIME_DIR, the updater job is rejected and the update stops with "The service manager rejected the updater job". Keep a valid XDG_RUNTIME_DIR when the environment provides one, derive /run/user/ when it exists, and carry DBUS_SESSION_BUS_ADDRESS when it is set. Nothing else about the launcher environment changes. --- loopdy_plugin/link_contracts.py | 2 +- loopdy_plugin/plugin_update.py | 15 ++++++- plugin.yaml | 2 +- tests/test_update_launcher_env.py | 73 +++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 tests/test_update_launcher_env.py diff --git a/loopdy_plugin/link_contracts.py b/loopdy_plugin/link_contracts.py index 8e8304c..f1bef60 100644 --- a/loopdy_plugin/link_contracts.py +++ b/loopdy_plugin/link_contracts.py @@ -112,7 +112,7 @@ def parse_direct_enrollment(payload: dict[str, Any]) -> dict[str, Any]: "body_fat_percentage", "workout", ) -PLUGIN_VERSION = "3.0.0" +PLUGIN_VERSION = "3.0.1" AVAILABLE_WIKI_OPERATIONS = available_wiki_operations() GROUPS_OPERATIONS = frozenset( { diff --git a/loopdy_plugin/plugin_update.py b/loopdy_plugin/plugin_update.py index 2224078..28d1ee8 100644 --- a/loopdy_plugin/plugin_update.py +++ b/loopdy_plugin/plugin_update.py @@ -568,11 +568,24 @@ def _clean_exec_command(command: list[str], *, hermes_home: Path) -> list[str]: def _launcher_env() -> dict[str, str]: - return { + env = { "PATH": os.environ.get("PATH", "/usr/local/bin:/usr/bin:/bin"), "HOME": str(Path.home()), "LANG": "C.UTF-8", } + # systemd-run --user cannot find the user bus without one of these. + runtime_dir = os.environ.get("XDG_RUNTIME_DIR") + if runtime_dir: + if os.path.isdir(runtime_dir): + env["XDG_RUNTIME_DIR"] = runtime_dir + elif hasattr(os, "getuid"): + runtime_dir = f"/run/user/{os.getuid()}" + if os.path.isdir(runtime_dir): + env["XDG_RUNTIME_DIR"] = runtime_dir + bus_address = os.environ.get("DBUS_SESSION_BUS_ADDRESS") + if bus_address: + env["DBUS_SESSION_BUS_ADDRESS"] = bus_address + return env def _wire_status(value: dict[str, Any]) -> dict[str, Any]: diff --git a/plugin.yaml b/plugin.yaml index bf39ea3..c0955f9 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -2,7 +2,7 @@ manifest_version: 1 name: loopdy label: bighelp kind: platform -version: "3.0.0" +version: "3.0.1" license: Apache-2.0 description: > The bighelp app's plugin for Hermes: native cards, Feed, Ideas and Goals, diff --git a/tests/test_update_launcher_env.py b/tests/test_update_launcher_env.py new file mode 100644 index 0000000..a5ab3db --- /dev/null +++ b/tests/test_update_launcher_env.py @@ -0,0 +1,73 @@ +"""Environment passed to the self-update launcher.""" +import os +import tempfile +import unittest +from unittest import mock + +from loopdy_plugin.plugin_update import _launcher_env + + +class UpdateLauncherEnvironmentTests(unittest.TestCase): + def test_carries_existing_xdg_runtime_directory(self): + with tempfile.TemporaryDirectory() as runtime_dir: + with mock.patch.dict(os.environ, { + "PATH": "/test/bin", + "HOME": "/test/home", + "XDG_RUNTIME_DIR": runtime_dir, + }, clear=True): + with mock.patch("loopdy_plugin.plugin_update.os.getuid", return_value=1234): + env = _launcher_env() + self.assertEqual(env.get("XDG_RUNTIME_DIR"), runtime_dir) + + def test_carries_dbus_session_bus_address_when_set(self): + with mock.patch.dict(os.environ, { + "PATH": "/test/bin", + "HOME": "/test/home", + "DBUS_SESSION_BUS_ADDRESS": "unix:path=/runtime/bus", + }, clear=True): + env = _launcher_env() + self.assertEqual(env.get("DBUS_SESSION_BUS_ADDRESS"), "unix:path=/runtime/bus") + + def test_keeps_path_home_and_lang(self): + with mock.patch.dict(os.environ, { + "PATH": "/test/bin", + "HOME": "/test/home", + }, clear=True): + env = _launcher_env() + self.assertEqual(env["PATH"], "/test/bin") + self.assertEqual(env["HOME"], "/test/home") + self.assertEqual(env["LANG"], "C.UTF-8") + + @unittest.skipUnless(os.path.isdir(f"/run/user/{os.getuid()}"), "real per-user runtime directory is unavailable") + def test_falls_back_to_existing_per_user_runtime_directory(self): + runtime_dir = f"/run/user/{os.getuid()}" + with mock.patch.dict(os.environ, { + "PATH": "/test/bin", + "HOME": "/test/home", + }, clear=True): + with mock.patch("loopdy_plugin.plugin_update.os.getuid", return_value=os.getuid()): + env = _launcher_env() + self.assertEqual(env.get("XDG_RUNTIME_DIR"), runtime_dir) + + def test_does_not_fall_back_when_per_user_runtime_directory_is_missing(self): + with mock.patch.dict(os.environ, { + "PATH": "/test/bin", + "HOME": "/test/home", + }, clear=True): + with mock.patch("loopdy_plugin.plugin_update.os.getuid", return_value=1234): + with mock.patch("loopdy_plugin.plugin_update.os.path.isdir", return_value=False): + env = _launcher_env() + self.assertNotIn("XDG_RUNTIME_DIR", env) + + def test_does_not_emit_nonexistent_xdg_runtime_directory(self): + with mock.patch.dict(os.environ, { + "PATH": "/test/bin", + "HOME": "/test/home", + "XDG_RUNTIME_DIR": "/no/such/runtime-directory-for-test", + }, clear=True): + env = _launcher_env() + self.assertNotIn("XDG_RUNTIME_DIR", env) + + +if __name__ == "__main__": + unittest.main() From 849a391c8e8460f55c6ca3ee898f0e38dc4c82e1 Mon Sep 17 00:00:00 2001 From: promptclickrun Date: Tue, 29 Sep 2026 09:00:40 -0500 Subject: [PATCH 2/2] Leave the version to the next release Plugin releases are batched now (#73): the release PR bumps the version. Co-Authored-By: Claude Opus 5.5 --- loopdy_plugin/link_contracts.py | 2 +- plugin.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/loopdy_plugin/link_contracts.py b/loopdy_plugin/link_contracts.py index f1bef60..8e8304c 100644 --- a/loopdy_plugin/link_contracts.py +++ b/loopdy_plugin/link_contracts.py @@ -112,7 +112,7 @@ def parse_direct_enrollment(payload: dict[str, Any]) -> dict[str, Any]: "body_fat_percentage", "workout", ) -PLUGIN_VERSION = "3.0.1" +PLUGIN_VERSION = "3.0.0" AVAILABLE_WIKI_OPERATIONS = available_wiki_operations() GROUPS_OPERATIONS = frozenset( { diff --git a/plugin.yaml b/plugin.yaml index c0955f9..bf39ea3 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -2,7 +2,7 @@ manifest_version: 1 name: loopdy label: bighelp kind: platform -version: "3.0.1" +version: "3.0.0" license: Apache-2.0 description: > The bighelp app's plugin for Hermes: native cards, Feed, Ideas and Goals,