Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/tsk-mtf4dv-session-mode-needs-fallback.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
### Fixed\n- Session mode availability now requires both taos-kiosk.service and plasma-mobile.service; desks without the fallback unit are not offered a switch.
48 changes: 48 additions & 0 deletions tests/test_session_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,51 @@ async def json(self):
resp = await system_routes.set_session_mode(_Req())
assert resp.status_code == 400
assert started == []


@pytest.mark.asyncio
async def test_state_unavailable_on_desk_without_fallback(monkeypatch):
async def fake(*args):
if args[0] == "cat":
unit = args[-1]
if unit == "taos-kiosk.service":
return 0, "# unit"
if unit == "plasma-mobile.service":
return 1, "No files found"
return 0, "# unit"
return 3, "inactive"

monkeypatch.setattr(system_routes, "_systemctl", fake)
state = await system_routes._session_mode_state()
assert state["available"] is False


@pytest.mark.asyncio
async def test_switch_refused_on_desk_without_fallback(monkeypatch):
started: list[str] = []

async def fake(*args):
if args[0] == "start":
started.append(args[-1])
return 0, ""
if args[0] == "cat":
unit = args[-1]
if unit == "taos-kiosk.service":
return 0, "# unit"
if unit == "plasma-mobile.service":
return 1, "No files found"
return 1, "No files found"
return 3, "inactive"

monkeypatch.setattr(system_routes, "_systemctl", fake)

class _Req:
async def body(self):
return b'{"mode":"kiosk"}'

async def json(self):
return {"mode": "kiosk"}

resp = await system_routes.set_session_mode(_Req())
assert resp.status_code == 404
assert started == []
6 changes: 4 additions & 2 deletions tinyagentos/routes/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,9 @@ async def _session_mode_state() -> dict:
# and rc is not. An unknown unit reports "inactive" too, so availability is
# probed separately with `cat`, which fails only when the unit is absent.
cat_rc, _ = await _systemctl("cat", _SESSION_UNITS["kiosk"])
available = cat_rc == 0
# availability needs both units because a desk has the kiosk unit and no fallback
plasma_cat_rc, _ = await _systemctl("cat", _SESSION_UNITS["plasma"])
available = cat_rc == 0 and plasma_cat_rc == 0
_, plasma_state = await _systemctl("is-active", _SESSION_UNITS["plasma"])
if kiosk_state == "active":
current = "kiosk"
Expand Down Expand Up @@ -397,7 +399,7 @@ async def set_session_mode(request: Request):
state = await _session_mode_state()
if not state["available"]:
return JSONResponse(
{"error": "this device has no taOS kiosk session installed"}, status_code=404,
{"error": "this device has no second session to switch to"}, status_code=404,
)
# Starting the target stops the other: the units Conflict. Doing it as two
# jobs (stop-then-start) would leave a window with NO session on screen.
Expand Down
Loading