Files
gpu-rent/tests/test_tunnel_watch.py
T
Leonid Pershin dc1fde9e3e Refactor LLM runtime handling and enhance CLI documentation
- Updated `resolve_llm_runtime` to prioritize live configuration over legacy notes, ensuring accurate runtime resolution.
- Enhanced `tunnel_forwards` to prefer current configuration for LLM runtime, improving tunnel setup logic.
- Improved idle-killer logic to handle stale markers and provide clearer warnings in the status output.
- Updated CLI documentation in `cli.md` to reflect changes in command behavior and runtime handling.
- Enhanced tests to validate new runtime resolution logic and ensure proper handling of configuration states.
2026-08-21 05:40:22 +03:00

75 lines
2.1 KiB
Python

from gpu_rent.tunnel import decide_watch, tunnel_forwards
def test_decide_ok_active():
d = decide_watch("ACTIVE", tunnel_alive=True)
assert d.kind == "ok"
def test_decide_reconnect_when_tunnel_dead():
d = decide_watch("ACTIVE", tunnel_alive=False)
assert d.kind == "reconnect"
def test_decide_unshelve_expired():
for st in ("EXPIRED", "SHELVED", "SHELVED_OFFLOADED"):
d = decide_watch(st, tunnel_alive=True)
assert d.kind == "unshelve", st
def test_decide_exit_error():
d = decide_watch("ERROR", tunnel_alive=True)
assert d.kind == "exit"
def test_decide_exit_missing():
d = decide_watch(None, tunnel_alive=False)
assert d.kind == "exit"
def test_tunnel_forwards_swarm_only(monkeypatch):
class Cfg:
swarmui_local_port = 17801
llm_runtime = "none"
ollama_local_port = 17811
llamacpp_local_port = 17812
monkeypatch.setattr("gpu_rent.tunnel.load_state", lambda: type("S", (), {"notes": {}})())
assert tunnel_forwards(Cfg()) == [(17801, 7801)]
def test_tunnel_forwards_prefers_cfg_over_stale_notes(monkeypatch):
class Cfg:
swarmui_local_port = 17801
llm_runtime = "none"
ollama_local_port = 17811
llamacpp_local_port = 17812
monkeypatch.setattr(
"gpu_rent.tunnel.load_state",
lambda: type("S", (), {"notes": {"llm_runtime": "ollama"}})(),
)
assert tunnel_forwards(Cfg()) == [(17801, 7801)]
def test_resolve_llm_notes_only_when_cfg_none(monkeypatch):
from gpu_rent.access_card import resolve_llm_runtime
class Cfg:
llm_runtime = "none"
monkeypatch.setattr(
"gpu_rent.access_card.load_state",
lambda: type("S", (), {"notes": {"llm_runtime": "ollama"}})(),
)
assert resolve_llm_runtime(Cfg()) == "ollama"
class Cfg2:
llm_runtime = "llamacpp"
monkeypatch.setattr(
"gpu_rent.access_card.load_state",
lambda: type("S", (), {"notes": {"llm_runtime": "ollama"}})(),
)
assert resolve_llm_runtime(Cfg2()) == "llamacpp"