AIMLxDIV commited on
Commit
c34e3ac
·
1 Parent(s): 0155d44

Add tests/test_api.py

Browse files
Files changed (1) hide show
  1. tests/test_api.py +62 -0
tests/test_api.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+ from fastapi.testclient import TestClient
3
+ from app import app
4
+ from codereview_env.models import TaskId, ActionType, Category, Severity, Verdict
5
+
6
+ def test_api_health():
7
+ client = TestClient(app)
8
+ response = client.get("/health")
9
+ assert response.status_code == 200
10
+ assert response.json()["status"] == "ok"
11
+ assert response.json()["env_ready"] is True
12
+
13
+ def test_api_workflow():
14
+ client = TestClient(app)
15
+
16
+ # 1. Reset
17
+ reset_resp = client.post("/reset", json={"task_id": "bug_detection", "seed": 1})
18
+ assert reset_resp.status_code == 200
19
+ data = reset_resp.json()
20
+ episode_id = data["episode_id"]
21
+ assert "observation" in data["result"]
22
+
23
+ # 2. Step
24
+ action = {
25
+ "action_type": "comment",
26
+ "body": "Starting review",
27
+ }
28
+ step_resp = client.post(f"/step/{episode_id}", json=action)
29
+ assert step_resp.status_code == 200
30
+ assert "observation" in step_resp.json()
31
+
32
+ # 3. Get Result
33
+ result_resp = client.get(f"/result/{episode_id}")
34
+ assert result_resp.status_code == 200
35
+ assert result_resp.json()["final_score"] >= 0
36
+
37
+ def test_api_leaderboard():
38
+ client = TestClient(app)
39
+ # Submit a score
40
+ sub = {
41
+ "agent_name": "test_agent",
42
+ "task_id": "bug_detection",
43
+ "score": 0.95,
44
+ "seed": 42
45
+ }
46
+ resp = client.post("/submit", json=sub)
47
+ assert resp.status_code == 200
48
+ assert resp.json()["status"] == "submitted"
49
+
50
+ # Check leaderboard
51
+ lb_resp = client.get("/leaderboard")
52
+ assert lb_resp.status_code == 200
53
+ assert len(lb_resp.json()["bug_detection"]) > 0
54
+ assert lb_resp.json()["bug_detection"][0]["agent_name"] == "test_agent"
55
+
56
+ def test_api_invalid_episode():
57
+ client = TestClient(app)
58
+ response = client.post("/step/nonexistent-id", json={
59
+ "action_type": "comment",
60
+ "body": "hello"
61
+ })
62
+ assert response.status_code == 404