Skip to content

Commit 74d359f

Browse files
authored
Merge pull request #232 from mauriciopaim/fix/vulkan-capability-check
fix: don't treat a failed package install as missing Vulkan
2 parents ceef641 + b00882a commit 74d359f

2 files changed

Lines changed: 56 additions & 4 deletions

File tree

lib/src/backend_installer.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,11 +1157,9 @@ def setup_vulkan_support() -> bool:
11571157
check=False
11581158
)
11591159
if not result or result.returncode != 0:
1160-
log_warning("Failed to install some Vulkan packages")
1161-
return False
1160+
log_warning("Could not install Vulkan packages, checking for an existing Vulkan setup")
11621161
except Exception as e:
1163-
log_error(f"Failed to install Vulkan dependencies: {e}")
1164-
return False
1162+
log_warning(f"Could not install Vulkan dependencies ({e}), checking for an existing Vulkan setup")
11651163
else:
11661164
# Check if Vulkan development files are available
11671165
log_info("Checking for Vulkan development files...")

tests/test_vulkan_setup.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import sys
2+
import unittest
3+
from pathlib import Path
4+
from unittest import mock
5+
6+
ROOT = Path(__file__).resolve().parents[1]
7+
sys.path.insert(0, str(ROOT / "lib" / "src"))
8+
9+
import backend_installer # noqa: E402
10+
11+
12+
class FakeResult:
13+
def __init__(self, returncode=0, stdout=b""):
14+
self.returncode = returncode
15+
self.stdout = stdout
16+
17+
18+
GPU_SUMMARY = b"GPU0:\n\tapiVersion = 1.4.354\n\tdeviceName = Radeon RX 9070 XT\n\tdeviceType = PHYSICAL_DEVICE_TYPE_DISCRETE_GPU\n"
19+
20+
21+
class SetupVulkanSupportTests(unittest.TestCase):
22+
"""The package install is a convenience; `vulkaninfo` is the real check."""
23+
24+
def _run(self, pacman_result=None, pacman_exc=None, has_gpu=True):
25+
def fake_which(name):
26+
return f"/usr/bin/{name}" if name in ("pacman", "vulkaninfo") else None
27+
28+
sudo = mock.Mock(side_effect=pacman_exc) if pacman_exc else mock.Mock(return_value=pacman_result)
29+
30+
with mock.patch.object(backend_installer.shutil, "which", side_effect=fake_which), \
31+
mock.patch.object(backend_installer, "run_sudo_command", sudo), \
32+
mock.patch.object(backend_installer, "run_command", return_value=FakeResult(0, GPU_SUMMARY)), \
33+
mock.patch.object(backend_installer, "vulkaninfo_has_hardware_gpu", return_value=has_gpu):
34+
return backend_installer.setup_vulkan_support()
35+
36+
def test_failed_package_install_still_detects_working_vulkan(self):
37+
self.assertTrue(self._run(pacman_result=FakeResult(returncode=1)))
38+
39+
def test_sudo_exception_still_detects_working_vulkan(self):
40+
self.assertTrue(self._run(pacman_exc=PermissionError("a password is required")))
41+
42+
def test_no_result_from_package_install_still_detects_working_vulkan(self):
43+
self.assertTrue(self._run(pacman_result=None))
44+
45+
def test_successful_package_install_detects_working_vulkan(self):
46+
self.assertTrue(self._run(pacman_result=FakeResult(returncode=0)))
47+
48+
def test_still_returns_false_when_no_hardware_gpu(self):
49+
"""The capability check must remain authoritative in both directions."""
50+
self.assertFalse(self._run(pacman_result=FakeResult(returncode=1), has_gpu=False))
51+
52+
53+
if __name__ == "__main__":
54+
unittest.main()

0 commit comments

Comments
 (0)