forked from johnny603/lux
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_agent_hints.py
More file actions
67 lines (56 loc) · 1.93 KB
/
Copy pathtest_agent_hints.py
File metadata and controls
67 lines (56 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import sys
from types import SimpleNamespace
import agent
import storage
def test_hint_generation_falls_back_between_models(monkeypatch):
calls = []
def fake_chat(model, messages):
calls.append(model)
if model == "primary":
raise RuntimeError("model unavailable")
return SimpleNamespace(
message=SimpleNamespace(
content=(
"Use a smaller step. Avoid revealing the answer directly. And check the tags."
)
)
)
monkeypatch.setenv("LUX_OLLAMA_MODEL", "primary")
monkeypatch.setenv("LUX_OLLAMA_MODELS", "fallback")
monkeypatch.setitem(sys.modules, "ollama", SimpleNamespace(chat=fake_chat))
hint = agent.ask_hint_via_ollama(
{
"id": "1",
"title": "Test",
"description": "Desc",
"category": "Linux",
"difficulty": "easy",
"tags": ["shell"],
},
state=storage.default_state(),
)
assert calls == ["primary", "fallback"]
assert hint.startswith("Use a smaller step")
assert "answer" in hint.lower()
def test_hint_generation_raises_when_all_models_fail(monkeypatch):
def fake_chat(model, messages):
raise RuntimeError(f"{model} down")
monkeypatch.delenv("LUX_OLLAMA_MODEL", raising=False)
monkeypatch.delenv("LUX_OLLAMA_MODELS", raising=False)
monkeypatch.setitem(sys.modules, "ollama", SimpleNamespace(chat=fake_chat))
try:
agent.ask_hint_via_ollama(
{
"id": "1",
"title": "Test",
"description": "Desc",
"category": "Linux",
"difficulty": "easy",
"tags": [],
},
state=storage.default_state(),
)
except RuntimeError as exc:
assert "Unable to generate a hint" in str(exc)
else:
raise AssertionError("expected RuntimeError")