test_fuse_intent.py
2.56 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
68
69
70
71
72
73
74
"""End-to-end tests for fuse_intent with mock LLM."""
import pytest
from intent_fusion import IntentRouter, fuse_intent, FusionVerdict, invalidate_cache
from tests.conftest import MockLLM, SAMPLE_ENTRIES
@pytest.fixture(autouse=True)
def _clean_singleton():
invalidate_cache()
yield
invalidate_cache()
class TestIntentRouter:
"""Tests using the class-based IntentRouter API."""
async def test_clear_direct_query(self, sample_entries, mock_llm):
router = IntentRouter(sample_entries)
result = await router.fuse("where is my order", mock_llm)
assert result.verdict == FusionVerdict.CLEAR
assert result.top is not None
assert result.top.name == "query_order_status"
assert result.total_ms > 0
async def test_small_talk_verdict(self, sample_entries):
"""Small talk should not get a confident CLEAR on a real intent."""
llm = MockLLM()
router = IntentRouter(sample_entries)
result = await router.fuse("hello there", llm)
assert result.verdict is not None
assert result.total_ms > 0
async def test_active_channels_both(self, sample_entries, mock_llm):
router = IntentRouter(sample_entries)
result = await router.fuse("where is my order", mock_llm)
assert result.degraded is False
assert "embedding" in result.active_channels
assert "tree" in result.active_channels
async def test_timing_fields_populated(self, sample_entries, mock_llm):
router = IntentRouter(sample_entries)
result = await router.fuse("cancel my order", mock_llm)
assert result.emb_ms >= 0
assert result.tree_ms >= 0
assert result.total_ms >= 0
async def test_candidates_list_populated(self, sample_entries, mock_llm):
router = IntentRouter(sample_entries)
result = await router.fuse("where is my order", mock_llm)
assert len(result.candidates) > 0
class TestFuseIntentFunction:
"""Tests using the convenience function API."""
async def test_function_api_works(self, sample_entries, mock_llm):
result = await fuse_intent("where is my order", sample_entries, mock_llm)
assert result.verdict in (FusionVerdict.CLEAR, FusionVerdict.AMBIGUOUS)
assert result.top is not None
async def test_function_api_reuses_router(self, sample_entries, mock_llm):
r1 = await fuse_intent("where is my order", sample_entries, mock_llm)
r2 = await fuse_intent("cancel my order", sample_entries, mock_llm)
assert r1.top is not None
assert r2.top is not None