linux observer
1# SPDX-License-Identifier: AGPL-3.0-only
2# Copyright (c) 2026 sol pbc
3
4"""Tests for session environment checks."""
5
6import os
7from unittest.mock import patch
8
9from solstone_linux.session_env import check_session_ready
10
11
12class TestCheckSessionReady:
13 """Test desktop session readiness checks."""
14
15 def test_no_display_server(self):
16 env = {
17 k: v for k, v in os.environ.items()
18 if k not in ("DISPLAY", "WAYLAND_DISPLAY")
19 }
20 with patch.dict(os.environ, env, clear=True):
21 with patch("solstone_linux.session_env._recover_session_env"):
22 result = check_session_ready()
23 assert result is not None
24 assert "display server" in result
25
26 def test_no_dbus(self):
27 env = {
28 k: v for k, v in os.environ.items()
29 if k != "DBUS_SESSION_BUS_ADDRESS"
30 }
31 env["DISPLAY"] = ":0"
32 with patch.dict(os.environ, env, clear=True):
33 with patch("solstone_linux.session_env._recover_session_env"):
34 result = check_session_ready()
35 assert result is not None
36 assert "DBus" in result
37
38 def test_ready_with_display_and_dbus(self):
39 env = dict(os.environ)
40 env["DISPLAY"] = ":0"
41 env["DBUS_SESSION_BUS_ADDRESS"] = "unix:path=/run/user/1000/bus"
42 with patch.dict(os.environ, env, clear=True):
43 with patch("solstone_linux.session_env._recover_session_env"):
44 with patch("solstone_linux.session_env.shutil") as mock_shutil:
45 mock_shutil.which.return_value = None # No pactl
46 result = check_session_ready()
47 assert result is None # Ready