# SPDX-License-Identifier: MIT """Tests for RDP session management.""" from __future__ import annotations import pytest from winpodx.core.config import Config from winpodx.core.rdp import _auto_kbd_flag, build_rdp_command, linux_to_unc def test_linux_to_unc_home(monkeypatch, tmp_path): monkeypatch.setattr("winpodx.core.rdp.Path.home", staticmethod(lambda: tmp_path)) doc = tmp_path / "Documents" / "test.docx" doc.parent.mkdir() doc.touch() result = linux_to_unc(str(doc)) assert result == "\\\\tsclient\\home\\Documents\\test.docx" def test_linux_to_unc_outside_home_raises(monkeypatch, tmp_path): # Paths outside $HOME and any media share must raise. monkeypatch.setattr("winpodx.core.rdp.Path.home", staticmethod(lambda: tmp_path / "home")) monkeypatch.setattr("winpodx.core.rdp._find_media_base", lambda: None) with pytest.raises(ValueError, match="outside shared locations"): linux_to_unc("/tmp/test.txt") def test_linux_to_unc_media_path(monkeypatch, tmp_path): media = tmp_path / "run_media" / "user" media.mkdir(parents=True) usb_file = media / "USB" / "report.docx" usb_file.parent.mkdir() usb_file.touch() monkeypatch.setattr("winpodx.core.rdp.Path.home", staticmethod(lambda: tmp_path / "home")) monkeypatch.setattr("winpodx.core.rdp._find_media_base", lambda: media) result = linux_to_unc(str(usb_file)) assert result == "\\\\tsclient\\media\\USB\\report.docx" def test_find_media_base_prefers_user_then_persistent_parent(monkeypatch): # A live media parent is preferred over the placeholder so a USB inserted # AFTER the session starts shows on refresh. Per-user dir wins; the # persistent parent is the fallback for the not-mounted-yet-at-launch case. from winpodx.core import rdp monkeypatch.setenv("USER", "alice") present: set[str] = set() monkeypatch.setattr(rdp.Path, "is_dir", lambda self: str(self) in present) # Nothing mounted, no media subsystem dir -> None (caller uses placeholder). assert rdp._find_media_base() is None # USB inserted while no per-user dir existed yet: the persistent parent # exists, so we redirect it (USB shows at \\media\alice\