Skip to content

Commit 4bab22f

Browse files
committed
Update v0.0.1
1 parent fb84e15 commit 4bab22f

1 file changed

Lines changed: 36 additions & 13 deletions

File tree

tests/test_agent.py

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,59 @@
11
import pytest
2+
23
from agentlow.agent import OllamaAgent
34
from agentlow.tools import ToolExecutor
4-
from pathlib import Path
5+
56

67
@pytest.fixture
7-
def agent(tmp_path):
8-
return OllamaAgent(
9-
model="qwen2.5:7b", # Asume Ollama corriendo en tests
8+
def agent(tmp_path, monkeypatch):
9+
"""Agente en modo unit-test.
10+
11+
En CI normalmente NO hay un servidor Ollama ejecutándose.
12+
Para que los tests sean deterministas y no dependan de red/servicios,
13+
mockeamos la llamada a Ollama devolviendo un "echo" del prompt.
14+
"""
15+
16+
a = OllamaAgent(
17+
model="qwen2.5:7b",
1018
work_dir=str(tmp_path),
11-
temperature=0.0
19+
temperature=0.0,
1220
)
1321

22+
def _fake_call_ollama(messages, tools=None):
23+
last_user = ""
24+
for m in reversed(messages):
25+
if m.get("role") == "user":
26+
last_user = str(m.get("content", ""))
27+
break
28+
29+
original = last_user.split("\n\n", 1)[1] if "\n\n" in last_user else last_user
30+
return {"message": {"content": f"Echo: {original}"}}
31+
32+
monkeypatch.setattr(a, "_call_ollama", _fake_call_ollama)
33+
return a
34+
35+
1436
def test_agent_init(agent):
1537
assert agent.model == "qwen2.5:7b"
1638
assert len(agent.messages) == 0
1739

40+
1841
def test_tool_executor(tmp_path):
1942
executor = ToolExecutor(work_dir=str(tmp_path))
20-
# Test read/write
2143
write_result = executor.execute_tool("write_file", {"path": "test.txt", "content": "Hello"})
2244
assert write_result["success"]
2345
read_result = executor.execute_tool("read_file", {"path": "test.txt"})
2446
assert read_result["content"] == "Hello"
2547

48+
2649
def test_agent_run_simple(agent):
2750
response = agent.run("Echo test", verbose=False)
28-
assert "test" in response.lower() # Asume modelo responde echo
51+
assert "test" in response.lower()
2952

30-
def test_cache(agent):
31-
# Asume caché implementado
32-
first = agent.run("Lista archivos")
33-
second = agent.run("Lista archivos")
34-
assert first == second # Con caché hit
3553

36-
# Más tests para herramientas Pro...
54+
def test_cache(agent):
55+
# Si luego implementas caché real, este test sigue válido
56+
# mientras el modelo/mock sea determinista.
57+
first = agent.run("Lista archivos", verbose=False)
58+
second = agent.run("Lista archivos", verbose=False)
59+
assert first == second

0 commit comments

Comments
 (0)