File size: 2,824 Bytes
cf796c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8d73fdc
 
cf796c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pytest
from src.nodes.entity_extractor import extract_entities
from src.state import init_state

def test_extract_order_id_32_char():
    """Test extraction of 32-character hex order ID"""
    state = init_state("Where is order ef4e1688abcd1234ef4e1688abcd1234?")
    result = extract_entities(state)
    assert result["last_order_id"] == "ef4e1688abcd1234ef4e1688abcd1234"

def test_extract_short_order_id():
    """Test extraction of short order ID format"""
    state = init_state("Check status of ORD-12345")
    result = extract_entities(state)
    assert result["last_order_id"] == "ORD-12345"

def test_pronoun_resolution_that():
    """Test pronoun 'that' resolves to previous order ID"""
    state = init_state("What about that?")
    state["last_order_id"] = "previous-order-123"
    result = extract_entities(state)
    assert result["last_order_id"] == "previous-order-123"
    assert any("pronoun" in log.lower() for log in result["error_log"])

def test_pronoun_resolution_it():
    """Test pronoun 'it' resolves to session context"""
    state = init_state("When will it arrive?")
    state["session_context"] = {"order_id": "session-order-456"}
    result = extract_entities(state)
    assert result["last_order_id"] == "session-order-456"

def test_no_pronoun_without_context():
    """Test pronoun without context doesn't create false positive"""
    state = init_state("What is that?")
    result = extract_entities(state)
    assert result.get("last_order_id") is None

def test_extract_category_electronics():
    """Test category extraction for electronics"""
    state = init_state("Show me electronics products")
    result = extract_entities(state)
    assert result["last_category"] == "electronics"

def test_extract_category_computers():
    """Test category extraction for computers"""
    state = init_state("I need a new computer")
    result = extract_entities(state)
    # Should match 'computer' which maps to computers category
    assert result["last_category"] in ["computer", "computers"]

def test_no_category_in_generic_query():
    """Test no category extracted from generic query"""
    state = init_state("Where is my order?")
    result = extract_entities(state)
    assert result.get("last_category") is None

def test_explicit_order_id_overrides_pronoun():
    """Test explicit order ID takes precedence over pronoun"""
    state = init_state("Check that order: abc123def456abc123def456abc123de")
    state["last_order_id"] = "old-order-999"
    result = extract_entities(state)
    assert result["last_order_id"] == "abc123def456abc123def456abc123de"

def test_case_insensitive_order_id():
    """Test order ID extraction is case insensitive"""
    state = init_state("ORDER-ABCD1234")
    result = extract_entities(state)
    assert result["last_order_id"] is not None