DevOps_Debugger / tests /test_api_openenv.py
printf-sourav's picture
Initial commit
27cdb3e
Raw
History Blame
1.62 kB
"""Tests for OpenEnv-style API session endpoints."""
from fastapi.testclient import TestClient
from api.main import app
client = TestClient(app)
def test_openenv_reset_returns_session_and_observation():
response = client.post(
"/reset",
json={"scenario_id": "missing_flask", "max_steps": 3},
)
assert response.status_code == 200
payload = response.json()
assert "session_id" in payload
assert "observation" in payload
assert "info" in payload
assert payload["observation"]["scenario_id"] == "missing_flask"
close_resp = client.post("/close", json={"session_id": payload["session_id"]})
assert close_resp.status_code == 200
assert close_resp.json()["closed"] is True
def test_openenv_step_unknown_session_returns_404():
response = client.post(
"/step",
json={
"session_id": "does-not-exist",
"action": {"command": "echo hello"},
},
)
assert response.status_code == 404
def test_openenv_session_auto_closes_when_done():
reset_resp = client.post(
"/reset",
json={"scenario_id": "missing_flask", "max_steps": 1},
)
assert reset_resp.status_code == 200
session_id = reset_resp.json()["session_id"]
step_resp = client.post(
"/step",
json={
"session_id": session_id,
"action": {"command": "echo noop"},
},
)
assert step_resp.status_code == 200
assert step_resp.json()["done"] is True
missing_resp = client.post("/close", json={"session_id": session_id})
assert missing_resp.status_code == 404