- Update COVERAGE.md to reflect completed features (now ~60%) - Update main README with features and tools list - Update CLI README with streaming options - Expand API tests from 5 to 11 (add stream endpoint tests) - Add 14 security tests for path traversal, command injection - Total tests: 109 (up from 88) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
163 lines
4.9 KiB
Python
163 lines
4.9 KiB
Python
"""
|
|
Tests for agent REST API endpoints.
|
|
"""
|
|
import pytest
|
|
|
|
|
|
class TestAgentListEndpoint:
|
|
"""Tests for GET /agents/ endpoint."""
|
|
|
|
@pytest.mark.anyio
|
|
async def test_list_agents(self, auth_client):
|
|
"""Test listing available agents."""
|
|
response = await auth_client.get("/agents/")
|
|
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert "agents" in data
|
|
assert len(data["agents"]) >= 1
|
|
|
|
# Check explore agent is present
|
|
agent_names = [a["name"] for a in data["agents"]]
|
|
assert "explore" in agent_names
|
|
|
|
@pytest.mark.anyio
|
|
async def test_list_agents_returns_descriptions(self, auth_client):
|
|
"""Test that agent list includes descriptions."""
|
|
response = await auth_client.get("/agents/")
|
|
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
for agent in data["agents"]:
|
|
assert "name" in agent
|
|
assert "description" in agent
|
|
assert len(agent["description"]) > 0
|
|
|
|
|
|
class TestAgentInfoEndpoint:
|
|
"""Tests for GET /agents/{agent_type} endpoint."""
|
|
|
|
@pytest.mark.anyio
|
|
async def test_get_explore_agent_info(self, auth_client):
|
|
"""Test getting explore agent info."""
|
|
response = await auth_client.get("/agents/explore")
|
|
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["name"] == "explore"
|
|
assert "description" in data
|
|
|
|
@pytest.mark.anyio
|
|
async def test_get_unknown_agent(self, auth_client):
|
|
"""Test getting info for unknown agent."""
|
|
response = await auth_client.get("/agents/nonexistent")
|
|
|
|
assert response.status_code == 404
|
|
|
|
@pytest.mark.anyio
|
|
async def test_get_agent_empty_name(self, auth_client):
|
|
"""Test getting agent with empty name."""
|
|
response = await auth_client.get("/agents/")
|
|
# This is the list endpoint, should return 200
|
|
assert response.status_code == 200
|
|
|
|
|
|
class TestAgentRunEndpoint:
|
|
"""Tests for POST /agents/run endpoint."""
|
|
|
|
@pytest.mark.anyio
|
|
async def test_run_with_unknown_agent(self, auth_client):
|
|
"""Test running unknown agent type."""
|
|
response = await auth_client.post(
|
|
"/agents/run",
|
|
json={
|
|
"prompt": "test",
|
|
"agent_type": "nonexistent",
|
|
"working_dir": "."
|
|
}
|
|
)
|
|
|
|
assert response.status_code == 400
|
|
assert "Unknown agent" in response.json()["detail"]
|
|
|
|
@pytest.mark.anyio
|
|
async def test_run_request_validation(self, auth_client):
|
|
"""Test request validation."""
|
|
# Missing required field
|
|
response = await auth_client.post(
|
|
"/agents/run",
|
|
json={
|
|
"working_dir": "."
|
|
}
|
|
)
|
|
|
|
assert response.status_code == 422 # Validation error
|
|
|
|
@pytest.mark.anyio
|
|
async def test_run_missing_prompt(self, auth_client):
|
|
"""Test running with missing prompt."""
|
|
response = await auth_client.post(
|
|
"/agents/run",
|
|
json={
|
|
"agent_type": "explore",
|
|
"working_dir": "."
|
|
}
|
|
)
|
|
|
|
assert response.status_code == 422
|
|
|
|
@pytest.mark.anyio
|
|
async def test_run_empty_body(self, auth_client):
|
|
"""Test running with empty request body."""
|
|
response = await auth_client.post("/agents/run", json={})
|
|
|
|
assert response.status_code == 422
|
|
|
|
|
|
class TestAgentStreamEndpoint:
|
|
"""Tests for POST /agents/stream endpoint."""
|
|
|
|
@pytest.mark.anyio
|
|
async def test_stream_with_unknown_agent(self, auth_client):
|
|
"""Test streaming unknown agent type."""
|
|
response = await auth_client.post(
|
|
"/agents/stream",
|
|
json={
|
|
"prompt": "test",
|
|
"agent_type": "nonexistent",
|
|
"working_dir": "."
|
|
}
|
|
)
|
|
|
|
assert response.status_code == 400
|
|
assert "Unknown agent" in response.json()["detail"]
|
|
|
|
@pytest.mark.anyio
|
|
async def test_stream_request_validation(self, auth_client):
|
|
"""Test stream request validation."""
|
|
response = await auth_client.post(
|
|
"/agents/stream",
|
|
json={
|
|
"agent_type": "explore"
|
|
# Missing prompt
|
|
}
|
|
)
|
|
|
|
assert response.status_code == 422
|
|
|
|
@pytest.mark.anyio
|
|
async def test_stream_content_type(self, auth_client):
|
|
"""Test that stream endpoint returns correct content type."""
|
|
# Note: This test would require mocking the agent to avoid LLM calls
|
|
# For now, we just verify validation works
|
|
response = await auth_client.post(
|
|
"/agents/stream",
|
|
json={
|
|
"prompt": "test",
|
|
"agent_type": "nonexistent",
|
|
"working_dir": "."
|
|
}
|
|
)
|
|
# Unknown agent returns 400, not streaming
|
|
assert response.status_code == 400
|