From 51e198ee792154cb2cab341263b18a2bfd023fea Mon Sep 17 00:00:00 2001 From: codex Date: Sat, 1 Aug 2026 22:35:59 -0300 Subject: [PATCH] test(game-mode): cover Ollama handoff client --- tests/test_game_mode.py | 42 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/test_game_mode.py b/tests/test_game_mode.py index a54f3ae..4ac03ef 100644 --- a/tests/test_game_mode.py +++ b/tests/test_game_mode.py @@ -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