37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
"""GET /tools/capabilities 统一能力列举测试。"""
|
|
|
|
from collections.abc import AsyncGenerator
|
|
|
|
import pytest
|
|
from httpx import ASGITransport, AsyncClient
|
|
|
|
from app.main import app
|
|
from app.services import skills as skills_service
|
|
|
|
|
|
@pytest.fixture
|
|
async def client() -> AsyncGenerator[AsyncClient, None]:
|
|
transport = ASGITransport(app=app)
|
|
async with AsyncClient(transport=transport, base_url="http://test") as http_client:
|
|
yield http_client
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_list_capabilities_includes_skills(client: AsyncClient) -> None:
|
|
await skills_service.create_skill(name="coding", trigger="代码", prompt_fragment="代码助手")
|
|
resp = await client.get("/api/v1/tools/capabilities")
|
|
assert resp.status_code == 200
|
|
data = resp.json()
|
|
# runtime 在测试环境可能未就绪(ASGITransport 不跑 lifespan),至少含 skill
|
|
skill_caps = [c for c in data if c["source"] == "skill"]
|
|
assert any(c["name"] == "coding" for c in skill_caps)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_list_capabilities_source_values(client: AsyncClient) -> None:
|
|
resp = await client.get("/api/v1/tools/capabilities")
|
|
assert resp.status_code == 200
|
|
for c in resp.json():
|
|
assert c["source"] in {"builtin", "mcp", "skill"}
|
|
assert "name" in c and "risk_level" in c
|