File size: 2,025 Bytes
0cb452d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Full HTTP flow test: reset -> step -> step -> step -> state -> grader score."""
import httpx

BASE = "http://127.0.0.1:8000"

# Reset
r = httpx.post(f"{BASE}/reset", json={"task_name": "basic-triage"})
assert r.status_code == 200, f"Reset failed: {r.status_code}"
data = r.json()
obs = data.get("observation", data)
pid = obs.get("current_patient", {}).get("patient_id", "?")
print(f"1. Reset OK: status={r.status_code}, patient={pid}")

# Step 1: assign P001 as IMMEDIATE (correct)
r = httpx.post(f"{BASE}/step", json={"action": {
    "action_type": "assign_priority",
    "patient_id": "P001",
    "priority_level": "immediate"
}})
assert r.status_code == 200, f"Step 1 failed: {r.status_code} {r.text}"
data = r.json()
print(f"2. Step 1: reward={data.get('reward')}, done={data.get('done')}")

# Step 2: assign P002 as NON_URGENT (correct)
r = httpx.post(f"{BASE}/step", json={"action": {
    "action_type": "assign_priority",
    "patient_id": "P002",
    "priority_level": "non_urgent"
}})
assert r.status_code == 200, f"Step 2 failed: {r.status_code}"
data = r.json()
print(f"3. Step 2: reward={data.get('reward')}, done={data.get('done')}")

# Step 3: assign P003 as URGENT (correct)
r = httpx.post(f"{BASE}/step", json={"action": {
    "action_type": "assign_priority",
    "patient_id": "P003",
    "priority_level": "urgent"
}})
assert r.status_code == 200, f"Step 3 failed: {r.status_code}"
data = r.json()
print(f"4. Step 3: reward={data.get('reward')}, done={data.get('done')}")
assert data.get("done") == True, "Should be done after all patients assigned"

# State
r = httpx.get(f"{BASE}/state")
assert r.status_code == 200, f"State failed: {r.status_code}"
state = r.json()
print(f"5. State: assignments={state.get('assignments')}")

# Verify via grader
import sys; sys.path.insert(0, ".")
from triage_flow.graders import grade_task
score = grade_task("basic-triage", state)
print(f"6. Grader score: {score}")
assert score == 1.0, f"Expected 1.0, got {score}"

print("\n=== FULL HTTP FLOW TEST PASSED ===")