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.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
"""Unit tests for remote ollama_pull matching (stdlib helpers)."""
|
||||
|
||||
from importlib.util import module_from_spec, spec_from_file_location
|
||||
from pathlib import Path
|
||||
|
||||
_ROOT = Path(__file__).resolve().parents[1]
|
||||
_SPEC = spec_from_file_location(
|
||||
"ollama_pull_remote",
|
||||
_ROOT / "src" / "gpu_rent" / "remote" / "ollama_pull.py",
|
||||
)
|
||||
assert _SPEC and _SPEC.loader
|
||||
_mod = module_from_spec(_SPEC)
|
||||
_SPEC.loader.exec_module(_mod)
|
||||
already_have = _mod.already_have
|
||||
|
||||
|
||||
def test_exact_tag_only():
|
||||
have = {"qwen2.5:3b", "qwen2.5:7b"}
|
||||
assert already_have(have, "qwen2.5:7b")
|
||||
assert not already_have(have, "qwen2.5:14b")
|
||||
assert already_have(have, "qwen2.5:3b")
|
||||
|
||||
|
||||
def test_latest_alias():
|
||||
assert already_have({"foo:latest"}, "foo")
|
||||
assert already_have({"foo"}, "foo:latest")
|
||||
assert not already_have({"foo:3b"}, "foo")
|
||||
@@ -38,12 +38,37 @@ def test_tunnel_forwards_swarm_only(monkeypatch):
|
||||
assert tunnel_forwards(Cfg()) == [(17801, 7801)]
|
||||
|
||||
|
||||
def test_tunnel_forwards_ollama(monkeypatch):
|
||||
def test_tunnel_forwards_prefers_cfg_over_stale_notes(monkeypatch):
|
||||
class Cfg:
|
||||
swarmui_local_port = 17801
|
||||
llm_runtime = "ollama"
|
||||
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), (17811, 11434)]
|
||||
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"
|
||||
|
||||
Reference in New Issue
Block a user