test(game-mode): cover Ollama handoff client

This commit is contained in:
codex 2026-08-01 22:35:59 -03:00
parent e96614ef9b
commit 51e198ee79

View File

@ -207,3 +207,45 @@ def test_game_mode_status_degrades_to_fallback_when_dependencies_fail(monkeypatc
assert status["inference_path"] == "fallback"
assert "api down" in status["error"]
assert "ollama down" in status["error"]
def test_game_mode_ollama_client_and_loaded_model_detection(monkeypatch) -> None:
monkeypatch.setattr(game_mode_module, "settings", _handoff_settings())
calls: list[tuple[str, str, object]] = []
class FakeResponse:
def __init__(self, payload):
self.payload = payload
def raise_for_status(self):
return None
def json(self):
return self.payload
class FakeClient:
def __init__(self, timeout):
calls.append(("timeout", "", timeout))
def __enter__(self):
return self
def __exit__(self, *_args):
return False
def get(self, url):
calls.append(("get", url, None))
return FakeResponse({"models": [{"model": "gpt-oss:20b"}]})
def post(self, url, json):
calls.append(("post", url, json))
return FakeResponse({"response": "READY"})
monkeypatch.setattr(game_mode_module.httpx, "Client", FakeClient)
svc = GameModeService()
assert svc._ollama_get("/api/ps")["models"]
assert svc._ollama_post("/api/generate", {"prompt": "test"}) == {"response": "READY"}
assert svc._model_loaded() is True
assert ("get", "http://ollama.test:11434/api/ps", None) in calls
assert ("post", "http://ollama.test:11434/api/generate", {"prompt": "test"}) in calls