File size: 1,634 Bytes
0e23a69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import sys

# add envs to path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "envs")))

from board_sim_env.server.app import app
from board_sim_env.models import BoardSimAction
from fastapi.testclient import TestClient

client = TestClient(app)

def test_api():
    print("Testing /reset endpoint...")
    response = client.post("/reset")
    assert response.status_code == 200, f"Reset failed: {response.text}"
    reset_data = response.json()
    print("/reset succeeded!")
    
    print("Testing /schema endpoint...")
    schema_response = client.get("/schema")
    assert schema_response.status_code == 200, f"Schema failed: {schema_response.text}"
    print("/schema succeeded!")
    
    print("Testing /state endpoint...")
    state_response = client.get("/state")
    assert state_response.status_code == 200, f"State failed: {state_response.text}"
    print("/state succeeded!")

    print("Testing /step endpoint...")
    # Get options from reset observation
    obs = reset_data.get("observation", {})
    options = obs.get("options", [])
    if not options:
        print("Warning: No options found in observation.")
        return
        
    action_payload = {
        "action": {
            "decision": options[0],
            "coalition_pitch": "Let's align on this for maximum profit!"
        }
    }
    
    step_response = client.post("/step", json=action_payload)
    assert step_response.status_code == 200, f"Step failed: {step_response.text}"
    print("/step succeeded!")
    print("All endpoints passed successfully!")

if __name__ == "__main__":
    test_api()