test_api.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. from fastapi.testclient import TestClient
  2. from app.main import app
  3. client = TestClient(app)
  4. def test_health_declares_real_persisted_mode() -> None:
  5. response = client.get("/api/health")
  6. assert response.status_code == 200
  7. assert response.json()["data_mode"] == "persisted-real-run"
  8. def test_real_e2e_runs_900029_and_900031_are_discoverable() -> None:
  9. response = client.get("/api/runs")
  10. assert response.status_code == 200
  11. by_id = {run["script_build_id"]: run for run in response.json()}
  12. assert {900029, 900031} <= set(by_id)
  13. assert by_id[900029]["task_count"] >= 11
  14. assert by_id[900031]["task_count"] >= 8
  15. assert by_id[900029]["planner_turn_count"] > 10
  16. assert by_id[900031]["planner_turn_count"] > 10
  17. def test_execution_projects_global_planner_and_dynamic_task_tree() -> None:
  18. for build_id in (900029, 900031):
  19. response = client.get(f"/api/runs/{build_id}/execution")
  20. assert response.status_code == 200
  21. body = response.json()
  22. assert body["data_mode"] == "persisted-real-run"
  23. assert len([task for task in body["tasks"] if task["parent_task_id"] is None]) == 1
  24. assert any(task["task_kind"] == "direction" for task in body["tasks"])
  25. assert any(task["task_kind"] == "compose" for task in body["tasks"])
  26. assert {turn["tool_name"] for turn in body["planner_turns"]} >= {
  27. "inspect_script_plan",
  28. "plan_script_tasks",
  29. "dispatch_script_tasks",
  30. "decide_script_task",
  31. }
  32. visible_counts = [len(turn["visible_task_ids"]) for turn in body["planner_turns"]]
  33. assert visible_counts == sorted(visible_counts)
  34. assert visible_counts[-1] == len(body["tasks"])
  35. def test_task_detail_exposes_lifecycle_worker_loop_and_data_proof() -> None:
  36. execution = client.get("/api/runs/900029/execution").json()
  37. paragraph = next(task for task in execution["tasks"] if task["task_kind"] == "paragraph")
  38. response = client.get(f"/api/runs/900029/tasks/{paragraph['task_id']}")
  39. assert response.status_code == 200
  40. body = response.json()
  41. assert {event["kind"] for event in body["lifecycle"]} >= {"task", "attempt", "validation", "decision"}
  42. assert body["attempts"]
  43. steps = body["attempts"][0]["steps"]
  44. assert any(step["step_kind"] == "tool_call" for step in steps)
  45. assert body["attempts"][0]["prompt"].startswith("Produce one independently testable Paragraph")
  46. assert body["data_usage"]["confirmed_reads"]
  47. assert body["data_usage"]["produced_outputs"]
  48. def test_unknown_run_and_task_are_404() -> None:
  49. assert client.get("/api/runs/999999/execution").status_code == 404
  50. assert client.get("/api/runs/900029/tasks/missing").status_code == 404