from fastapi.testclient import TestClient from env.environment import IncidentResponseEnv from env.models import Action from server.app import app from tasks.easy_task import EasyTask def test_grade_endpoint_scores_history() -> None: client = TestClient(app) env = IncidentResponseEnv(EasyTask()) env.reset() env.step(Action(action_type="query_metrics", params={"service": "api-gateway"})) env.step( Action( action_type="update_config", params={ "service": "api-gateway", "key": "upstream_url", "value": "http://backend:8080", }, ) ) final = env.step(Action(action_type="mark_resolved", params={})) payload = { "task_id": "single-config-fault", "action_history": list(final.observation.action_history), "final_state": env.state(), } response = client.post("/grade", json=payload) assert response.status_code == 200 body = response.json() assert body["task_id"] == "single-config-fault" assert 0.0 < body["score"] < 1.0