Add E2E tests, fix bugs

Made-with: Cursor
This commit is contained in:
Oleksandr Bezdieniezhnykh
2026-04-13 05:17:48 +03:00
parent 1f98b5e958
commit 8f7deb3fca
71 changed files with 4740 additions and 29 deletions
+79 -28
View File
@@ -1,9 +1,83 @@
import os
import platform
import subprocess
import psutil
cimport constants
cdef str _CACHED_HW_INFO = None
def _get_cpu():
try:
with open("/proc/cpuinfo") as f:
for line in f:
if "model name" in line.lower():
return line.split(":")[1].strip()
except OSError:
pass
cdef str p = platform.processor()
if p:
return p
return platform.machine()
def _get_gpu():
try:
result = subprocess.run(
["lspci"], capture_output=True, text=True, timeout=5,
)
for line in result.stdout.splitlines():
if "VGA" in line:
parts = line.split(":")
if len(parts) > 2:
return parts[2].strip()
return parts[-1].strip()
except (OSError, subprocess.TimeoutExpired, FileNotFoundError):
pass
try:
result = subprocess.run(
["system_profiler", "SPDisplaysDataType"],
capture_output=True, text=True, timeout=5,
)
for line in result.stdout.splitlines():
if "Chipset Model" in line:
return line.split(":")[1].strip()
except (OSError, subprocess.TimeoutExpired, FileNotFoundError):
pass
return "unknown"
def _get_drive_serial():
try:
for block in sorted(os.listdir("/sys/block")):
for candidate in [
f"/sys/block/{block}/device/vpd_pg80",
f"/sys/block/{block}/device/serial",
f"/sys/block/{block}/serial",
]:
try:
with open(candidate, "rb") as f:
serial = f.read().strip(b"\x00\x14 \t\n\r\v\f").decode("utf-8", errors="ignore")
if serial:
return serial
except OSError:
continue
except OSError:
pass
try:
result = subprocess.run(
["ioreg", "-rd1", "-c", "IOPlatformExpertDevice"],
capture_output=True, text=True, timeout=5,
)
for line in result.stdout.splitlines():
if "IOPlatformSerialNumber" in line:
return line.split('"')[-2]
except (OSError, subprocess.TimeoutExpired, FileNotFoundError):
pass
return "unknown"
cdef class HardwareService:
@staticmethod
@@ -14,35 +88,12 @@ cdef class HardwareService:
constants.log(<str>"Using cached hardware info")
return <str> _CACHED_HW_INFO
if os.name == 'nt': # windows
os_command = (
"powershell -Command \""
"Get-CimInstance -ClassName Win32_Processor | Select-Object -ExpandProperty Name | Write-Output; "
"Get-CimInstance -ClassName Win32_VideoController | Select-Object -ExpandProperty Name | Write-Output; "
"Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -ExpandProperty TotalVisibleMemorySize | Write-Output; "
"(Get-Disk | Where-Object {$_.IsSystem -eq $true}).SerialNumber"
"\""
)
else:
os_command = (
"lscpu | grep 'Model name:' | cut -d':' -f2 && "
"lspci | grep VGA | cut -d':' -f3 && "
"free -k | awk '/^Mem:/ {print $2}' && "
"cat /sys/block/sda/device/vpd_pg80 2>/dev/null || cat /sys/block/sda/device/serial 2>/dev/null"
)
cdef str cpu = _get_cpu()
cdef str gpu = _get_gpu()
cdef str memory = str(psutil.virtual_memory().total // 1024)
cdef str drive_serial = _get_drive_serial()
result = subprocess.check_output(os_command, shell=True).decode('utf-8', errors='ignore')
lines = [line.replace(" ", " ").replace("Name=", "").strip('\x00\x14 \t\n\r\v\f') for line in result.splitlines() if line.strip()]
cdef str cpu = lines[0]
cdef str gpu = lines[1]
# could be multiple gpus
len_lines = len(lines)
cdef str memory = lines[len_lines-2].replace("TotalVisibleMemorySize=", "").replace(" ", " ")
cdef str drive_serial = lines[len_lines-1]
cdef str res = f'CPU: {cpu}. GPU: {gpu}. Memory: {memory}. DriveSerial: {drive_serial}'
cdef str res = f'CPU: {cpu}. GPU: {gpu}. Memory: {memory}. DriveSerial: {drive_serial}'
constants.log(<str>f'Gathered hardware: {res}')
_CACHED_HW_INFO = res
return res