Skip to content
This repository was archived by the owner on Oct 21, 2025. It is now read-only.

Commit 2e2eb08

Browse files
committed
Type fixes
1 parent c978b7a commit 2e2eb08

File tree

3 files changed

+41
-23
lines changed

3 files changed

+41
-23
lines changed

src/cli/pentest.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,14 @@ def main(
213213
click.echo(f"✅ {backend_type} model {client.get_model_name()} ready")
214214

215215
# Check if backend is busy before starting tests (Ollama only)
216-
if not skip_busy_check and hasattr(client, "check_status"):
216+
if (
217+
not skip_busy_check
218+
and hasattr(client, "check_status")
219+
and callable(getattr(client, "check_status", None))
220+
):
217221
click.echo(f"🔍 Checking {backend_type} status...")
218222
try:
219-
status = client.check_status()
223+
status = client.check_status() # type: ignore
220224

221225
if status.is_busy:
222226
click.echo(f"⚠️ WARNING: {backend_type} appears busy!")

src/utils/model_client.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@
22

33
import subprocess
44
import time
5-
from typing import Any
5+
from typing import TYPE_CHECKING, Any, Union
66

77
import requests
88
from requests.exceptions import Timeout
99
from src.models import ModelResponse, OllamaStatus
10-
from src.utils.llm_backend import create_backend
1110
from src.utils.settings_manager import settings_manager
1211

12+
if TYPE_CHECKING:
13+
from src.utils.llm_backend import LLMBackend
1314

14-
def get_client(seed: int | None = None) -> object:
15+
16+
def get_client(seed: int | None = None) -> Union["LLMBackend", "OllamaClient"]:
1517
"""Factory function to get the configured LLM client."""
18+
from src.utils.llm_backend import create_backend
19+
1620
try:
1721
settings = settings_manager.load_settings()
1822
return create_backend(settings, seed)
@@ -313,6 +317,18 @@ def get_backend_type(self) -> str:
313317
"""Get the backend type identifier (for compatibility)."""
314318
return "Ollama"
315319

320+
def get_model_name(self) -> str:
321+
"""Get the model name (for compatibility)."""
322+
return self.model
323+
324+
def is_available(self) -> bool:
325+
"""Check if model is available (for compatibility)."""
326+
return self.is_model_available()
327+
328+
def check_status(self) -> OllamaStatus:
329+
"""Check Ollama status (for compatibility)."""
330+
return self.check_ollama_status()
331+
316332

317333
def test_connection() -> bool | None:
318334
"""Test Ollama connection and model availability"""

tests/test_model_client.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,56 +21,54 @@ def test_default_initialization(self) -> None:
2121
client = OllamaClient()
2222
assert client.base_url == "http://localhost:11434"
2323
assert client.model == "gpt-oss:20b"
24-
assert client.session is not None
2524

2625
def test_custom_initialization(self) -> None:
2726
"""Test client accepts custom configuration"""
2827
client = OllamaClient(host="custom.host", port=8080, model="custom:model")
2928
assert client.base_url == "http://custom.host:8080"
3029
assert client.model == "custom:model"
3130

32-
def test_session_persistence(self) -> None:
33-
"""Test that session object persists across calls"""
34-
client = OllamaClient()
35-
session1 = client.session
36-
session2 = client.session
37-
assert session1 is session2
31+
def test_seed_initialization(self) -> None:
32+
"""Test that seed parameter is properly stored"""
33+
client = OllamaClient(seed=42)
34+
assert client.seed == 42
35+
36+
client_no_seed = OllamaClient()
37+
assert client_no_seed.seed is None
3838

3939

4040
class TestOllamaClientModelAvailability:
4141
"""Test model availability checking"""
4242

43-
@patch('src.utils.model_client.requests.Session')
44-
def test_model_available(self, mock_session_class) -> None:
43+
@patch('src.utils.model_client.requests.get')
44+
def test_model_available(self, mock_get) -> None:
4545
"""Test when model is available"""
46-
mock_session = MagicMock()
4746
mock_response = MagicMock()
4847
mock_response.json.return_value = {
4948
"models": [
5049
{"name": "gpt-oss:20b"},
5150
{"name": "other:model"}
5251
]
5352
}
54-
mock_session.get.return_value = mock_response
55-
mock_session_class.return_value = mock_session
53+
mock_response.raise_for_status.return_value = None
54+
mock_get.return_value = mock_response
5655

5756
client = OllamaClient()
5857
assert client.is_model_available() is True
59-
mock_session.get.assert_called_once_with(
58+
mock_get.assert_called_once_with(
6059
"http://localhost:11434/api/tags",
6160
timeout=180
6261
)
6362

64-
@patch('src.utils.model_client.requests.Session')
65-
def test_model_not_available(self, mock_session_class) -> None:
63+
@patch('src.utils.model_client.requests.get')
64+
def test_model_not_available(self, mock_get) -> None:
6665
"""Test when model is not available"""
67-
mock_session = MagicMock()
6866
mock_response = MagicMock()
6967
mock_response.json.return_value = {
7068
"models": [{"name": "other:model"}]
7169
}
72-
mock_session.get.return_value = mock_response
73-
mock_session_class.return_value = mock_session
70+
mock_response.raise_for_status.return_value = None
71+
mock_get.return_value = mock_response
7472

7573
client = OllamaClient()
7674
assert client.is_model_available() is False

0 commit comments

Comments
 (0)