包含本地/远程部署脚本、AI Agent 服务、Dashboard 与 QA 验证。 Co-authored-by: Cursor <cursoragent@cursor.com>
78 lines
2.3 KiB
Python
78 lines
2.3 KiB
Python
import json
|
|
|
|
import httpx
|
|
import pytest
|
|
import respx
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
@respx.mock
|
|
async def test_create_issue_calls_gptproto_then_plane(client):
|
|
gpt_route = respx.post("https://gptproto.com/v1/chat/completions").mock(
|
|
return_value=httpx.Response(
|
|
200,
|
|
json={
|
|
"id": "chatcmpl-1",
|
|
"object": "chat.completion",
|
|
"created": 0,
|
|
"model": "claude-sonnet-4-6",
|
|
"choices": [
|
|
{
|
|
"index": 0,
|
|
"message": {
|
|
"role": "assistant",
|
|
"content": json.dumps(
|
|
{
|
|
"name": "Fix login bug",
|
|
"description_html": "<p>Login fails on Safari</p>",
|
|
}
|
|
),
|
|
},
|
|
"finish_reason": "stop",
|
|
}
|
|
],
|
|
"usage": {"prompt_tokens": 10, "completion_tokens": 20, "total_tokens": 30},
|
|
},
|
|
)
|
|
)
|
|
|
|
plane_route = respx.post(
|
|
"http://api:8000/api/v1/workspaces/ws-demo/projects/proj-123/issues/"
|
|
).mock(
|
|
return_value=httpx.Response(
|
|
201,
|
|
json={
|
|
"id": "issue-uuid-1",
|
|
"name": "Fix login bug",
|
|
"description_html": "<p>Login fails on Safari</p>",
|
|
"project": "proj-123",
|
|
},
|
|
)
|
|
)
|
|
|
|
payload = {
|
|
"prompt": "users report login broken on safari",
|
|
"project_id": "proj-123",
|
|
"workspace_slug": "ws-demo",
|
|
}
|
|
resp = await client.post("/ai/create-issue", json=payload)
|
|
|
|
assert resp.status_code == 200, resp.text
|
|
body = resp.json()
|
|
assert body["id"] == "issue-uuid-1"
|
|
assert body["name"] == "Fix login bug"
|
|
|
|
assert gpt_route.called
|
|
assert plane_route.called
|
|
|
|
plane_request_body = json.loads(plane_route.calls[0].request.content.decode())
|
|
assert plane_request_body["name"] == "Fix login bug"
|
|
assert "Safari" in plane_request_body["description_html"]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
@respx.mock
|
|
async def test_create_issue_validates_input(client):
|
|
resp = await client.post("/ai/create-issue", json={"prompt": "x"})
|
|
assert resp.status_code == 422
|