-cpu flag

This commit is contained in:
Dobromir Popov
2026-07-09 08:19:15 +03:00
parent 4ed585bf54
commit 9ec4ca9ce1
8 changed files with 121 additions and 11 deletions

View File

@@ -610,3 +610,44 @@ def test_default_cli_passes_advertise_host(monkeypatch):
assert captured["tracker_url"] == "http://192.168.0.179:8081"
assert captured["advertise_host"] == "192.168.0.42"
assert captured["debug"] is True
def test_default_cli_passes_force_cpu(monkeypatch):
"""`meshnet-node --cpu` forwards force_cpu into run_startup."""
from meshnet_node.cli import main
captured = {}
def fake_run_startup(*args, **kwargs):
captured.update(kwargs)
class _FakeNode:
chat_completion_count = 0
def stop(self):
pass
return _FakeNode()
saved = {
"tracker_url": "http://localhost:8080",
"model_name": "stub-model",
"model_hf_repo": "",
"quantization": "auto",
"download_dir": "/tmp/models",
"wallet_path": "/tmp/wallet.json",
"port": 7000,
"host": "0.0.0.0",
}
monkeypatch.setattr(sys, "argv", ["meshnet-node", "--cpu"])
with patch("meshnet_node.config.load_config", return_value=saved):
with patch("meshnet_node.startup.run_startup", side_effect=fake_run_startup):
with patch("meshnet_node.dashboard.run_dashboard", side_effect=KeyboardInterrupt):
try:
main()
except SystemExit as exc:
assert exc.code == 0
assert captured["force_cpu"] is True

View File

@@ -34,6 +34,27 @@ from meshnet_tracker.server import TrackerServer
# ---------------------------------------------------------------------------
def test_with_forced_cpu_overrides_device_but_keeps_gpu_inventory():
"""--cpu should register and run on CPU while preserving detected GPU metadata."""
import meshnet_node.hardware as hardware_mod
hw = hardware_mod.with_forced_cpu(
{
"device": "cuda",
"gpu_name": "NVIDIA GeForce RTX 4060",
"vram_mb": 8192,
"dedicated_vram_mb": 8192,
"shared_vram_mb": 0,
"ram_mb": 32768,
"cuda_available": True,
}
)
assert hw["device"] == "cpu"
assert hw["cuda_available"] is False
assert hw["gpu_name"] == "NVIDIA GeForce RTX 4060"
assert hw["vram_mb"] == 8192
def test_detect_hardware_returns_valid_profile():
"""Hardware detection always returns a dict with required keys."""
hw = detect_hardware()