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_ollama(monkeypatch): class Cfg: swarmui_local_port = 17801 llm_runtime = "ollama" 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)]