File size: 3,671 Bytes
6c7a6ef
 
adb0674
6c7a6ef
adb0674
 
 
6c7a6ef
 
adb0674
 
 
6c7a6ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
adb0674
 
 
6c7a6ef
 
 
 
 
 
 
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
"""Smoke tests for Enterprise Support Ticket Triage environment."""

from env.support_env import EnterpriseSupportTicketTriageEnv
from env.models import Action, ActionType, PriorityLevel
from env.tasks import TASK_ORDER


def test_all_tasks_reset():
    """Verify all 9 tasks can be reset and produce valid observations."""
    env = EnterpriseSupportTicketTriageEnv()
    for task_id in TASK_ORDER:
        obs = env.reset(task_id=task_id)
        assert obs.task_id == task_id, f"Task ID mismatch: {obs.task_id} != {task_id}"
        assert obs.step_count == 0
        assert obs.max_steps_remaining > 0
        assert obs.current_status.value == "open"
        assert obs.subject, f"Empty subject for {task_id}"
        assert obs.customer_message, f"Empty customer message for {task_id}"
        print(f"βœ“ {task_id}: ticket={obs.ticket_id} status={obs.current_status.value}")
    env.close()


def test_step_produces_reward():
    """Verify step() returns valid reward structure."""
    env = EnterpriseSupportTicketTriageEnv()
    env.reset(task_id="easy_billing_duplicate_charge")

    action = Action(
        action_type=ActionType.CLASSIFY,
        message="Billing issue - duplicate charge",
        tags=["billing"],
    )
    obs, reward, done, info = env.step(action)
    assert obs.step_count == 1
    assert isinstance(reward.value, float)
    assert -1.0 <= reward.value <= 1.0
    assert not done
    print(f"βœ“ Step reward: {reward.value:.3f} ({reward.reason})")
    env.close()


def test_variant_system():
    """Verify stochastic variants produce different observations."""
    env = EnterpriseSupportTicketTriageEnv()
    obs1 = env.reset(task_id="easy_billing_duplicate_charge", seed=42)
    obs2 = env.reset(task_id="easy_billing_duplicate_charge", seed=43)
    assert obs1.customer_message != obs2.customer_message, "Variants should differ"
    print(f"βœ“ Variant 1: {obs1.customer_message[:60]}...")
    print(f"βœ“ Variant 2: {obs2.customer_message[:60]}...")
    env.close()


def test_customer_simulation():
    """Verify customer responds after request_info with diagnostic fields."""
    env = EnterpriseSupportTicketTriageEnv()
    env.reset(task_id="medium_security_suspicious_login")

    action = Action(
        action_type=ActionType.REQUEST_INFO,
        message="Please share the last login time and MFA status.",
        tags=["last_known_login_time", "mfa_status"],
    )
    obs, _, _, _ = env.step(action)

    # Should have: initial customer message + agent request + customer reply = 3 turns
    assert len(obs.conversation_history) >= 3, (
        f"Expected customer simulation reply, got {len(obs.conversation_history)} turns"
    )
    last_turn = obs.conversation_history[-1]
    assert last_turn.speaker == "customer", f"Last speaker should be customer, got {last_turn.speaker}"
    print(f"βœ“ Customer replied: {last_turn.message[:80]}...")
    env.close()


def test_close_method():
    """Verify close() doesn't error."""
    env = EnterpriseSupportTicketTriageEnv()
    env.reset(task_id="easy_billing_duplicate_charge")
    env.close()
    print("βœ“ close() succeeded")


def test_all_task_ids():
    """Verify get_task_ids() returns all 9 tasks."""
    env = EnterpriseSupportTicketTriageEnv()
    task_ids = env.get_task_ids()
    assert len(task_ids) == 9, f"Expected 9 tasks, got {len(task_ids)}"
    print(f"βœ“ {len(task_ids)} tasks available: {task_ids}")
    env.close()


if __name__ == "__main__":
    test_all_tasks_reset()
    test_step_produces_reward()
    test_variant_system()
    test_customer_simulation()
    test_close_method()
    test_all_task_ids()
    print("\nβœ… All tests passed!")