meta_hackathon / tests /test_environment.py
Neetu143's picture
Upload support triage environment
cfa210f verified
Raw History Blame Contribute Delete
4.4 kB
from support_triage_env.environment import SupportTriageCoreEnvironment
from support_triage_env.models import TriageAction
from support_triage_env.server.environment import SupportTriageEnvironment
def test_reset_selects_requested_task():
env = SupportTriageEnvironment()
observation = env.reset(task_id="shipping_damaged_replacement")
assert observation.task_id == "shipping_damaged_replacement"
assert observation.case_title == "Damaged replacement request still needs evidence"
assert observation.workspace.priority is None
assert observation.steps_remaining == 14
assert "lookup_order(value)" in observation.available_actions
assert hasattr(observation, "investigation_requirements")
assert not hasattr(observation, "reply_requirements")
assert not hasattr(observation, "score_breakdown")
assert not hasattr(observation, "missing_items")
def test_seed_selects_alternate_variant():
env = SupportTriageEnvironment()
observation = env.reset(task_id="billing_duplicate_charge", seed=1)
assert observation.ticket.order_id == "MH-5188"
assert observation.case_title == "Perceived duplicate charge caused by an authorization hold"
assert observation.allowed_values["lookup_policy"] == ["billing_charge_anomaly"]
def test_perfect_billing_run_reaches_full_score():
env = SupportTriageEnvironment()
env.reset(task_id="billing_duplicate_charge")
env.step(TriageAction(action_type="lookup_policy", value="billing_charge_anomaly"))
env.step(TriageAction(action_type="lookup_order", value="MH-4821"))
env.step(TriageAction(action_type="set_priority", value="high"))
env.step(TriageAction(action_type="set_queue", value="billing"))
env.step(TriageAction(action_type="set_status", value="pending_refund_review"))
env.step(TriageAction(action_type="add_tag", value="billing"))
env.step(TriageAction(action_type="add_tag", value="refund"))
env.step(TriageAction(action_type="add_tag", value="duplicate_charge"))
env.step(
TriageAction(
action_type="add_internal_note",
value=(
"The ledger shows two settled charges for the same renewal. "
"Route the case into refund review while the subscription remains active."
),
)
)
env.step(
TriageAction(
action_type="draft_reply",
value=(
"I am sorry about the duplicate charge. We are moving this into refund review now, "
"and you will receive an update within 24 hours. Your subscription remains active."
),
)
)
final_observation = env.step(TriageAction(action_type="submit"))
assert final_observation.done is True
assert 0.98 < env.state.completion_score < 1.0
assert env.state.submitted is True
def test_invalid_lookup_is_penalized():
env = SupportTriageEnvironment()
env.reset(task_id="billing_duplicate_charge")
observation = env.step(TriageAction(action_type="lookup_policy", value="wrong_policy"))
assert observation.reward < 0
assert observation.last_action_error == "no policy record found for 'wrong_policy'"
def test_core_step_returns_typed_reward_and_investigation_log():
env = SupportTriageCoreEnvironment()
observation = env.reset(task_id="billing_duplicate_charge")
result = env.step(TriageAction(action_type="lookup_policy", value="billing_charge_anomaly"))
assert observation.task_id == "billing_duplicate_charge"
assert result.observation.investigation_log[0].source == "policy"
assert result.reward.value > 0
assert result.reward.completion_score > 0
assert result.done is False
assert result.info.step_count == 1
assert result.info.last_action_error is None
def test_core_state_method_returns_current_state():
env = SupportTriageCoreEnvironment()
env.reset(task_id="shipping_damaged_replacement")
env.step(TriageAction(action_type="lookup_policy", value="damage_replacement"))
env.step(TriageAction(action_type="set_queue", value="logistics"))
state = env.state()
assert state.task_id == "shipping_damaged_replacement"
assert state.case_title == "Damaged replacement request still needs evidence"
assert state.workspace.queue == "logistics"
assert state.step_count == 2
assert state.investigation_log[0].source == "policy"