72 lines
1.9 KiB
Python
72 lines
1.9 KiB
Python
from fastapi.testclient import TestClient
|
|
|
|
from ai_orchestrator.main import app
|
|
|
|
|
|
def test_health_endpoint_returns_ok() -> None:
|
|
client = TestClient(app)
|
|
|
|
response = client.get("/health")
|
|
|
|
assert response.status_code == 200
|
|
assert response.json() == {"status": "ok"}
|
|
|
|
|
|
def test_post_tasks_creates_planned_task() -> None:
|
|
client = TestClient(app)
|
|
|
|
response = client.post(
|
|
"/tasks",
|
|
json={
|
|
"project_id": "default",
|
|
"goal": "Prepare a plan",
|
|
"inputs": {"source": "test"},
|
|
"execution_mode": "agent_graph",
|
|
},
|
|
)
|
|
|
|
payload = response.json()
|
|
|
|
assert response.status_code == 200
|
|
assert payload["status"] == "running"
|
|
assert payload["progress"]["total"] == 2
|
|
|
|
|
|
def test_cancel_endpoint_marks_task_cancelled() -> None:
|
|
client = TestClient(app)
|
|
|
|
created = client.post(
|
|
"/tasks",
|
|
json={
|
|
"project_id": "default",
|
|
"goal": "Cancel me",
|
|
"inputs": {},
|
|
"execution_mode": "agent_graph",
|
|
},
|
|
).json()
|
|
response = client.post(f"/tasks/{created['task_id']}/cancel", json={"reason": "stop"})
|
|
|
|
assert response.status_code == 200
|
|
assert response.json()["status"] == "cancelled"
|
|
|
|
|
|
def test_worker_registration_is_exposed_via_list_endpoint() -> None:
|
|
client = TestClient(app)
|
|
|
|
registration = client.post(
|
|
"/workers/register",
|
|
json={
|
|
"worker_id": "worker_home_pc",
|
|
"name": "Home PC",
|
|
"capabilities": ["file.read", "command.run"],
|
|
"version": "0.1.0",
|
|
"machine": "DESKTOP-1",
|
|
"os": "windows",
|
|
},
|
|
)
|
|
listing = client.get("/workers")
|
|
|
|
assert registration.status_code == 200
|
|
assert listing.status_code == 200
|
|
assert any(worker["worker_id"] == "worker_home_pc" for worker in listing.json()["workers"])
|