1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
|
"""Tests for fungus.umu_manager — UMU-Launcher installation and update management."""
import io
import os
import re
import subprocess
import tarfile
import tempfile
from pathlib import Path
from unittest.mock import MagicMock, patch
import pytest
# ---------------------------------------------------------------------------
# Helpers
# ---------------------------------------------------------------------------
def _make_tar_bytes(version: str = "1.4.0") -> bytes:
"""Create a tar archive containing ``umu/umu-run`` as bytes."""
buf = tempfile.NamedTemporaryFile(suffix=".tar", delete=False)
buf.close()
with tarfile.open(buf.name, "w:") as tar:
data = b"#!/bin/bash\necho umu-run\n"
# The source code extracts with tar.extractfile("umu/umu-run")
info = tarfile.TarInfo(name="umu/umu-run")
info.size = len(data)
info.mode = 0o755
tar.addfile(info, fileobj=io.BytesIO(data))
with open(buf.name, "rb") as f:
tar_bytes = f.read()
os.remove(buf.name)
return tar_bytes
def _make_bad_tar_bytes() -> bytes:
"""Create a tar archive WITHOUT umu/umu-run."""
buf = tempfile.NamedTemporaryFile(suffix=".tar", delete=False)
buf.close()
with tarfile.open(buf.name, "w:") as tar:
data = b"wrong content"
info = tarfile.TarInfo(name="wrong/path/file.txt")
info.size = len(data)
tar.addfile(info, fileobj=io.BytesIO(data))
with open(buf.name, "rb") as f:
tar_bytes = f.read()
os.remove(buf.name)
return tar_bytes
# ---------------------------------------------------------------------------
# Fixtures
# ---------------------------------------------------------------------------
@pytest.fixture()
def umu_install_dir(tmp_path):
"""Provide a temporary UMU install directory and patch module-level constants."""
install_dir = tmp_path / "fungus-launcher"
install_dir.mkdir()
with patch("fungus.umu_manager.UMU_INSTALL_DIR", str(install_dir)):
with patch("fungus.umu_manager.UMU_VERSION_FILE", str(install_dir / "version.txt")):
with patch("fungus.umu_manager.UMU_BIN_PATH", str(install_dir / "umu-run")):
with patch("fungus.umu_manager.STEAMRT_CHECK_FILE", str(install_dir / "steamrt.txt")):
yield install_dir
@pytest.fixture()
def mock_requests_get():
"""Provide a mock for requests.get that can be configured per-test."""
with patch("fungus.umu_manager.requests.get") as mock_get:
yield mock_get
@pytest.fixture()
def fake_proton_path(umu_install_dir):
"""Create a fake Proton directory under the temp data dir.
The update_steam_runtime function builds the proton path from XDG_DATA_HOME
(or ~/.local/share). We patch that so the directory exists under tmp_path.
"""
share_dir = umu_install_dir / "Steam" / "compatibilitytools.d"
share_dir.mkdir(parents=True, exist_ok=True)
with patch.dict(os.environ, {"XDG_DATA_HOME": str(umu_install_dir)}):
yield share_dir
# ---------------------------------------------------------------------------
# Test get_umu_run_path
# ---------------------------------------------------------------------------
class TestGetUmuRunPath:
def test_returns_path_from_constants(self):
"""get_umu_run_path should return the umu_run path from constants."""
from fungus.umu_manager import get_umu_run_path
with patch("fungus.constants.umu_run", Path("/custom/path/umu-run")):
result = get_umu_run_path()
assert result == "/custom/path/umu-run"
def test_returns_string(self):
"""The result should be a string, not a Path object."""
from fungus.umu_manager import get_umu_run_path
with patch("fungus.constants.umu_run", Path("/some/path")):
result = get_umu_run_path()
assert isinstance(result, str)
# ---------------------------------------------------------------------------
# Test get_latest_umu_version
# ---------------------------------------------------------------------------
class TestGetLatestUmuVersion:
def test_returns_tag_on_success(self, mock_requests_get):
"""Should return the tag_name from the first release."""
from fungus.umu_manager import get_latest_umu_version
mock_requests_get.return_value = MagicMock(
status_code=200,
json=lambda: [{"tag_name": "1.4.0"}],
text="ok",
)
result = get_latest_umu_version()
assert result == "1.4.0"
def test_returns_none_on_empty_releases(self, mock_requests_get):
"""Should return None when the releases list is empty."""
from fungus.umu_manager import get_latest_umu_version
mock_requests_get.return_value = MagicMock(
status_code=200,
json=lambda: [],
text="",
)
result = get_latest_umu_version()
assert result is None
def test_returns_none_on_non_200_status(self, mock_requests_get):
"""Should return None when the API returns a non-200 status."""
from fungus.umu_manager import get_latest_umu_version
mock_requests_get.return_value = MagicMock(
status_code=403,
json=lambda: [],
text="forbidden",
)
result = get_latest_umu_version()
assert result is None
def test_returns_none_on_request_exception(self, mock_requests_get):
"""Should return None when requests.get raises an exception."""
from fungus.umu_manager import get_latest_umu_version
mock_requests_get.side_effect = Exception("network error")
result = get_latest_umu_version()
assert result is None
def test_calls_api_with_timeout(self, mock_requests_get):
"""Should pass a timeout to requests.get."""
from fungus.umu_manager import get_latest_umu_version
mock_requests_get.return_value = MagicMock(
status_code=200,
json=lambda: [{"tag_name": "1.0.0"}],
text="ok",
)
get_latest_umu_version()
mock_requests_get.assert_called_once()
call_kwargs = mock_requests_get.call_args[1]
assert call_kwargs.get("timeout") == 5
# ---------------------------------------------------------------------------
# Test get_installed_umu_version
# ---------------------------------------------------------------------------
class TestGetInstalledUmuVersion:
def test_returns_version_from_file(self, umu_install_dir):
"""Should return the version string from the version file."""
version_file = umu_install_dir / "version.txt"
version_file.write_text("1.4.0", encoding="utf-8")
from fungus.umu_manager import get_installed_umu_version
result = get_installed_umu_version()
assert result == "1.4.0"
def test_strips_whitespace(self, umu_install_dir):
"""Should strip leading/trailing whitespace from the version file."""
version_file = umu_install_dir / "version.txt"
version_file.write_text(" 1.3.0 \n", encoding="utf-8")
from fungus.umu_manager import get_installed_umu_version
result = get_installed_umu_version()
assert result == "1.3.0"
def test_returns_none_when_file_missing(self, umu_install_dir):
"""Should return None when the version file does not exist."""
from fungus.umu_manager import get_installed_umu_version
result = get_installed_umu_version()
assert result is None
# ---------------------------------------------------------------------------
# Test is_umu_installed
# ---------------------------------------------------------------------------
class TestIsUmuInstalled:
def test_returns_true_when_binary_exists_and_executable(self, umu_install_dir):
"""Should return True when the binary exists and is executable."""
bin_path = umu_install_dir / "umu-run"
bin_path.write_text("#!/bin/bash\necho hello\n", encoding="utf-8")
bin_path.chmod(0o755)
from fungus.umu_manager import is_umu_installed
assert is_umu_installed() is True
def test_returns_false_when_binary_missing(self, umu_install_dir):
"""Should return False when the binary does not exist."""
from fungus.umu_manager import is_umu_installed
assert is_umu_installed() is False
def test_returns_false_when_not_executable(self, umu_install_dir):
"""Should return False when the binary exists but is not executable."""
bin_path = umu_install_dir / "umu-run"
bin_path.write_text("#!/bin/bash\necho hello\n", encoding="utf-8")
bin_path.chmod(0o644)
from fungus.umu_manager import is_umu_installed
assert is_umu_installed() is False
# ---------------------------------------------------------------------------
# Test get_steamrt_last_check
# ---------------------------------------------------------------------------
class TestGetSteamrtLastCheck:
def test_returns_timestamp_from_file(self, umu_install_dir):
"""Should return the timestamp string from the file."""
check_file = umu_install_dir / "steamrt.txt"
check_file.write_text("2025-07-01 14:30", encoding="utf-8")
from fungus.umu_manager import get_steamrt_last_check
result = get_steamrt_last_check()
assert result == "2025-07-01 14:30"
def test_returns_none_when_file_missing(self, umu_install_dir):
"""Should return None when the check file does not exist."""
from fungus.umu_manager import get_steamrt_last_check
result = get_steamrt_last_check()
assert result is None
def test_returns_none_when_file_empty(self, umu_install_dir):
"""Should return None when the file exists but is empty."""
check_file = umu_install_dir / "steamrt.txt"
check_file.write_text("", encoding="utf-8")
from fungus.umu_manager import get_steamrt_last_check
result = get_steamrt_last_check()
assert result is None
def test_returns_none_on_os_error(self, umu_install_dir):
"""Should return None when reading the file raises an OSError."""
check_file = umu_install_dir / "steamrt.txt"
check_file.write_text("2025-07-01 14:30", encoding="utf-8")
with patch("builtins.open", side_effect=OSError("permission denied")):
from fungus.umu_manager import get_steamrt_last_check
result = get_steamrt_last_check()
assert result is None
# ---------------------------------------------------------------------------
# Test save_steamrt_last_check
# ---------------------------------------------------------------------------
class TestSaveSteamrtLastCheck:
def test_writes_timestamp_and_returns_true(self, umu_install_dir):
"""Should write a timestamp and return True on success."""
from fungus.umu_manager import save_steamrt_last_check
result = save_steamrt_last_check()
assert result is True
check_file = umu_install_dir / "steamrt.txt"
assert check_file.exists()
content = check_file.read_text(encoding="utf-8").strip()
# Should match YYYY-MM-DD HH:MM format
assert re.match(r"\d{4}-\d{2}-\d{2} \d{2}:\d{2}", content)
def test_creates_directory_if_missing(self, umu_install_dir):
"""Should create the install directory if it does not exist."""
import shutil
shutil.rmtree(umu_install_dir)
with patch("fungus.umu_manager.UMU_INSTALL_DIR", str(umu_install_dir)):
with patch("fungus.umu_manager.STEAMRT_CHECK_FILE", str(umu_install_dir / "steamrt.txt")):
from fungus.umu_manager import save_steamrt_last_check
result = save_steamrt_last_check()
assert result is True
assert umu_install_dir.exists()
def test_returns_false_on_os_error(self, umu_install_dir):
"""Should return False when writing raises an OSError."""
with patch("builtins.open", side_effect=OSError("permission denied")):
with patch("os.makedirs", side_effect=OSError("permission denied")):
from fungus.umu_manager import save_steamrt_last_check
result = save_steamrt_last_check()
assert result is False
# ---------------------------------------------------------------------------
# Test download_umu_run
# ---------------------------------------------------------------------------
class TestDownloadUmuRun:
def test_successful_download_and_install(self, umu_install_dir, mock_requests_get):
"""Should download, extract, and install umu-run successfully."""
tar_bytes = _make_tar_bytes()
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.headers = {"content-length": str(len(tar_bytes))}
mock_response.iter_content.return_value = [tar_bytes]
mock_requests_get.return_value = mock_response
from fungus.umu_manager import download_umu_run
result = download_umu_run("1.4.0")
assert result is True
bin_path = umu_install_dir / "umu-run"
assert bin_path.exists()
assert os.access(str(bin_path), os.X_OK)
version_file = umu_install_dir / "version.txt"
assert version_file.read_text(encoding="utf-8").strip() == "1.4.0"
def test_returns_false_on_non_200_response(self, umu_install_dir, mock_requests_get):
"""Should return False when the download returns a non-200 status."""
mock_requests_get.return_value = MagicMock(
status_code=404,
headers={},
text="not found",
)
from fungus.umu_manager import download_umu_run
result = download_umu_run("9.9.9")
assert result is False
def test_returns_false_on_request_exception(self, umu_install_dir, mock_requests_get):
"""Should return False when the download request fails."""
mock_requests_get.side_effect = Exception("connection refused")
from fungus.umu_manager import download_umu_run
result = download_umu_run("1.4.0")
assert result is False
def test_returns_false_when_tar_missing_member(self, umu_install_dir, mock_requests_get):
"""Should return False when the tar archive doesn't contain umu/umu-run."""
tar_bytes = _make_bad_tar_bytes()
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.headers = {"content-length": str(len(tar_bytes))}
mock_response.iter_content.return_value = [tar_bytes]
mock_requests_get.return_value = mock_response
from fungus.umu_manager import download_umu_run
result = download_umu_run("1.4.0")
assert result is False
def test_calls_progress_callback(self, umu_install_dir, mock_requests_get):
"""Should call the progress callback with percentage values."""
tar_bytes = _make_tar_bytes()
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.headers = {"content-length": str(len(tar_bytes))}
mock_response.iter_content.return_value = [tar_bytes]
mock_requests_get.return_value = mock_response
callback = MagicMock()
from fungus.umu_manager import download_umu_run
download_umu_run("1.4.0", progress_callback=callback)
callback.assert_called()
# Should have been called with 100 at the end
calls = [c[0][0] for c in callback.call_args_list]
assert 100 in calls
def test_returns_false_on_chmod_failure(self, umu_install_dir, mock_requests_get):
"""Should return False if setting executable permission fails."""
tar_bytes = _make_tar_bytes()
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.headers = {"content-length": str(len(tar_bytes))}
mock_response.iter_content.return_value = [tar_bytes]
mock_requests_get.return_value = mock_response
with patch("os.chmod", side_effect=OSError("permission denied")):
from fungus.umu_manager import download_umu_run
result = download_umu_run("1.4.0")
assert result is False
def test_returns_false_on_version_file_write_failure(self, umu_install_dir, mock_requests_get):
"""Should return False if writing the version file fails."""
tar_bytes = _make_tar_bytes()
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.headers = {"content-length": str(len(tar_bytes))}
mock_response.iter_content.return_value = [tar_bytes]
mock_requests_get.return_value = mock_response
# Patch only the open call that writes the version file
original_open = open
def failing_open(*args, **kwargs):
if args and "version.txt" in str(args[0]):
raise OSError("disk full")
return original_open(*args, **kwargs)
with patch("builtins.open", failing_open):
from fungus.umu_manager import download_umu_run
result = download_umu_run("1.4.0")
assert result is False
def test_creates_install_directory(self, umu_install_dir, mock_requests_get):
"""Should create the install directory if it doesn't exist."""
import shutil
shutil.rmtree(umu_install_dir)
tar_bytes = _make_tar_bytes()
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.headers = {"content-length": str(len(tar_bytes))}
mock_response.iter_content.return_value = [tar_bytes]
mock_requests_get.return_value = mock_response
from fungus.umu_manager import download_umu_run
result = download_umu_run("1.4.0")
assert result is True
assert umu_install_dir.exists()
def test_cleans_up_temp_file_on_failure(self, umu_install_dir, mock_requests_get):
"""Should clean up the temporary download file on failure."""
mock_requests_get.return_value = MagicMock(status_code=404, headers={}, text="not found")
from fungus.umu_manager import download_umu_run
download_umu_run("9.9.9")
# No temp files should remain in /tmp matching our pattern
# (hard to verify precisely, but at least it shouldn't crash)
# ---------------------------------------------------------------------------
# Test check_and_install_if_needed
# ---------------------------------------------------------------------------
class TestCheckAndInstallIfNeeded:
def test_up_to_date(self, umu_install_dir):
"""Should return (True, 'up_to_date') when already at the latest version."""
bin_path = umu_install_dir / "umu-run"
bin_path.write_text("#!/bin/bash\n", encoding="utf-8")
bin_path.chmod(0o755)
(umu_install_dir / "version.txt").write_text("1.4.0", encoding="utf-8")
with patch("fungus.umu_manager.get_latest_umu_version", return_value="1.4.0"):
from fungus.umu_manager import check_and_install_if_needed
result = check_and_install_if_needed()
assert result == (True, "up_to_date")
def test_updates_when_outdated(self, umu_install_dir, mock_requests_get):
"""Should download and update when a newer version is available."""
bin_path = umu_install_dir / "umu-run"
bin_path.write_text("#!/bin/bash\n", encoding="utf-8")
bin_path.chmod(0o755)
(umu_install_dir / "version.txt").write_text("1.3.0", encoding="utf-8")
tar_bytes = _make_tar_bytes("1.4.0")
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.headers = {"content-length": str(len(tar_bytes))}
mock_response.iter_content.return_value = [tar_bytes]
mock_requests_get.return_value = mock_response
with patch("fungus.umu_manager.get_latest_umu_version", return_value="1.4.0"):
from fungus.umu_manager import check_and_install_if_needed
result = check_and_install_if_needed()
assert result[1] == "updated"
assert result[0] is True
def test_installs_when_not_installed(self, umu_install_dir, mock_requests_get):
"""Should download and install when umu-run is not present."""
tar_bytes = _make_tar_bytes("1.4.0")
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.headers = {"content-length": str(len(tar_bytes))}
mock_response.iter_content.return_value = [tar_bytes]
mock_requests_get.return_value = mock_response
with patch("fungus.umu_manager.get_latest_umu_version", return_value="1.4.0"):
from fungus.umu_manager import check_and_install_if_needed
result = check_and_install_if_needed()
assert result[1] == "installed"
assert result[0] is True
def test_returns_failed_when_latest_version_fetch_fails(self, umu_install_dir):
"""Should return (False, 'failed') when the version API is unreachable."""
with patch("fungus.umu_manager.get_latest_umu_version", return_value=None):
from fungus.umu_manager import check_and_install_if_needed
result = check_and_install_if_needed()
assert result == (False, "failed")
def test_returns_failed_when_update_download_fails(self, umu_install_dir, mock_requests_get):
"""Should return (False, 'failed') when the download fails during update."""
bin_path = umu_install_dir / "umu-run"
bin_path.write_text("#!/bin/bash\n", encoding="utf-8")
bin_path.chmod(0o755)
(umu_install_dir / "version.txt").write_text("1.3.0", encoding="utf-8")
mock_requests_get.return_value = MagicMock(status_code=404, headers={}, text="not found")
with patch("fungus.umu_manager.get_latest_umu_version", return_value="1.4.0"):
from fungus.umu_manager import check_and_install_if_needed
result = check_and_install_if_needed()
assert result == (False, "failed")
def test_returns_failed_when_install_download_fails(self, umu_install_dir, mock_requests_get):
"""Should return (False, 'failed') when the download fails during install."""
mock_requests_get.return_value = MagicMock(status_code=404, headers={}, text="not found")
with patch("fungus.umu_manager.get_latest_umu_version", return_value="1.4.0"):
from fungus.umu_manager import check_and_install_if_needed
result = check_and_install_if_needed()
assert result == (False, "failed")
def test_returns_failed_when_latest_api_returns_none_during_update(self, umu_install_dir):
"""Should return (False, 'failed') when API returns None during update check."""
bin_path = umu_install_dir / "umu-run"
bin_path.write_text("#!/bin/bash\n", encoding="utf-8")
bin_path.chmod(0o755)
(umu_install_dir / "version.txt").write_text("1.3.0", encoding="utf-8")
with patch("fungus.umu_manager.get_latest_umu_version", return_value=None):
from fungus.umu_manager import check_and_install_if_needed
result = check_and_install_if_needed()
assert result == (False, "failed")
def test_calls_progress_callback_on_update(self, umu_install_dir, mock_requests_get):
"""Progress callback should be forwarded during update."""
bin_path = umu_install_dir / "umu-run"
bin_path.write_text("#!/bin/bash\n", encoding="utf-8")
bin_path.chmod(0o755)
(umu_install_dir / "version.txt").write_text("1.3.0", encoding="utf-8")
tar_bytes = _make_tar_bytes("1.4.0")
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.headers = {"content-length": str(len(tar_bytes))}
mock_response.iter_content.return_value = [tar_bytes]
mock_requests_get.return_value = mock_response
callback = MagicMock()
with patch("fungus.umu_manager.get_latest_umu_version", return_value="1.4.0"):
from fungus.umu_manager import check_and_install_if_needed
check_and_install_if_needed(progress_callback=callback)
callback.assert_called()
def test_calls_progress_callback_on_install(self, umu_install_dir, mock_requests_get):
"""Progress callback should be forwarded during initial install."""
tar_bytes = _make_tar_bytes("1.4.0")
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.headers = {"content-length": str(len(tar_bytes))}
mock_response.iter_content.return_value = [tar_bytes]
mock_requests_get.return_value = mock_response
callback = MagicMock()
with patch("fungus.umu_manager.get_latest_umu_version", return_value="1.4.0"):
from fungus.umu_manager import check_and_install_if_needed
check_and_install_if_needed(progress_callback=callback)
callback.assert_called()
# ---------------------------------------------------------------------------
# Test update_steam_runtime
# ---------------------------------------------------------------------------
class TestUpdateSteamRuntime:
def test_returns_error_when_proton_path_not_found(self):
"""Should return an error when the Proton directory does not exist."""
with patch("fungus.umu_manager.get_umu_run_path", return_value="/fake/umu-run"):
from fungus.umu_manager import update_steam_runtime
result = update_steam_runtime("Proton-9.0")
assert result[0] is False
assert "Proton path not found" in result[1]
def test_runs_wineprefixcreate_command(self, umu_install_dir, fake_proton_path):
"""Should run umu-run with wineprefixcreate and correct env vars."""
(fake_proton_path / "Proton-9.0").mkdir(parents=True, exist_ok=True)
mock_proc = MagicMock()
mock_proc.stdout = iter(["Already up to date\n"])
mock_proc.wait.return_value = 0
mock_proc.returncode = 0
with patch("fungus.umu_manager.get_umu_run_path", return_value="/fake/umu-run"):
with patch("subprocess.Popen", return_value=mock_proc):
from fungus.umu_manager import update_steam_runtime
result = update_steam_runtime("Proton-9.0")
assert result[0] is True
assert result[1] == "Already up to date"
subprocess.Popen.assert_called_once() # pyright: ignore[reportAttributeAccessIssue]
call_args = subprocess.Popen.call_args # pyright: ignore[reportAttributeAccessIssue]
cmd = call_args[0][0]
assert cmd[0] == "/fake/umu-run"
assert "wineprefixcreate" in cmd
assert "/usr/bin/true" in cmd
def test_sets_proton_version_env(self, umu_install_dir, fake_proton_path):
"""Should set PROTONVERSION env var for Proton 9.x."""
(fake_proton_path / "Proton-9.0").mkdir(parents=True, exist_ok=True)
mock_proc = MagicMock()
mock_proc.stdout = iter(["Done\n"])
mock_proc.wait.return_value = 0
mock_proc.returncode = 0
with patch("fungus.umu_manager.get_umu_run_path", return_value="/fake/umu-run"):
with patch("subprocess.Popen", return_value=mock_proc):
from fungus.umu_manager import update_steam_runtime
update_steam_runtime("Proton-9.0")
call_kwargs = subprocess.Popen.call_args[1] # pyright: ignore[reportAttributeAccessIssue]
env = call_kwargs["env"]
assert env.get("PROTONVERSION") == "9"
def test_sets_proton_version_env_for_proton_11(self, umu_install_dir, fake_proton_path):
"""Should set PROTONVERSION for Proton 11.x."""
(fake_proton_path / "Proton-11.0-1").mkdir(parents=True, exist_ok=True)
mock_proc = MagicMock()
mock_proc.stdout = iter(["Done\n"])
mock_proc.wait.return_value = 0
mock_proc.returncode = 0
with patch("fungus.umu_manager.get_umu_run_path", return_value="/fake/umu-run"):
with patch("subprocess.Popen", return_value=mock_proc):
from fungus.umu_manager import update_steam_runtime
update_steam_runtime("Proton-11.0-1")
call_kwargs = subprocess.Popen.call_args[1] # pyright: ignore[reportAttributeAccessIssue]
env = call_kwargs["env"]
assert env.get("PROTONVERSION") == "11"
def test_does_not_set_proton_version_for_unknown_format(self, umu_install_dir, fake_proton_path):
"""Should not set PROTONVERSION if version cannot be parsed."""
(fake_proton_path / "UnknownFormat").mkdir(parents=True, exist_ok=True)
mock_proc = MagicMock()
mock_proc.stdout = iter(["Done\n"])
mock_proc.wait.return_value = 0
mock_proc.returncode = 0
with patch("fungus.umu_manager.get_umu_run_path", return_value="/fake/umu-run"):
with patch("subprocess.Popen", return_value=mock_proc):
from fungus.umu_manager import update_steam_runtime
update_steam_runtime("UnknownFormat")
call_kwargs = subprocess.Popen.call_args[1] # pyright: ignore[reportAttributeAccessIssue]
env = call_kwargs["env"]
assert "PROTONVERSION" not in env
def test_returns_update_ok_on_success(self, umu_install_dir, fake_proton_path):
"""Should return (True, 'Update OK') on successful runtime update."""
(fake_proton_path / "Proton-9.0").mkdir(parents=True, exist_ok=True)
mock_proc = MagicMock()
mock_proc.stdout = iter(["Downloading steamrt...\n", "Extracting...\n", "Done\n"])
mock_proc.wait.return_value = 0
mock_proc.returncode = 0
with patch("fungus.umu_manager.get_umu_run_path", return_value="/fake/umu-run"):
with patch("subprocess.Popen", return_value=mock_proc):
from fungus.umu_manager import update_steam_runtime
result = update_steam_runtime("Proton-9.0")
assert result == (True, "Update OK")
def test_calls_progress_callback_on_download(self, umu_install_dir, fake_proton_path):
"""Progress callback should be called when Downloading/Extracting is seen."""
(fake_proton_path / "Proton-9.0").mkdir(parents=True, exist_ok=True)
mock_proc = MagicMock()
mock_proc.stdout = iter(["Downloading steamrt...\n", "Done\n"])
mock_proc.wait.return_value = 0
mock_proc.returncode = 0
callback = MagicMock()
with patch("fungus.umu_manager.get_umu_run_path", return_value="/fake/umu-run"):
with patch("subprocess.Popen", return_value=mock_proc):
from fungus.umu_manager import update_steam_runtime
update_steam_runtime("Proton-9.0", progress_callback=callback)
callback.assert_any_call(50)
def test_calls_on_success_callback(self, umu_install_dir, fake_proton_path):
"""on_success callback should be called on 'Already up to date'."""
(fake_proton_path / "Proton-9.0").mkdir(parents=True, exist_ok=True)
mock_proc = MagicMock()
mock_proc.stdout = iter(["Already up to date\n"])
mock_proc.wait.return_value = 0
mock_proc.returncode = 0
on_success = MagicMock()
with patch("fungus.umu_manager.get_umu_run_path", return_value="/fake/umu-run"):
with patch("subprocess.Popen", return_value=mock_proc):
from fungus.umu_manager import update_steam_runtime
result = update_steam_runtime(
"Proton-9.0",
on_success=on_success,
)
assert result[0] is True
on_success.assert_called_once()
def test_calls_on_success_on_update_ok(self, umu_install_dir, fake_proton_path):
"""on_success callback should be called on successful update."""
(fake_proton_path / "Proton-9.0").mkdir(parents=True, exist_ok=True)
mock_proc = MagicMock()
mock_proc.stdout = iter(["Done\n"])
mock_proc.wait.return_value = 0
mock_proc.returncode = 0
on_success = MagicMock()
with patch("fungus.umu_manager.get_umu_run_path", return_value="/fake/umu-run"):
with patch("subprocess.Popen", return_value=mock_proc):
from fungus.umu_manager import update_steam_runtime
result = update_steam_runtime(
"Proton-9.0",
on_success=on_success,
)
assert result[0] is True
on_success.assert_called_once()
def test_returns_failed_on_nonzero_exit(self, umu_install_dir, fake_proton_path):
"""Should return (False, message) when umu-run exits with non-zero code."""
(fake_proton_path / "Proton-9.0").mkdir(parents=True, exist_ok=True)
mock_proc = MagicMock()
mock_proc.stdout = iter(["Error occurred\n"])
mock_proc.wait.return_value = 1
mock_proc.returncode = 1
with patch("fungus.umu_manager.get_umu_run_path", return_value="/fake/umu-run"):
with patch("subprocess.Popen", return_value=mock_proc):
from fungus.umu_manager import update_steam_runtime
result = update_steam_runtime("Proton-9.0")
assert result[0] is False
assert "exit code 1" in result[1]
def test_returns_failed_on_subprocess_exception(self, umu_install_dir, fake_proton_path):
"""Should return (False, str(e)) when subprocess.Popen raises an exception."""
(fake_proton_path / "Proton-9.0").mkdir(parents=True, exist_ok=True)
with patch("fungus.umu_manager.get_umu_run_path", return_value="/fake/umu-run"):
with patch("subprocess.Popen", side_effect=FileNotFoundError("bwrap not found")):
from fungus.umu_manager import update_steam_runtime
result = update_steam_runtime("Proton-9.0")
assert result[0] is False
assert "bwrap not found" in result[1]
def test_returns_failed_when_no_stdout(self, umu_install_dir, fake_proton_path):
"""Should return (False, 'No output from umu-run') when stdout is None."""
(fake_proton_path / "Proton-9.0").mkdir(parents=True, exist_ok=True)
mock_proc = MagicMock()
mock_proc.stdout = None
mock_proc.wait.return_value = 0
with patch("fungus.umu_manager.get_umu_run_path", return_value="/fake/umu-run"):
with patch("subprocess.Popen", return_value=mock_proc):
from fungus.umu_manager import update_steam_runtime
result = update_steam_runtime("Proton-9.0")
assert result == (False, "No output from umu-run")
def test_sets_gameid_env(self, umu_install_dir, fake_proton_path):
"""Should set GAMEID environment variable."""
(fake_proton_path / "Proton-9.0").mkdir(parents=True, exist_ok=True)
mock_proc = MagicMock()
mock_proc.stdout = iter(["Done\n"])
mock_proc.wait.return_value = 0
mock_proc.returncode = 0
with patch("fungus.umu_manager.get_umu_run_path", return_value="/fake/umu-run"):
with patch("subprocess.Popen", return_value=mock_proc):
from fungus.umu_manager import update_steam_runtime
update_steam_runtime("Proton-9.0")
call_kwargs = subprocess.Popen.call_args[1] # pyright: ignore[reportAttributeAccessIssue]
env = call_kwargs["env"]
assert env.get("GAMEID") == "umu-update-handshake"
def test_sets_protonpath_env(self, umu_install_dir, fake_proton_path):
"""Should set PROTONPATH to the full path of the Proton directory."""
(fake_proton_path / "Proton-9.0").mkdir(parents=True, exist_ok=True)
mock_proc = MagicMock()
mock_proc.stdout = iter(["Done\n"])
mock_proc.wait.return_value = 0
mock_proc.returncode = 0
with patch("fungus.umu_manager.get_umu_run_path", return_value="/fake/umu-run"):
with patch("subprocess.Popen", return_value=mock_proc):
from fungus.umu_manager import update_steam_runtime
update_steam_runtime("Proton-9.0")
call_kwargs = subprocess.Popen.call_args[1] # pyright: ignore[reportAttributeAccessIssue]
env = call_kwargs["env"]
assert env.get("PROTONPATH") == str(fake_proton_path / "Proton-9.0")
|